From d5fc9df94d353936049e54e67b46dc41dcff0ccf Mon Sep 17 00:00:00 2001 From: "ay9thqi3tbqiwbegqsg a[soiaosshasdg" <30902201+alx365@users.noreply.github.com> Date: Tue, 20 Oct 2020 18:07:50 +0000 Subject: [PATCH] added color button, i am unsure what to do with it know... you figure that out (#32) * Add GtkColorButton widget --- src/widgets/widget_definitions.rs | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/widgets/widget_definitions.rs b/src/widgets/widget_definitions.rs index 5b718a3..fed26e5 100644 --- a/src/widgets/widget_definitions.rs +++ b/src/widgets/widget_definitions.rs @@ -22,6 +22,8 @@ pub(super) fn widget_to_gtk_widget(bargs: &mut BuilderArgs) -> Result build_gtk_literal(bargs)?.upcast(), "input" => build_gtk_input(bargs)?.upcast(), "calendar" => build_gtk_calendar(bargs)?.upcast(), + "colorButton" => build_gtk_color_button(bargs)?.upcast(), + "expander" => build_gtk_expander(bargs)?.upcast(), _ => return Ok(None), }; Ok(Some(gtk_widget)) @@ -145,6 +147,37 @@ pub(super) fn resolve_orientable_attrs(bargs: &mut BuilderArgs, gtk_widget: >k // concrete widgets +/// @widget expander widget +fn build_gtk_expander(bargs: &mut BuilderArgs) -> Result { + let gtk_widget = gtk::Expander::new(Some("Placeholder text, don't forget to set the property 'name'")); + resolve_block!(bargs, gtk_widget, { + // @prop label - label of the expander + prop(label: as_string) {gtk_widget.set_label(Some(&label));} + }); + Ok(gtk_widget) +} +/// @widget color button +fn build_gtk_color_button(bargs: &mut BuilderArgs) -> Result { + let gtk_widget = gtk::ColorButtonBuilder::new().build(); + let on_change_handler_id: Rc>> = 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_set(move |gtk_widget| { + run_command(&onchange, gtk_widget.get_rgba()); + }) + )); + old_id.map(|id| gtk_widget.disconnect(id)); + } + prop(use_alpha: as_bool) {gtk_widget.set_use_alpha(use_alpha);} + }); + + Ok(gtk_widget) +} + /// @widget scale extends range /// @desc a slider. fn build_gtk_scale(bargs: &mut BuilderArgs) -> Result {