Skip to content

Instantly share code, notes, and snippets.

@Dmitry-Borodin
Created March 7, 2020 14:18
Show Gist options
  • Save Dmitry-Borodin/154a75473c2fcf6479c4578b2685b367 to your computer and use it in GitHub Desktop.
Save Dmitry-Borodin/154a75473c2fcf6479c4578b2685b367 to your computer and use it in GitHub Desktop.
gtk-rs closing application panic sample
//! # 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: &gtk::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