fix(wallpaper): color picker functionality
This commit is contained in:
parent
6cb05e6494
commit
6e4ea7675d
2 changed files with 44 additions and 24 deletions
|
|
@ -23,12 +23,12 @@ use cosmic::widget::{
|
||||||
settings, tab_bar, text, toggler,
|
settings, tab_bar, text, toggler,
|
||||||
};
|
};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::{window, Alignment, Color, Length},
|
Apply, Element, Task,
|
||||||
surface,
|
widget::{ColorPickerModel, color_picker::ColorPickerUpdate, icon},
|
||||||
};
|
};
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
widget::{color_picker::ColorPickerUpdate, icon, ColorPickerModel},
|
iced::{Alignment, Color, Length, window},
|
||||||
Apply, Element, Task,
|
surface,
|
||||||
};
|
};
|
||||||
use cosmic_bg_config::Source;
|
use cosmic_bg_config::Source;
|
||||||
use cosmic_settings_page::Section;
|
use cosmic_settings_page::Section;
|
||||||
|
|
@ -731,30 +731,40 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::ColorAdd(message) => {
|
Message::ColorAdd(message) => {
|
||||||
if let ColorPickerUpdate::ActionFinished = message {
|
match message {
|
||||||
let _res = self
|
ColorPickerUpdate::ActionFinished => {
|
||||||
.color_model
|
if let Some(color) = self.color_model.get_applied_color() {
|
||||||
.update::<crate::app::Message>(ColorPickerUpdate::AppliedColor);
|
let ret = self
|
||||||
|
.color_model
|
||||||
|
.update::<crate::app::Message>(ColorPickerUpdate::ActionFinished);
|
||||||
|
let color = wallpaper::Color::Single([color.r, color.g, color.b]);
|
||||||
|
|
||||||
if let Some(color) = self.color_model.get_applied_color() {
|
if let Choice::Color(c) = self.selection.active.clone() {
|
||||||
let color = wallpaper::Color::Single([color.r, color.g, color.b]);
|
if let Err(why) = self.config.remove_custom_color(&c) {
|
||||||
|
tracing::error!(?why, "could not set custom color");
|
||||||
|
}
|
||||||
|
self.selection.remove_custom_color(&c);
|
||||||
|
}
|
||||||
|
if let Err(why) = self.config.add_custom_color(color.clone()) {
|
||||||
|
tracing::error!(?why, "could not set custom color");
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(why) = self.config.add_custom_color(color.clone()) {
|
self.cached_display_handle = None;
|
||||||
tracing::error!(?why, "could not set custom color");
|
self.selection.replace_active_custom(color.clone());
|
||||||
|
self.config_apply();
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self.selection.add_custom_color(color.clone());
|
m => {
|
||||||
self.selection.active = Choice::Color(color);
|
return self.color_model.update::<crate::app::Message>(m);
|
||||||
self.cached_display_handle = None;
|
|
||||||
self.context_view = None;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return self.color_model.update::<crate::app::Message>(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::ColorAddContext => {
|
Message::ColorAddContext => {
|
||||||
self.context_view = Some(ContextView::AddColor);
|
self.context_view = Some(ContextView::AddColor);
|
||||||
|
self.selection.active = Choice::Color(wallpaper::Color::Single([0., 0., 0.]));
|
||||||
return cosmic::task::message(crate::app::Message::OpenContextDrawer(
|
return cosmic::task::message(crate::app::Message::OpenContextDrawer(
|
||||||
self.entity,
|
self.entity,
|
||||||
fl!("color-picker").into(),
|
fl!("color-picker").into(),
|
||||||
|
|
@ -1112,6 +1122,16 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn replace_active_custom(&mut self, color: wallpaper::Color) {
|
||||||
|
if let Choice::Color(active) = &self.active {
|
||||||
|
self.custom_colors.retain(|c| c != active);
|
||||||
|
}
|
||||||
|
if !self.custom_colors.contains(&color) {
|
||||||
|
self.custom_colors.push(color.clone());
|
||||||
|
self.active = Choice::Color(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn add_custom_image(&mut self, path: PathBuf, display: Image, selection: ImageHandle) {
|
fn add_custom_image(&mut self, path: PathBuf, display: Image, selection: ImageHandle) {
|
||||||
let key = self.paths.insert(path);
|
let key = self.paths.insert(path);
|
||||||
self.is_custom.insert(key, ());
|
self.is_custom.insert(key, ());
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,11 @@ impl<Message: 'static> Section<Message> {
|
||||||
pub fn view<Model: Page<Message>>(
|
pub fn view<Model: Page<Message>>(
|
||||||
mut self,
|
mut self,
|
||||||
func: impl for<'a> Fn(
|
func: impl for<'a> Fn(
|
||||||
&'a Binder<Message>,
|
&'a Binder<Message>,
|
||||||
&'a Model,
|
&'a Model,
|
||||||
&'a Section<Message>,
|
&'a Section<Message>,
|
||||||
) -> cosmic::Element<'a, Message>
|
) -> cosmic::Element<'a, Message>
|
||||||
+ 'static,
|
+ 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.view_fn = Box::new(move |binder, model: &dyn Page<Message>, section| {
|
self.view_fn = Box::new(move |binder, model: &dyn Page<Message>, section| {
|
||||||
let model = model.downcast_ref::<Model>().unwrap_or_else(|| {
|
let model = model.downcast_ref::<Model>().unwrap_or_else(|| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue