gtk.model_button

Module for [ModelButton] class

Types 3

GtkModelButton is a button class that can use a #GAction as its model. In contrast to #GtkToggleButton or #GtkRadioButton, which can also be backed by a #GAction via the #GtkActionable: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.Popover.newFromModel]; they can also be used manually in a #GtkPopoverMenu.

When the action is specified via the #GtkActionable:action-name and #GtkActionable: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 #GtkModelButton:role property.

The content of the button is specified by the #GtkModelButton:text and #GtkModelButton:icon properties.

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

Model buttons have built-in support for submenus in #GtkPopoverMenu. To make a GtkModelButton that opens a submenu when activated, set the #GtkModelButton:menu-name property. To make a button that goes back to the parent menu, you should set the #GtkModelButton: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

modelbutton
├── <child>
╰── check

modelbutton
├── <child>
╰── radio

modelbutton
├── <child>
╰── arrow

GtkModelButton has a main CSS node with name modelbutton, and a subnode, which will have the name check, radio or arrow, depending on the role of the button and whether it has a menu name set.

The subnode is positioned before or after the content nodes and gets the .left or .right style class, depending on where it is located.

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

Iconic model buttons (see #GtkModelButton: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.

Methods
GType _gType() @property
ModelButton self()Returns `this`, for use in `with` statements.
ModelButtonGidBuilder builder()Get builder for [gtk.model_button.ModelButton] Returns: New builder object
bool active() @propertyGet `active` property. Returns: The state of the button. This is reflecting the state of the associated #GAction.
void active(bool propval) @propertySet `active` property. Params: propval = The state of the button. This is reflecting the state of the associated #GAction.
bool centered() @propertyGet `centered` property. Returns: Whether to render the button contents centered instead of left-aligned. This property should be set for title-like items.
void centered(bool propval) @propertySet `centered` property. Params: propval = Whether to render the button contents centered instead of left-aligned. This property should be set for title-like items.
gio.icon.Icon icon() @propertyGet `icon` property. Returns: A #GIcon that will be used if iconic appearance for the button is desired.
void icon(gio.icon.Icon propval) @propertySet `icon` property. Params: propval = A #GIcon that will be used if iconic appearance for the button is desired.
bool iconic() @propertyGet `iconic` property. Returns: 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 link...
void iconic(bool propval) @propertySet `iconic` property. Params: propval = 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 section...
bool inverted() @propertyGet `inverted` property. Returns: 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.
void inverted(bool propval) @propertySet `inverted` property. Params: propval = 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.
string menuName() @propertyGet `menuName` property. Returns: 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.
void menuName(string propval) @propertySet `menuName` property. Params: propval = 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.
gtk.types.ButtonRole role() @propertyGet `role` property. Returns: Specifies whether the button is a plain, check or radio button. When #GtkActionable:action-name is set, the role will be determined from the action and does not have t...
void role(gtk.types.ButtonRole propval) @propertySet `role` property. Params: propval = Specifies whether the button is a plain, check or radio button. When #GtkActionable:action-name is set, the role will be determined from the action and does n...
string text() @propertyGet `text` property. Returns: The label for the button.
void text(string propval) @propertySet `text` property. Params: propval = The label for the button.
bool useMarkup() @propertyGet `useMarkup` property. Returns: If true, XML tags in the text of the button are interpreted as by [pango.global.parseMarkup] to format the enclosed spans of text. If false, the text will be disp...
void useMarkup(bool propval) @propertySet `useMarkup` property. Params: propval = If true, XML tags in the text of the button are interpreted as by [pango.global.parseMarkup] to format the enclosed spans of text. If false, the text wil...
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new GtkModelButton. Returns: the newly created #GtkModelButton widget
Methods
T active(bool propval)Set `active` property. Params: propval = The state of the button. This is reflecting the state of the associated #GAction. Returns: Builder instance for fluent chaining
T centered(bool propval)Set `centered` property. Params: propval = Whether to render the button contents centered instead of left-aligned. This property should be set for title-like items. Returns: Builder instance for fl...
T icon(gio.icon.Icon propval)Set `icon` property. Params: propval = A #GIcon that will be used if iconic appearance for the button is desired. Returns: Builder instance for fluent chaining
T iconic(bool propval)Set `iconic` property. Params: propval = 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 section...
T inverted(bool propval)Set `inverted` property. Params: propval = 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. Ret...
T menuName(string propval)Set `menuName` property. Params: propval = 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: Builder inst...
T role(gtk.types.ButtonRole propval)Set `role` property. Params: propval = Specifies whether the button is a plain, check or radio button. When #GtkActionable:action-name is set, the role will be determined from the action and does n...
T text(string propval)Set `text` property. Params: propval = The label for the button. Returns: Builder instance for fluent chaining
T useMarkup(bool propval)Set `useMarkup` property. Params: propval = If true, XML tags in the text of the button are interpreted as by [pango.global.parseMarkup] to format the enclosed spans of text. If false, the text wil...

Fluent builder for [gtk.model_button.ModelButton]