Created
March 7, 2020 14:18
-
-
Save Dmitry-Borodin/154a75473c2fcf6479c4578b2685b367 to your computer and use it in GitHub Desktop.
gtk-rs closing application panic sample
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
//! # Builder Basics Sample | |
//! | |
//! This sample demonstrates how to use the builder with an imported glade file | |
extern crate gio; | |
extern crate gtk; | |
use gio::prelude::*; | |
use gtk::prelude::*; | |
use gtk::{ApplicationWindow, Builder, Button, MessageDialog}; | |
use std::env::args; | |
fn build_ui(application: >k::Application) { | |
let glade_src = include_str!("builder_basics.glade"); | |
let builder = Builder::new_from_string(glade_src); | |
let window: ApplicationWindow = builder.get_object("window1").expect("Couldn't get window1"); | |
window.set_application(Some(application)); | |
let bigbutton: Button = builder.get_object("button1").expect("Couldn't get button1"); | |
let dialog: MessageDialog = builder | |
.get_object("messagedialog1") | |
.expect("Couldn't get messagedialog1"); | |
bigbutton.connect_clicked(move |_| { | |
gtk::main_quit(); | |
}); | |
window.show_all(); | |
} | |
fn main() { | |
let application = gtk::Application::new( | |
Some("com.github.gtk-rs.examples.builder_basics"), | |
Default::default(), | |
) | |
.expect("Initialization failed..."); | |
application.connect_activate(|app| { | |
build_ui(app); | |
}); | |
application.run(&args().collect::<Vec<_>>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment