Commit 50f8c26b authored by mh's avatar mh

Added basic interaction with two buttons changing a label

parent 41324741
This diff is collapsed.
......@@ -50,6 +50,15 @@ macro_rules! upgrade_weak {
}
fn build_ui(application: &gtk::Application) {
/*Additional data - Back-end Program data
*/
let mut number: isize = 0;
/*
End Back-end data
*/
let glade_src = include_str!("gtk-test.glade");
let builder = Builder::new_from_string(glade_src);
......@@ -79,21 +88,22 @@ fn build_ui(application: &gtk::Application) {
let entry_weak = entry.downgrade();
button.connect_clicked(clone!(window_weak, entry_weak => move |_| {
let window = upgrade_weak!(window_weak);
let entry = upgrade_weak!(entry_weak);
let window = upgrade_weak!(window_weak);
let entry = upgrade_weak!(entry_weak);
let dialog = Dialog::new_with_buttons(Some("Menu sub-Window"),
Some(&window),
gtk::DialogFlags::MODAL,
&[("No", ResponseType::No),
("Yes", ResponseType::Yes),
("Other", ResponseType::Other(0))]);
let dialog = Dialog::new_with_buttons(Some("Menu sub-Window"),
Some(&window),
gtk::DialogFlags::MODAL,
&[("No", ResponseType::No),
("Yes", ResponseType::Yes),
("Other", ResponseType::Other(0))]);
let ret = dialog.run();
let ret = dialog.run();
dialog.destroy();
dialog.destroy();
entry.set_text(&format!("Clicked {}", ret));
}));
let button_ok: Button = builder
......@@ -118,6 +128,27 @@ fn build_ui(application: &gtk::Application) {
dialog_cancel.hide();
});
let label: Label = builder
.get_object("label-bot")
.expect("Could not reach label bot");
let changer_button1: Button = builder
.get_object("changer-button1")
.expect("Could not build changer button 1");
let changer_button2: Button = builder
.get_object("changer-button2")
.expect("Could not build changer button 2");
let label_clone1 = label.clone();
changer_button1.connect_clicked(move |_| {
label_clone1.set_label("Button 1 was pressed");
println!("The number is : {}", number);
});
let label_clone2 = label.clone();
changer_button2.connect_clicked(move |_| {
label_clone2.set_label("Button 2 was pressed");
println!("The number is : {}", number);
});
//Display Key-pressed events in terminal
//This will not work if your focus is in a sub-window
window.connect_key_press_event(clone!(entry_weak => move |_, key| {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment