added color widget (difference to the color button, is thats its not hidden behind a button so you can always see it. (#38)

This commit is contained in:
ay9thqi3tbqiwbegqsg a[soiaosshasdg 2020-10-21 17:57:37 +00:00 committed by GitHub
parent 5f3e16e70c
commit 4ddbea7194
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,7 @@ pub(super) fn widget_to_gtk_widget(bargs: &mut BuilderArgs) -> Result<Option<gtk
"calendar" => build_gtk_calendar(bargs)?.upcast(), "calendar" => build_gtk_calendar(bargs)?.upcast(),
"color-button" => build_gtk_color_button(bargs)?.upcast(), "color-button" => build_gtk_color_button(bargs)?.upcast(),
"expander" => build_gtk_expander(bargs)?.upcast(), "expander" => build_gtk_expander(bargs)?.upcast(),
"color-chooser" => build_gtk_color_chooser(bargs)?.upcast(),
_ => return Ok(None), _ => return Ok(None),
}; };
Ok(Some(gtk_widget)) Ok(Some(gtk_widget))
@ -178,6 +179,28 @@ fn build_gtk_color_button(bargs: &mut BuilderArgs) -> Result<gtk::ColorButton> {
Ok(gtk_widget) Ok(gtk_widget)
} }
/// @widget color-chooser
fn build_gtk_color_chooser(bargs: &mut BuilderArgs) -> Result<gtk::ColorChooserWidget> {
let gtk_widget = gtk::ColorChooserWidget::new();
let on_change_handler_id: Rc<RefCell<Option<glib::SignalHandlerId>>> = Rc::new(RefCell::new(None));
resolve_block!(bargs, gtk_widget, {
// @prop use-alpha - bool to wether or not use alpha
prop(use_alpha: as_bool) {gtk_widget.set_use_alpha(use_alpha);},
// @prop onchange - runs the code when the color was selected
prop(onchange: as_string) {
let old_id = on_change_handler_id.replace(Some(
gtk_widget.connect_color_activated(move |_a, gtk_widget| {
run_command(&onchange, gtk_widget);
})
));
old_id.map(|id| gtk_widget.disconnect(id));
}
});
Ok(gtk_widget)
}
/// @widget scale extends range /// @widget scale extends range
/// @desc a slider. /// @desc a slider.
fn build_gtk_scale(bargs: &mut BuilderArgs) -> Result<gtk::Scale> { fn build_gtk_scale(bargs: &mut BuilderArgs) -> Result<gtk::Scale> {