A CheckMenuItem is a menu item that maintains the state of a boolean value in addition to a MenuItem usual role in activating application code.
A check box indicating the state of the boolean value is displayed at the left side of the MenuItem. Activating the MenuItem toggles the value.
menuitem
├── check.left
╰── <child>
nuItem has a main CSS node with
name menuitem, and a subnode with name check, which gets the .left or .right style class.
Example: CheckMenuItem:
public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.CheckMenuItem";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
// MenuBar:
Gtk.MenuBar bar = new Gtk.MenuBar ();
this.add (bar);
// File:
Gtk.MenuItem item_file = new Gtk.MenuItem.with_label ("File");
bar.add (item_file);
Gtk.Menu filemenu = new Gtk.Menu ();
item_file.set_submenu (filemenu);
Gtk.CheckMenuItem item_option = new Gtk.CheckMenuItem.with_label ("My Option");
item_option.set_active (true);
filemenu.add (item_option);
item_option.toggled.connect (() => {
print ("%s\n", item_option.active.to_string ());
});
}
public static int main (string[] args) {
Gtk.init (ref args);
Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}
valac --pkg gtk+-3.0 Gtk.CheckMenuItem.vala