ImageMenuItemRef

public struct ImageMenuItemRef : ImageMenuItemProtocol, GWeakCapturing

A GtkImageMenuItem is a menu item which has an icon next to the text label.

This is functionally equivalent to:

(C Language Example):

  GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
  GtkWidget *label = gtk_label_new ("Music");
  GtkWidget *menu_item = gtk_menu_item_new ();

  gtk_container_add (GTK_CONTAINER (box), icon);
  gtk_container_add (GTK_CONTAINER (box), label);

  gtk_container_add (GTK_CONTAINER (menu_item), box);

  gtk_widget_show_all (menu_item);

Note that the user may disable display of menu icons using the GtkSettings:gtk-menu-images setting, so make sure to still fill in the text label. If you want to ensure that your menu items show an icon you are strongly encouraged to use a GtkMenuItem with a GtkImage instead.

GtkImageMenuItem has been deprecated since GTK+ 3.10. If you want to display an icon in a menu item, you should use GtkMenuItem and pack a GtkBox with a GtkImage and a GtkLabel instead. You should also consider using GtkBuilder and the XML GMenu description for creating menus, by following the GMenu guide. You should consider using icons in menu items only sparingly, and for “objects” (or “nouns”) elements only, like bookmarks, files, and links; “actions” (or “verbs”) should not have icons.

Furthermore, if you would like to display keyboard accelerator, you must pack the accel label into the box using gtk_box_pack_end() and align the label, otherwise the accelerator will not display correctly. The following code snippet adds a keyboard accelerator to the menu item, with a key binding of Ctrl+M:

(C Language Example):

  GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
  GtkWidget *label = gtk_accel_label_new ("Music");
  GtkWidget *menu_item = gtk_menu_item_new ();
  GtkAccelGroup *accel_group = gtk_accel_group_new ();

  gtk_container_add (GTK_CONTAINER (box), icon);

  gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
  gtk_label_set_xalign (GTK_LABEL (label), 0.0);

  gtk_widget_add_accelerator (menu_item, "activate", accel_group,
                              GDK_KEY_m, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
  gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), menu_item);

  gtk_box_pack_end (GTK_BOX (box), label, TRUE, TRUE, 0);

  gtk_container_add (GTK_CONTAINER (menu_item), box);

  gtk_widget_show_all (menu_item);

The ImageMenuItemRef type acts as a lightweight Swift reference to an underlying GtkImageMenuItem instance. It exposes methods that can operate on this data type through ImageMenuItemProtocol conformance. Use ImageMenuItemRef only as an unowned reference to an existing GtkImageMenuItem instance.

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

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

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

ImageMenuItem Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GtkImageMenuItem>?)
  • 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 ImageMenuItemProtocol

    Declaration

    Swift

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

    Declaration

    Swift

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

    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 ImageMenuItemProtocol.

    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 ImageMenuItemProtocol.

    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 ImageMenuItemProtocol.

    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 ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)
  • Creates a new `GtkImageMenuItem` with an empty label.
    

    new is deprecated: Use gtk_menu_item_new() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    init()
  • Creates a new GtkImageMenuItem containing the image and text from a stock item. Some stock ids have preprocessor macros like GTK_STOCK_OK and GTK_STOCK_APPLY.

    If you want this menu item to have changeable accelerators, then pass in nil for accel_group. Next call gtk_menu_item_set_accel_path() with an appropriate path for the menu item, use gtk_stock_lookup() to look up the standard accelerator for the stock item, and if one is found, call gtk_accel_map_add_entry() to register it.

    new_from_stock is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    init<AccelGroupT>(stock stockID: UnsafePointer<gchar>!, accelGroup: AccelGroupT?) where AccelGroupT : AccelGroupProtocol
  • Creates a new GtkImageMenuItem containing a label.

    new_with_label is deprecated: Use gtk_menu_item_new_with_label() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    init(label: UnsafePointer<gchar>!)
  • Creates a new GtkImageMenuItem 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.

    new_with_mnemonic is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    init(mnemonic label: UnsafePointer<gchar>!)
  • Creates a new GtkImageMenuItem containing the image and text from a stock item. Some stock ids have preprocessor macros like GTK_STOCK_OK and GTK_STOCK_APPLY.

    If you want this menu item to have changeable accelerators, then pass in nil for accel_group. Next call gtk_menu_item_set_accel_path() with an appropriate path for the menu item, use gtk_stock_lookup() to look up the standard accelerator for the stock item, and if one is found, call gtk_accel_map_add_entry() to register it.

    new_from_stock is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    static func newFrom<AccelGroupT>(stock stockID: UnsafePointer<gchar>!, accelGroup: AccelGroupT?) -> WidgetRef! where AccelGroupT : AccelGroupProtocol
  • Creates a new GtkImageMenuItem containing a label.

    new_with_label is deprecated: Use gtk_menu_item_new_with_label() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    static func imageMenuItemNewWith(label: UnsafePointer<gchar>!) -> WidgetRef!
  • Creates a new GtkImageMenuItem 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.

    new_with_mnemonic is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    static func imageMenuItemNewWith(mnemonic label: UnsafePointer<gchar>!) -> WidgetRef!