-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26b1c3b
commit 7408385
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
} |