Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: Ported Switch to RUST #561

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::*;
onkarrai06 marked this conversation as resolved.
Show resolved Hide resolved

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 |_| {
onkarrai06 marked this conversation as resolved.
Show resolved Hide resolved
label_on.set_label(if switch_on.is_active() {
"On"
} else {
"Off"
});
onkarrai06 marked this conversation as resolved.
Show resolved Hide resolved
switch_off.set_active(!switch_on.is_active());
}));

switch_off.connect_active_notify(clone!(@weak switch_off, @weak switch_on => move |_| {
onkarrai06 marked this conversation as resolved.
Show resolved Hide resolved
label_off.set_label(if switch_off.is_active() { "On" } else { "Off" });
switch_on.set_active(!switch_off.is_active());
}));
}