Class: Gtk::ModelButton

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

Overview

GtkModelButton is a button class that can use a #GAction as its model. In contrast to Gtk::ToggleButton or #GtkRadioButton, which can also be backed by a #GAction via the Gtk::Actionable:action-name property, GtkModelButton will adapt its appearance according to the kind of action it is backed by, and appear either as a plain, check or radio button.

Model buttons are used when popovers from a menu model with gtk_popover_new_from_model(); they can also be used manually in a Gtk::PopoverMenu.

When the action is specified via the Gtk::Actionable:action-name and Gtk::Actionable:action-target properties, the role of the button (i.e. whether it is a plain, check or radio button) is determined by the type of the action and doesn’t have to be explicitly specified with the Gtk::ModelButton:role property.

The content of the button is specified by the Gtk::ModelButton:text and Gtk::ModelButton:icon properties.

The appearance of model buttons can be influenced with the Gtk::ModelButton:centered and #GtkModelButton:iconic properties.

Model buttons have built-in support for submenus in Gtk::PopoverMenu. To make a GtkModelButton that opens a submenu when activated, set the Gtk::ModelButton:menu-name property. To make a button that goes back to the parent menu, you should set the Gtk::ModelButton:inverted property to place the submenu indicator at the opposite side.

# Example

|[ <object class=“GtkPopoverMenu”>

<child>
  <object class="GtkBox">
    <property name="visible">True</property>
    <property name="margin">10</property>
    <child>
      <object class="GtkModelButton">
        <property name="visible">True</property>
        <property name="action-name">view.cut</property>
        <property name="text" translatable="yes">Cut</property>
      </object>
    </child>
    <child>
      <object class="GtkModelButton">
        <property name="visible">True</property>
        <property name="action-name">view.copy</property>
        <property name="text" translatable="yes">Copy</property>
      </object>
    </child>
    <child>
      <object class="GtkModelButton">
        <property name="visible">True</property>
        <property name="action-name">view.paste</property>
        <property name="text" translatable="yes">Paste</property>
      </object>
    </child>
  </object>
</child>

</object> ]|

# CSS nodes

button.model
├── <child>
╰── check

Iconic model buttons (see Gtk::ModelButton:iconic) change the name of their main node to button and add a .model style class to it. The indicator subnode is invisible in this case.

Instance Method Summary collapse

Instance Method Details

#active=(active) ⇒ TrueClass

The state of the button. This is reflecting the state of the associated #GAction.

Parameters:

  • active (TrueClass)

Returns:

  • (TrueClass)

    active

  • (TrueClass)

    active

#active?TrueClass

The state of the button. This is reflecting the state of the associated #GAction.

Returns:

  • (TrueClass)

    active

#centered=(centered) ⇒ TrueClass

Whether to render the button contents centered instead of left-aligned. This property should be set for title-like items.

Parameters:

  • centered (TrueClass)

Returns:

  • (TrueClass)

    centered

  • (TrueClass)

    centered

#centered?TrueClass

Whether to render the button contents centered instead of left-aligned. This property should be set for title-like items.

Returns:

  • (TrueClass)

    centered

#iconGio::Icon

A #GIcon that will be used if iconic appearance for the button is desired.

Returns:

#icon=(icon) ⇒ Gio::Icon

A #GIcon that will be used if iconic appearance for the button is desired.

Parameters:

Returns:

#iconic=(iconic) ⇒ TrueClass

If this property is set, the button will show an icon if one is set. If no icon is set, the text will be used. This is typically used for horizontal sections of linked buttons.

Parameters:

  • iconic (TrueClass)

Returns:

  • (TrueClass)

    iconic

  • (TrueClass)

    iconic

#iconic?TrueClass

If this property is set, the button will show an icon if one is set. If no icon is set, the text will be used. This is typically used for horizontal sections of linked buttons.

Returns:

  • (TrueClass)

    iconic

#inverted=(inverted) ⇒ TrueClass

Whether to show the submenu indicator at the opposite side than normal. This property should be set for model buttons that ‘go back’ to a parent menu.

Parameters:

  • inverted (TrueClass)

Returns:

  • (TrueClass)

    inverted

  • (TrueClass)

    inverted

#inverted?TrueClass

Whether to show the submenu indicator at the opposite side than normal. This property should be set for model buttons that ‘go back’ to a parent menu.

Returns:

  • (TrueClass)

    inverted

The name of a submenu to open when the button is activated. If this is set, the button should not have an action associated with it.

Returns:

  • (String)

    menu-name

The name of a submenu to open when the button is activated. If this is set, the button should not have an action associated with it.

Parameters:

  • menu_name (String)

Returns:

  • (String)

    menu-name

  • (String)

    menu-name

#newGtk::Widget

Creates a new GtkModelButton.

Returns:

  • (Gtk::Widget)

    the newly created Gtk::ModelButton widget

#roleGtk::ButtonRole

Specifies whether the button is a plain, check or radio button. When Gtk::Actionable:action-name is set, the role will be determined from the action and does not have to be set explicitly.

Returns:

#role=(role) ⇒ Gtk::ButtonRole

Specifies whether the button is a plain, check or radio button. When Gtk::Actionable:action-name is set, the role will be determined from the action and does not have to be set explicitly.

Parameters:

Returns:

#textString

The label for the button.

Returns:

  • (String)

    text

#text=(text) ⇒ String

The label for the button.

Parameters:

  • text (String)

Returns:

  • (String)

    text

  • (String)

    text

#use_markup=(use_markup) ⇒ TrueClass

If true, XML tags in the text of the button are interpreted as by pango_parse_markup() to format the enclosed spans of text. If false, the text will be displayed verbatim.

Parameters:

  • use_markup (TrueClass)

Returns:

  • (TrueClass)

    use-markup

  • (TrueClass)

    use-markup

#use_markup?TrueClass

If true, XML tags in the text of the button are interpreted as by pango_parse_markup() to format the enclosed spans of text. If false, the text will be displayed verbatim.

Returns:

  • (TrueClass)

    use-markup