Skip to content

Commit

Permalink
reduce requirement to gnome_42 to support ubuntu 22.04
Browse files Browse the repository at this point in the history
  • Loading branch information
gabm committed Dec 27, 2023
1 parent b0f55b9 commit 4614d2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include = [


[dependencies]
relm4 = { version = "0.6.2", features = ["macros", "libadwaita", "gnome_44"] }
relm4 = { version = "0.6.2", features = ["macros", "libadwaita", "gnome_42"] }
pangocairo = "0.17.10"
tokio = { version = "1.32.0", features = ["full"] }
gdk-pixbuf = "0.17.2"
Expand Down
31 changes: 19 additions & 12 deletions src/ui/toolbars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use gdk_pixbuf::{
};
use relm4::{
actions::{ActionablePlus, RelmAction, RelmActionGroup},
gtk::{prelude::*, Align, ColorDialog, Window},
gtk::{prelude::*, Align, ColorChooserDialog, ResponseType},
prelude::*,
};

Expand Down Expand Up @@ -228,22 +228,29 @@ pub enum ColorButtons {
}

impl StyleToolbar {
fn show_color_dialog(&self, sender: ComponentSender<StyleToolbar>, root: Option<Window>) {
fn show_color_dialog(&self, sender: ComponentSender<StyleToolbar>) {
let current_color = Some(self.custom_color.into());
relm4::spawn_local(async move {
let dialog = ColorDialog::builder()
let dialog = ColorChooserDialog::builder()
.modal(true)
.title("Choose Color")
.with_alpha(true)
.hide_on_close(true)
.build();
dialog.set_use_alpha(true);
if let Some(color) = current_color.as_ref() {
dialog.set_rgba(color);
}

let color = dialog
.choose_rgba_future(root.as_ref(), current_color.as_ref())
.await
.ok()
.map(Color::from_gdk);
let dialog_copy = dialog.clone();
dialog.connect_response(move |_, r| {
if r == ResponseType::Ok {
dialog_copy.hide();
let color = Color::from_gdk(dialog_copy.rgba());
sender.input(StyleToolbarInput::ColorDialogFinished(Some(color)));
}
});

sender.input(StyleToolbarInput::ColorDialogFinished(color));
dialog.show();
});
}

Expand Down Expand Up @@ -371,10 +378,10 @@ impl Component for StyleToolbar {
},
}

fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>, root: &Self::Root) {
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>, _root: &Self::Root) {
match message {
StyleToolbarInput::ShowColorDialog => {
self.show_color_dialog(sender, root.toplevel_window());
self.show_color_dialog(sender);
}
StyleToolbarInput::ColorDialogFinished(color) => {
if let Some(color) = color {
Expand Down

0 comments on commit 4614d2f

Please sign in to comment.