Skip to content

Instantly share code, notes, and snippets.

@gicrisf
Created November 11, 2020 19:06
Show Gist options
  • Select an option

  • Save gicrisf/9c7615436b9da6aabd57b280787ab7a3 to your computer and use it in GitHub Desktop.

Select an option

Save gicrisf/9c7615436b9da6aabd57b280787ab7a3 to your computer and use it in GitHub Desktop.
Add a simple button as tab of a GTK notebook without an associated content is very simple: just leave blank the child!
let window: gtk::Window = gtk::Window::new(gtk::WindowType::Toplevel);
let notebook = gtk::Notebook::new();
// Useful as "add child" button like in a classic browser
// Get image for your button
let add_image = gtk::Image::from_icon_name(Some("list-add"), gtk::IconSize::Button);
// Make button
let button = gtk::Button::new();
button.set_relief(gtk::ReliefStyle::None); // Relief can be "Normal"/"None"
button.set_focus_on_click(false);
button.add(&add_image);
let tab_box = gtk::Box::new(gtk::Orientation::Horizontal, 0);
tab_box.set_property_width_request(15 as i32); // Tab lenght in pixel
tab_box.pack_end(&button, false, false, 0); // Append button to button, packing on the right side
tab_box.show_all();
let add_content = gtk::Box::new(gtk::Orientation::Horizontal, 0); // void box as child
notebook.append_page(&add_content, Some(&add_tab.tab_box));
window.add(&notebook);
window.set_title("Notebook Add Button example");
window.show_all();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment