ImageMenuItemProtocol

public protocol ImageMenuItemProtocol : MenuItemProtocol

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 ImageMenuItemProtocol protocol exposes the methods and properties of an underlying GtkImageMenuItem instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see ImageMenuItem. Alternatively, use ImageMenuItemRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkImageMenuItem instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • image_menu_item_ptr Default implementation

    Typed pointer to the underlying GtkImageMenuItem instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkImageMenuItem instance.

    Declaration

    Swift

    var image_menu_item_ptr: UnsafeMutablePointer<GtkImageMenuItem>! { get }
  • Required Initialiser for types conforming to ImageMenuItemProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

ImageMenuItem Class

  • Bind a ImageMenuItemPropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: ImageMenuItemPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a ImageMenuItem property

    Declaration

    Swift

    @inlinable
    func get(property: ImageMenuItemPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    Set the value of a ImageMenuItem property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: ImageMenuItemPropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

ImageMenuItem Class: ImageMenuItemProtocol extension (methods and fields)

  • getAlwaysShowImage() Extension method

    Returns whether the menu item will ignore the GtkSettings:gtk-menu-images setting and always show the image, if available.

    get_always_show_image is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func getAlwaysShowImage() -> Bool
  • getImage() Extension method

    Gets the widget that is currently set as the image of image_menu_item. See gtk_image_menu_item_set_image().

    get_image is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func getImage() -> WidgetRef!
  • getUseStock() Extension method

    Checks whether the label set in the menuitem is used as a stock id to select the stock item for the item.

    get_use_stock is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func getUseStock() -> Bool
  • set(accelGroup:) Extension method

    Specifies an accel_group to add the menu items accelerator to (this only applies to stock items so a stock item must already be set, make sure to call gtk_image_menu_item_set_use_stock() and gtk_menu_item_set_label() with a valid stock item first).

    If you want this menu item to have changeable accelerators then you shouldnt need this (see gtk_image_menu_item_new_from_stock()).

    set_accel_group is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func set<AccelGroupT>(accelGroup: AccelGroupT) where AccelGroupT : AccelGroupProtocol
  • If true, the menu item will ignore the GtkSettings:gtk-menu-images setting and always show the image, if available.

    Use this property if the menuitem would be useless or hard to use without the image.

    set_always_show_image is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func setAlwaysShowImage(alwaysShow: Bool)
  • set(image:) Extension method

    Sets the image of image_menu_item to the given widget. Note that it depends on the show-menu-images setting whether the image will be displayed or not.

    set_image is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func set(image: WidgetRef? = nil)
  • set(image:) Extension method

    Sets the image of image_menu_item to the given widget. Note that it depends on the show-menu-images setting whether the image will be displayed or not.

    set_image is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func set<WidgetT>(image: WidgetT?) where WidgetT : WidgetProtocol
  • set(useStock:) Extension method

    If true, the label set in the menuitem is used as a stock id to select the stock item for the item.

    set_use_stock is deprecated: This method is deprecated.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    func set(useStock: Bool)
  • alwaysShowImage Extension method

    Returns whether the menu item will ignore the GtkSettings:gtk-menu-images setting and always show the image, if available.

    get_always_show_image is deprecated: This method is deprecated.

    Declaration

    Swift

    @inlinable
    var alwaysShowImage: Bool { get nonmutating set }
  • image Extension method

    Child widget to appear next to the menu text.

    image is deprecated: Use a #GtkMenuItem containing a #GtkBox with a #GtkAccelLabel and a #GtkImage instead

    Declaration

    Swift

    @inlinable
    var image: WidgetRef! { get nonmutating set }
  • useStock Extension method

    Checks whether the label set in the menuitem is used as a stock id to select the stock item for the item.

    get_use_stock is deprecated: This method is deprecated.

    Declaration

    Swift

    @inlinable
    var useStock: Bool { get nonmutating set }
  • menuItem Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var menuItem: GtkMenuItem { get }