Skip to content

Commit

Permalink
library: Ported SpinButton in RUST
Browse files Browse the repository at this point in the history
  • Loading branch information
onkarrai06 committed Sep 3, 2023
1 parent 26b1c3b commit 7408385
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Library/demos/Spin Button/code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::workbench;
use glib::clone;
use gtk::glib;
use gtk::prelude::*;
use gtk::SpinType::StepForward;

pub fn main() {
let hours: gtk::SpinButton = workbench::builder().object("hours").unwrap();
let minutes: gtk::SpinButton = workbench::builder().object("minutes").unwrap();

fn tellTime(hours: &str, minutes: &str) {
println!("The time selected is {hours}:{minutes}");
}

hours.connect_value_changed(clone!(@weak minutes => move |hours| {
tellTime(&hours.text(), &minutes.text());
}));

hours.connect_output(move |hours| {
let value = hours.value();
let text = format!("{:02}", value);
hours.set_text(&text);
return true.into();
});

minutes.connect_output(move |minutes| {
let value = minutes.value();
let text = format!("{:02}", value);
minutes.set_text(&text);
return true.into();
});

minutes.connect_wrapped(clone!(@weak hours => move |minutes| {
let spin_type: gtk:: SpinType = StepForward;
hours.spin(spin_type, 1.0);
}));

minutes.connect_value_changed(move |minutes| {
tellTime(&hours.text(), &minutes.text());
});
}

0 comments on commit 7408385

Please sign in to comment.