Skip to content

Commit

Permalink
library: Ported Switch in RUST
Browse files Browse the repository at this point in the history
  • Loading branch information
onkarrai06 committed Aug 31, 2023
1 parent 5866af7 commit 90ab009
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Library/demos/Switch/code.rs
Original file line number Diff line number Diff line change
@@ -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());
}));
}

0 comments on commit 90ab009

Please sign in to comment.