Last active
May 7, 2016 19:32
-
-
Save zzeroo/8a4ac9b2f272d3ea02f43cf4359281c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /// Cargo.toml | |
| /// [dependencies] | |
| /// gtk = { git = "https://github.com/gtk-rs/gtk", features = ["v3_10"] } | |
| /// gdk = { git = "https://github.com/gtk-rs/gdk" } | |
| extern crate gdk; | |
| extern crate gtk; | |
| use gdk::enums::*; | |
| use gtk::prelude::*; | |
| fn main() { | |
| gtk::init().unwrap_or_else(|_| panic!("Failed to initalize GTK.")); | |
| let window = gtk::Window::new(gtk::WindowType::Toplevel); | |
| // Window properties | |
| window.set_title("Stack switcher test"); | |
| window.set_default_size(800, 600); | |
| // Connect delete event to quit the gtk::main thread | |
| window.connect_delete_event(|_, _| { | |
| gtk::main_quit(); | |
| Inhibit(true) | |
| }); | |
| // Connect ESC key press event, and quit the gui if ESC was pressed | |
| window.connect_key_press_event(move |_, key| { | |
| match key.get_keyval() as u32 { | |
| key::Escape => gtk::main_quit(), | |
| _ => (), | |
| } | |
| Inhibit(false) | |
| }); | |
| let box_main = gtk::Box::new(gtk::Orientation::Horizontal, 0); | |
| let stack_switcher = gtk::StackSwitcher::new(); | |
| box_main.pack_start(&stack_switcher, false, false, 0); | |
| let stack = gtk::Stack::new(); | |
| stack.set_transition_type(gtk::StackTransitionType::SlideLeftRight); | |
| stack_switcher.set_stack(Some(&stack)); | |
| let separator = gtk::Separator::new(gtk::Orientation::Vertical); | |
| box_main.pack_start(&separator, false, false, 0); | |
| box_main.pack_start(&stack, true, true, 0); | |
| // Construct the StackSwitcher | |
| for i in 1..10 { | |
| let label = gtk::Label::new(Some(&i.to_string())); | |
| stack.add_named(&label, &i.to_string()); | |
| } | |
| window.add(&box_main); | |
| window.show_all(); | |
| gtk::main(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment