From 90ab009a5d1d0a1a66d27883b69ce1400ac05aaf Mon Sep 17 00:00:00 2001 From: onkarrai06 Date: Thu, 31 Aug 2023 13:33:01 +0500 Subject: [PATCH 1/2] library: Ported Switch in RUST --- src/Library/demos/Switch/code.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/Library/demos/Switch/code.rs diff --git a/src/Library/demos/Switch/code.rs b/src/Library/demos/Switch/code.rs new file mode 100644 index 000000000..872207223 --- /dev/null +++ b/src/Library/demos/Switch/code.rs @@ -0,0 +1,26 @@ +use crate::workbench; +use glib::clone; +use gtk::glib; +use gtk::prelude::*; + +pub fn main() { + let switch_on: gtk::Switch = workbench::builder().object("switch_on").unwrap(); + let label_on: gtk::Label = workbench::builder().object("label_on").unwrap(); + + let switch_off: gtk::Switch = workbench::builder().object("switch_off").unwrap(); + let label_off: gtk::Label = workbench::builder().object("label_off").unwrap(); + + switch_on.connect_active_notify(clone!(@weak switch_off, @weak switch_on => move |_| { + label_on.set_label(if switch_on.is_active() { + "On" + } else { + "Off" + }); + switch_off.set_active(!switch_on.is_active()); + })); + + switch_off.connect_active_notify(clone!(@weak switch_off, @weak switch_on => move |_| { + label_off.set_label(if switch_off.is_active() { "On" } else { "Off" }); + switch_on.set_active(!switch_off.is_active()); + })); +} From 2980d94cc97b90b28ef6d57e9d97935c21489296 Mon Sep 17 00:00:00 2001 From: onkarrai06 Date: Thu, 31 Aug 2023 14:05:35 +0500 Subject: [PATCH 2/2] library: Updated code for Switch in RUST --- src/Library/demos/Switch/code.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Library/demos/Switch/code.rs b/src/Library/demos/Switch/code.rs index 872207223..476c3a8d0 100644 --- a/src/Library/demos/Switch/code.rs +++ b/src/Library/demos/Switch/code.rs @@ -1,7 +1,6 @@ use crate::workbench; use glib::clone; use gtk::glib; -use gtk::prelude::*; pub fn main() { let switch_on: gtk::Switch = workbench::builder().object("switch_on").unwrap(); @@ -10,17 +9,13 @@ pub fn main() { let switch_off: gtk::Switch = workbench::builder().object("switch_off").unwrap(); let label_off: gtk::Label = workbench::builder().object("label_off").unwrap(); - switch_on.connect_active_notify(clone!(@weak switch_off, @weak switch_on => move |_| { - label_on.set_label(if switch_on.is_active() { - "On" - } else { - "Off" - }); + switch_on.connect_active_notify(clone!(@weak switch_off => move |switch_on| { + label_on.set_label(if switch_on.is_active() { "On" } else { "Off" }); switch_off.set_active(!switch_on.is_active()); })); - switch_off.connect_active_notify(clone!(@weak switch_off, @weak switch_on => move |_| { + switch_off.connect_active_notify(move |switch_off| { label_off.set_label(if switch_off.is_active() { "On" } else { "Off" }); switch_on.set_active(!switch_off.is_active()); - })); + }); }