Class ButtonContent

All Implemented Interfaces:
PointerInterface

public class ButtonContent extends Widget
A helper widget for creating buttons.

<picture>
<source srcset="button-content-dark.png" media="(prefers-color-scheme: dark)">
<img src="button-content.png" alt="button-content">
</picture>

`AdwButtonContent` is a box-like widget with an icon and a label.

It's intended to be used as a direct child of [class@Gtk.Button],
[class@Gtk.MenuButton] or [class@SplitButton], when they need to have both an
icon and a label, as follows:

```xml
<object class="GtkButton">
<property name="child">
<object class="AdwButtonContent">
<property name="icon-name">document-open-symbolic</property>
<property name="label" translatable="yes">_Open</property>
<property name="use-underline">True</property>
</object>
</property>
</object>
```

`AdwButtonContent` handles style classes and connecting the mnemonic to the
button automatically.

## CSS nodes

```
buttoncontent
├── image
╰── label
```

`AdwButtonContent`'s CSS node is called `buttoncontent`. It contains the
subnodes `image` and `label`.

When inside a `GtkButton` or `AdwSplitButton`, the button will receive the
`.image-text-button` style class. When inside a `GtkMenuButton`, the
internal `GtkButton` will receive it instead.

## Accessibility

`AdwButtonContent` uses the `GTK_ACCESSIBLE_ROLE_GROUP` role.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.ButtonContent.html

  • Constructor Details

    • ButtonContent

      public ButtonContent(PointerContainer pointer)
    • ButtonContent

      public ButtonContent()
      Creates a new `AdwButtonContent`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getIconName

      public Str getIconName()
      Gets the name of the displayed icon.
      Returns:
      the icon name
    • getLabel

      public Str getLabel()
      Gets the displayed label.
      Returns:
      the label
    • getUseUnderline

      public boolean getUseUnderline()
      Gets whether an underline in the text indicates a mnemonic.
      Returns:
      whether an underline in the text indicates a mnemonic
    • setIconName

      public void setIconName(@Nonnull Str icon_name)
      Sets the name of the displayed icon.

      If empty, the icon is not shown.
      Parameters:
      icon_name - the new icon name
    • setIconName

      public void setIconName(String icon_name)
      Sets the name of the displayed icon.

      If empty, the icon is not shown.
      Parameters:
      icon_name - the new icon name
    • setLabel

      public void setLabel(@Nonnull Str label)
      Sets the displayed label.
      Parameters:
      label - the new label
    • setLabel

      public void setLabel(String label)
      Sets the displayed label.
      Parameters:
      label - the new label
    • setUseUnderline

      public void setUseUnderline(boolean use_underline)
      Sets whether an underline in the text indicates a mnemonic.

      The mnemonic can be used to activate the parent button.

      See [property@ButtonContent:label].
      Parameters:
      use_underline - whether an underline in the text indicates a mnemonic
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()