From 740838512a4df5e0b4a62829ca42890039d350f4 Mon Sep 17 00:00:00 2001 From: onkarrai06 Date: Sun, 3 Sep 2023 18:14:54 +0500 Subject: [PATCH] library: Ported SpinButton in RUST --- src/Library/demos/Spin Button/code.rs | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Library/demos/Spin Button/code.rs diff --git a/src/Library/demos/Spin Button/code.rs b/src/Library/demos/Spin Button/code.rs new file mode 100644 index 000000000..a9d4d3451 --- /dev/null +++ b/src/Library/demos/Spin Button/code.rs @@ -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()); + }); +}