Class: Gtk::MenuButton

Inherits:
Widget
  • Object
show all
Defined in:
(unknown)

Overview

The GtkMenuButton widget is used to display a popup when clicked.

An example GtkMenuButton

This popup can be provided either as a GtkPopover or as an abstract GMenuModel.

The GtkMenuButton widget can show either an icon (set with the [propertyGtk.MenuButton:icon-name] property) or a label (set with the [propertyGtk.MenuButton:label] property). If neither is explicitly set, a [classGtk.Image] is automatically created, using an arrow image oriented according to [propertyGtk.MenuButton:direction] or the generic “open-menu-symbolic” icon if the direction is not set.

The positioning of the popup is determined by the [propertyGtk.MenuButton:direction] property of the menu button.

For menus, the [propertyGtk.Widget:halign] and [propertyGtk.Widget:valign] properties of the menu are also taken into account. For example, when the direction is %GTK_ARROW_DOWN and the horizontal alignment is %GTK_ALIGN_START, the menu will be positioned below the button, with the starting edge (depending on the text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is popped up above the button instead. If the alignment would move part of the menu offscreen, it is “pushed in”.

start center end
down
up
left
right

CSS nodes

menubutton
╰── button.toggle
    ╰── <content>
         ╰── [arrow]

GtkMenuButton has a single CSS node with name menubutton which contains a button node with a .toggle style class.

If the button contains an icon, it will have the .image-button style class, if it contains text, it will have .text-button style class. If an arrow is visible in addition to an icon, text or a custom child, it will also have .arrow-button style class.

Inside the toggle button content, there is an arrow node for the indicator, which will carry one of the .none, .up, .down, .left or .right style classes to indicate the direction that the menu will appear in. The CSS is expected to provide a suitable image for each of these cases using the -gtk-icon-source property.

Optionally, the menubutton node can carry the .circular style class to request a round appearance.

Accessibility

GtkMenuButton uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.

Instance Method Summary collapse

Methods inherited from Widget

#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #children, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=

Constructor Details

#initializeGtk::Widget

Creates a new GtkMenuButton widget with downwards-pointing arrow as the only child.

You can replace the child widget with another GtkWidget should you wish to.

Instance Method Details

#activeBoolean

Returns whether the menu button is active.

Returns:

  • (Boolean)

    TRUE if the button is active

#active=(active) ⇒ Boolean

Whether the menu button is active.

Parameters:

  • active (Boolean)

Returns:

  • (Boolean)

    active

  • (Boolean)

    active

#active?Boolean

Whether the menu button is active.

Returns:

  • (Boolean)

    active

#always_show_arrowBoolean

Gets whether to show a dropdown arrow even when using an icon or a custom child. child.

Returns:

  • (Boolean)

    whether to show a dropdown arrow even when using an icon or a custom

#always_show_arrow=(always_show_arrow) ⇒ Boolean

Whether to show a dropdown arrow even when using an icon or a custom child.

Parameters:

  • always_show_arrow (Boolean)

Returns:

  • (Boolean)

    always-show-arrow

  • (Boolean)

    always-show-arrow

#always_show_arrow?Boolean

Whether to show a dropdown arrow even when using an icon or a custom child.

Returns:

  • (Boolean)

    always-show-arrow

#can_shrinkBoolean

Retrieves whether the button can be smaller than the natural size of its contents.

Returns:

  • (Boolean)

    true if the button can shrink, and false otherwise

#can_shrink=(can_shrink) ⇒ Boolean

Whether the size of the button can be made smaller than the natural size of its contents.

Parameters:

  • can_shrink (Boolean)

Returns:

  • (Boolean)

    can-shrink

  • (Boolean)

    can-shrink

#can_shrink?Boolean

Whether the size of the button can be made smaller than the natural size of its contents.

Returns:

  • (Boolean)

    can-shrink

#childGtk::Widget

The child widget.

Returns:

#child=(child) ⇒ Gtk::Widget

The child widget.

Parameters:

Returns:

#directionGtk::ArrowType

The GtkArrowType representing the direction in which the menu or popover will be popped out.

Returns:

#direction=(direction) ⇒ Gtk::ArrowType

The GtkArrowType representing the direction in which the menu or popover will be popped out.

Parameters:

Returns:

#has_frameBoolean

Returns whether the button has a frame.

Returns:

  • (Boolean)

    true if the button has a frame

#has_frame=(has_frame) ⇒ Boolean

Whether the button has a frame.

Parameters:

  • has_frame (Boolean)

Returns:

  • (Boolean)

    has-frame

  • (Boolean)

    has-frame

#has_frame?Boolean

Whether the button has a frame.

Returns:

  • (Boolean)

    has-frame

#icon_nameString

The name of the icon used to automatically populate the button.

Returns:

  • (String)

    icon-name

#icon_name=(icon_name) ⇒ String

The name of the icon used to automatically populate the button.

Parameters:

  • icon_name (String)

Returns:

  • (String)

    icon-name

  • (String)

    icon-name

#labelString

The label for the button.

Returns:

  • (String)

    label

#label=(label) ⇒ String

The label for the button.

Parameters:

  • label (String)

Returns:

  • (String)

    label

  • (String)

    label

The GMenuModel from which the popup will be created.

See [methodGtk.MenuButton.set_menu_model] for the interaction with the [propertyGtk.MenuButton:popover] property.

Returns:

  • (Gio::MenuModel)

    menu-model

The GMenuModel from which the popup will be created.

See [methodGtk.MenuButton.set_menu_model] for the interaction with the [propertyGtk.MenuButton:popover] property.

Parameters:

  • menu_model (Gio::MenuModel)

Returns:

  • (Gio::MenuModel)

    menu-model

  • (Gio::MenuModel)

    menu-model

#popdownnil

Dismiss the menu.

Returns:

  • (nil)

#popoverGtk::Popover

The GtkPopover that will be popped up when the button is clicked.

Returns:

#popover=(popover) ⇒ Gtk::Popover

The GtkPopover that will be popped up when the button is clicked.

Parameters:

Returns:

Pop up the menu.

Returns:

  • (nil)

#primaryBoolean

Returns whether the menu button acts as a primary menu.

Returns:

  • (Boolean)

    true if the button is a primary menu

#primary=(primary) ⇒ Boolean

Whether the menu button acts as a primary menu.

Primary menus can be opened using the F10 key

Parameters:

  • primary (Boolean)

Returns:

  • (Boolean)

    primary

  • (Boolean)

    primary

#primary?Boolean

Whether the menu button acts as a primary menu.

Primary menus can be opened using the F10 key

Returns:

  • (Boolean)

    primary

#set_create_popup_func(func, user_data, destroy_notify) ⇒ nil

Sets func to be called when a popup is about to be shown.

func should use one of

  • [methodGtk.MenuButton.set_popover]
  • [methodGtk.MenuButton.set_menu_model]

to set a popup for menu_button. If func is non-nil, menu_button will always be sensitive.

Using this function will not reset the menu widget attached to menu_button. Instead, this can be done manually in func.

Parameters:

  • func (Gtk::MenuButtonCreatePopupFunc)

    function to call when a popup is about to be shown, but none has been provided via other means, or nil to reset to default behavior.

  • user_data (GObject)

    user data to pass to func.

  • destroy_notify (GLib::DestroyNotify)

    destroy notify for user_data

Returns:

  • (nil)

#use_underlineBoolean

Returns whether an embedded underline in the text indicates a mnemonic.

Returns:

  • (Boolean)

    true whether an embedded underline in the text indicates the mnemonic accelerator keys.

#use_underline=(use_underline) ⇒ Boolean

If set an underscore in the text indicates a mnemonic.

Parameters:

  • use_underline (Boolean)

Returns:

  • (Boolean)

    use-underline

  • (Boolean)

    use-underline

#use_underline?Boolean

If set an underscore in the text indicates a mnemonic.

Returns:

  • (Boolean)

    use-underline