Skip to content

Instantly share code, notes, and snippets.

@robertsanseries
Last active January 6, 2021 17:55
Show Gist options
  • Save robertsanseries/8b2342ed4551ff51fbf29f2c2f5f8ef2 to your computer and use it in GitHub Desktop.
Save robertsanseries/8b2342ed4551ff51fbf29f2c2f5f8ef2 to your computer and use it in GitHub Desktop.
Example of Gtk.Popover with vala
public class Application : Gtk.Window {
public GLib.Menu menu_model { get; set; }
public Application () {
this.set_default_size (700, 600);
var header_bar = new Gtk.HeaderBar ();
header_bar.set_title ("teste");
header_bar.show_close_button = true;
var button = new Gtk.Button();
button.set_image (new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.LARGE_TOOLBAR));
var menu = new GLib.Menu ();
var item1 = new GLib.MenuItem ("item 1", null);
var item2 = new GLib.MenuItem ("item 2", null);
menu.append_item (item1);
menu.append_item (item2);
var menu_popover = new Gtk.Popover(button);
menu_popover.position = Gtk.PositionType.BOTTOM;
menu_popover.set_size_request (256, -1);
menu_popover.modal = false;
menu_popover.bind_model (menu, null);
button.clicked.connect (() => {
menu_popover.set_visible (true);
});
header_bar.pack_end (button);
this.set_titlebar (header_bar);
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment