MenuItem
open class MenuItem : Bin, MenuItemProtocol
The GtkMenuItem widget and the derived widgets are the only valid
children for menus. Their function is to correctly handle highlighting,
alignment, events and submenus.
As a GtkMenuItem derives from GtkBin it can hold any valid child widget,
although only a few are really useful.
By default, a GtkMenuItem sets a GtkAccelLabel as its child.
GtkMenuItem has direct functions to set the label and its mnemonic.
For more advanced label settings, you can fetch the child widget from the GtkBin.
An example for setting markup and accelerator on a MenuItem: (C Language Example):
GtkWidget *menu_item = gtk_menu_item_new_with_label ("Example Menu Item");
GtkWidget *child = gtk_bin_get_child (GTK_BIN (menu_item));
gtk_label_set_markup (GTK_LABEL (child), "<i>new label</i> with <b>markup</b>");
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (child), GDK_KEY_1, 0);
GtkMenuItem as GtkBuildable
The GtkMenuItem implementation of the GtkBuildable interface supports
adding a submenu by specifying “submenu” as the “type” attribute of
a <child> element.
An example of UI definition fragment with submenus:
<object class="GtkMenuItem">
<child type="submenu">
<object class="GtkMenu"/>
</child>
</object>
CSS nodes
(plain Language Example):
menuitem
├── <child>
╰── [arrow.right]
GtkMenuItem has a single CSS node with name menuitem. If the menuitem has a submenu, it gets another CSS node with name arrow, which has the .left or .right style class.
The MenuItem type acts as a reference-counted owner of an underlying GtkMenuItem instance.
It provides the methods that can operate on this data type through MenuItemProtocol conformance.
Use MenuItem as a strong reference or owner of a GtkMenuItem instance.
-
Designated initialiser from the underlying `C` data type.This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the
MenuIteminstance.Declaration
Swift
@inlinable public init(_ op: UnsafeMutablePointer<GtkMenuItem>)Parameters
oppointer to the underlying object
-
Designated initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theMenuIteminstance.Declaration
Swift
@inlinable public init(_ op: UnsafePointer<GtkMenuItem>)Parameters
oppointer to the underlying object
-
Optional initialiser from a non-mutating
gpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theMenuIteminstance.Declaration
Swift
@inlinable override public init!(gpointer op: gpointer?)Parameters
opgpointer to the underlying object
-
Optional initialiser from a non-mutating
gconstpointerto the underlyingCdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theMenuIteminstance.Declaration
Swift
@inlinable override public init!(gconstpointer op: gconstpointer?)Parameters
oppointer to the underlying object
-
Optional initialiser from a constant pointer to the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theMenuIteminstance.Declaration
Swift
@inlinable public init!(_ op: UnsafePointer<GtkMenuItem>?)Parameters
oppointer to the underlying object
-
Optional initialiser from the underlying
Cdata type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to theMenuIteminstance.Declaration
Swift
@inlinable public init!(_ op: UnsafeMutablePointer<GtkMenuItem>?)Parameters
oppointer to the underlying object
-
Designated initialiser from the underlying
Cdata type. Will retainGtkMenuItem. i.e., ownership is transferred to theMenuIteminstance.Declaration
Swift
@inlinable public init(retaining op: UnsafeMutablePointer<GtkMenuItem>)Parameters
oppointer to the underlying object
-
Reference intialiser for a related type that implements
MenuItemProtocolWill retainGtkMenuItem.Declaration
Swift
@inlinable public init<T>(menuItem other: T) where T : MenuItemProtocolParameters
otheran instance of a related type that implements
MenuItemProtocol -
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable override public init<T>(cPointer p: UnsafeMutablePointer<T>)Parameters
cPointerpointer to the underlying object
-
Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)Parameters
cPointerpointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable override public init(raw p: UnsafeRawPointer)Parameters
praw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable override public init(retainingRaw raw: UnsafeRawPointer) -
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable public required init(raw p: UnsafeMutableRawPointer)Parameters
pmutable raw pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable required public init(retainingRaw raw: UnsafeMutableRawPointer)Parameters
rawmutable raw pointer to the underlying object
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable override public init(opaquePointer p: OpaquePointer)Parameters
popaque pointer to the underlying object
-
Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuItemProtocol.Declaration
Swift
@inlinable override public init(retainingOpaquePointer p: OpaquePointer)Parameters
popaque pointer to the underlying object
-
Creates a new
GtkMenuItem.Declaration
Swift
@inlinable public init() -
Creates a new
GtkMenuItemwhose child is aGtkLabel.Declaration
Swift
@inlinable public init(label: UnsafePointer<gchar>!) -
Creates a new
GtkMenuItemcontaining a label.The label will be created using
gtk_label_new_with_mnemonic(), so underscores inlabelindicate the mnemonic for the menu item.Declaration
Swift
@inlinable public init(mnemonic label: UnsafePointer<gchar>!) -
Creates a new
GtkMenuItemwhose child is aGtkLabel.Declaration
Swift
@inlinable public static func newWith(label: UnsafePointer<gchar>!) -> Widget! -
Creates a new
GtkMenuItemcontaining a label.The label will be created using
gtk_label_new_with_mnemonic(), so underscores inlabelindicate the mnemonic for the menu item.Declaration
Swift
@inlinable public static func newWith(mnemonic label: UnsafePointer<gchar>!) -> Widget!
View on GitHub
Install in Dash
MenuItem Class Reference