Commit fd992c08 authored by mh's avatar mh

switched main to traditional non-glade building. Working prototype.

parent 50f8c26b
......@@ -7,6 +7,15 @@ A sandbox environment for developing GUI applications in Rust with GTK-rs.
Basic
## Branches
**This branch :** Master
Exploring traditional building style (i.e. without .glade src) to explore some deeper connection with data.
**Other branches :**
- glade : Forked from earlier works on master - A working example of decent UI elements and minimal interaction
## More :
- Find out how to manage icon of application
......
......@@ -59,54 +59,56 @@ fn build_ui(application: &gtk::Application) {
End Back-end data
*/
let glade_src = include_str!("gtk-test.glade");
let builder = Builder::new_from_string(glade_src);
/*UNUSED CODE : attempt to integrate non-glade elements on top of glade failed.
let label = Label::new(Some("The label at start"));
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
vbox.add(&label);
vbox.set_child_expand(&label, false);
vbox.set_child_fill(&label, true);
vbox.set_child_padding(&label, 10);
vbox.set_child_pack_type(&label, PackType::End);
*/
let window = gtk::ApplicationWindowBuilder::new()
.application(application)
.title("GTK Testing Sandbox")
.border_width(10)
.window_position(gtk::WindowPosition::Center)
.default_width(460)
.default_height(380)
.build();
let menu_button: Button = Button::new_with_label("Menu");
let intro_label = Label::new(Some("Welcome to the GTK-rs Sandbox"));
let entry: Entry = gtk::Entry::new();
let vbox1 = gtk::Box::new(gtk::Orientation::Vertical, 0);
vbox1.add(&menu_button);
vbox1.set_child_expand(&menu_button, false);
vbox1.set_child_fill(&menu_button, false);
vbox1.set_child_padding(&menu_button, 5);
vbox1.set_child_pack_type(&menu_button, PackType::Start);
vbox1.add(&intro_label);
let window: ApplicationWindow = builder
.get_object("window1")
.expect("Could not build window 1");
vbox1.set_child_padding(&intro_label, 5);
window.set_application(Some(application));
vbox1.add(&entry);
vbox1.set_child_padding(&entry, 5);
//window.add(&vbox); non-glade element
window.add(&vbox1);
let window_weak = window.downgrade();
let button: Button = builder.get_object("button").expect("Couldn't get button");
let entry: Entry = builder.get_object("entry").expect("Couldn't get entry");
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);
menu_button.connect_clicked(clone!(window_weak, entry_weak => move |_| {
let window = upgrade_weak!(window_weak);
let entry = upgrade_weak!(entry_weak);
let dialog = Dialog::new_with_buttons(Some("Menu sub-Window"),
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();
dialog.destroy();
let ret = dialog.run();
dialog.destroy();
entry.set_text(&format!("Clicked {}", ret));
}));
let button_ok: Button = builder
/*let button_ok: Button = builder
.get_object("button1")
.expect("Could not build button ok");
let dialog_ok: MessageDialog = builder
......@@ -147,7 +149,7 @@ fn build_ui(application: &gtk::Application) {
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
......
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