MenuItemRef

public struct MenuItemRef : MenuItemProtocol, GWeakCapturing

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 MenuItemRef type acts as a lightweight Swift reference to an underlying GtkMenuItem instance. It exposes methods that can operate on this data type through MenuItemProtocol conformance. Use MenuItemRef only as an unowned reference to an existing GtkMenuItem instance.

  • ptr
    Untyped pointer to the underlying `GtkMenuItem` instance.
    

    For type-safe access, use the generated, typed pointer menu_item_ptr property instead.

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

MenuItem Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GtkMenuItem>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GtkMenuItem>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GtkMenuItem>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GtkMenuItem>?)
  • Conditional initialiser from an optional gpointer

    Declaration

    Swift

    @inlinable
    init!(gpointer g: gpointer?)
  • Conditional initialiser from an optional, non-mutable gconstpointer

    Declaration

    Swift

    @inlinable
    init!(gconstpointer g: gconstpointer?)
  • Reference intialiser for a related type that implements MenuItemProtocol

    Declaration

    Swift

    @inlinable
    init<T>(_ other: T) where T : MenuItemProtocol
  • This factory is syntactic sugar for setting weak pointers wrapped in GWeak<T>

    Declaration

    Swift

    @inlinable
    static func unowned<T>(_ other: T) -> MenuItemRef where T : MenuItemProtocol
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to MenuItemProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(cPointer: UnsafeMutablePointer<T>)
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to MenuItemProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(constPointer: UnsafePointer<T>)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to MenuItemProtocol.

    Declaration

    Swift

    @inlinable
    init(mutating 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
    init(raw: UnsafeMutableRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to MenuItemProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)
  • Creates a new GtkMenuItem.

    Declaration

    Swift

    @inlinable
    init()
  • Creates a new GtkMenuItem whose child is a GtkLabel.

    Declaration

    Swift

    @inlinable
    init(label: UnsafePointer<gchar>!)
  • Creates a new GtkMenuItem containing a label.

    The label will be created using gtk_label_new_with_mnemonic(), so underscores in label indicate the mnemonic for the menu item.

    Declaration

    Swift

    @inlinable
    init(mnemonic label: UnsafePointer<gchar>!)
  • Creates a new GtkMenuItem whose child is a GtkLabel.

    Declaration

    Swift

    @inlinable
    static func newWith(label: UnsafePointer<gchar>!) -> WidgetRef!
  • Creates a new GtkMenuItem containing a label.

    The label will be created using gtk_label_new_with_mnemonic(), so underscores in label indicate the mnemonic for the menu item.

    Declaration

    Swift

    @inlinable
    static func newWith(mnemonic label: UnsafePointer<gchar>!) -> WidgetRef!