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.
-
Untyped pointer to the underlying `GtkImageMenuItem` instance.For type-safe access, use the generated, typed pointer
image_menu_item_ptrproperty instead.Declaration
Swift
public let ptr: UnsafeMutableRawPointer!
-
Designated initialiser from the underlying
Cdata typeDeclaration
Swift
@inlinable init(_ p: UnsafeMutablePointer<GtkImageMenuItem>) -
Designated initialiser from a constant pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init(_ p: UnsafePointer<GtkImageMenuItem>) -
Conditional initialiser from an optional pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafeMutablePointer<GtkImageMenuItem>?) -
Conditional initialiser from an optional, non-mutable pointer to the underlying
Cdata typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafePointer<GtkImageMenuItem>?) -
Conditional initialiser from an optional
gpointerDeclaration
Swift
@inlinable init!(gpointer g: gpointer?) -
Conditional initialiser from an optional, non-mutable
gconstpointerDeclaration
Swift
@inlinable init!(gconstpointer g: gconstpointer?) -
Reference intialiser for a related type that implements
ImageMenuItemProtocolDeclaration
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
GtkImageMenuItemcontaining the image and text from a stock item. Some stock ids have preprocessor macros likeGTK_STOCK_OKandGTK_STOCK_APPLY.If you want this menu item to have changeable accelerators, then pass in
nilfor accel_group. Next callgtk_menu_item_set_accel_path()with an appropriate path for the menu item, usegtk_stock_lookup()to look up the standard accelerator for the stock item, and if one is found, callgtk_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
GtkImageMenuItemcontaining 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
GtkImageMenuItemcontaining a label. The label will be created usinggtk_label_new_with_mnemonic(), so underscores inlabelindicate 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
GtkImageMenuItemcontaining the image and text from a stock item. Some stock ids have preprocessor macros likeGTK_STOCK_OKandGTK_STOCK_APPLY.If you want this menu item to have changeable accelerators, then pass in
nilfor accel_group. Next callgtk_menu_item_set_accel_path()with an appropriate path for the menu item, usegtk_stock_lookup()to look up the standard accelerator for the stock item, and if one is found, callgtk_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
GtkImageMenuItemcontaining 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
GtkImageMenuItemcontaining a label. The label will be created usinggtk_label_new_with_mnemonic(), so underscores inlabelindicate 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!
View on GitHub
Install in Dash
ImageMenuItemRef Structure Reference