Class Expander

All Implemented Interfaces:
PointerInterface

public class Expander extends Widget
`GtkExpander` allows the user to reveal its child by clicking
on an expander triangle.

![An example GtkExpander](expander.png)

This is similar to the triangles used in a `GtkTreeView`.

Normally you use an expander as you would use a frame; you create
the child widget and use [method@Gtk.Expander.set_child] to add it
to the expander. When the expander is toggled, it will take care of
showing and hiding the child automatically.

# Special Usage

There are situations in which you may prefer to show and hide the
expanded widget yourself, such as when you want to actually create
the widget at expansion time. In this case, create a `GtkExpander`
but do not add a child to it. The expander widget has an
[property@Gtk.Expander:expanded[ property which can be used to
monitor its expansion state. You should watch this property with
a signal connection as follows:

```c
static void
expander_callback (GObject *object,
GParamSpec *param_spec,
gpointer user_data)
{
GtkExpander *expander;

expander = GTK_EXPANDER (object);

if (gtk_expander_get_expanded (expander))
{
// Show or create widgets
}
else
{
// Hide or destroy widgets
}
}

static void
create_expander (void)
{
GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options");
g_signal_connect (expander, "notify::expanded",
G_CALLBACK (expander_callback), NULL);

// ...
}
```

# GtkExpander as GtkBuildable

The `GtkExpander` implementation of the `GtkBuildable` interface supports
placing a child in the label position by specifying “label” as the
“type” attribute of a <child> element. A normal content child can be
specified without specifying a <child> type attribute.

An example of a UI definition fragment with GtkExpander:

```xml
<object class="GtkExpander">
<child type="label">
<object class="GtkLabel" id="expander-label"/>
</child>
<child>
<object class="GtkEntry" id="expander-content"/>
</child>
</object>
```

# CSS nodes

```
expander
╰── box
├── title
│ ├── arrow
│ ╰── <label widget>
╰── <child>
```

`GtkExpander` has three CSS nodes, the main node with the name expander,
a subnode with name title and node below it with name arrow. The arrow of an
expander that is showing its child gets the :checked pseudoclass added to it.

# Accessibility

`GtkExpander` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.

https://docs.gtk.org/gtk4/class.Expander.html

  • Field Details

  • Constructor Details

    • Expander

      public Expander(PointerContainer pointer)
    • Expander

      public Expander(@Nullable Str label)
      Creates a new expander using @label as the text of the label.
      Parameters:
      label - the text of the label
    • Expander

      public Expander(String label)
      Creates a new expander using @label as the text of the label.
      Parameters:
      label - the text of the label
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newWithMnemonicExpander

      public static Expander newWithMnemonicExpander(@Nullable Str label)
      Creates a new expander using @label as the text of the label.

      If characters in @label are preceded by an underscore, they are
      underlined. If you need a literal underscore character in a label,
      use “__” (two underscores). The first underlined character represents
      a keyboard accelerator called a mnemonic.

      Pressing Alt and that key activates the button.
      Parameters:
      label - the text of the label with an underscore in front of the mnemonic character
      Returns:
      a new `GtkExpander` widget.
    • newWithMnemonicExpander

      public static Expander newWithMnemonicExpander(String label)
      Creates a new expander using @label as the text of the label.

      If characters in @label are preceded by an underscore, they are
      underlined. If you need a literal underscore character in a label,
      use “__” (two underscores). The first underlined character represents
      a keyboard accelerator called a mnemonic.

      Pressing Alt and that key activates the button.
      Parameters:
      label - the text of the label with an underscore in front of the mnemonic character
      Returns:
      a new `GtkExpander` widget.
    • getChild

      public Widget getChild()
      Gets the child widget of @expander.
      Returns:
      the child widget of @expander
    • getExpanded

      public boolean getExpanded()
      Queries a `GtkExpander` and returns its current state.

      Returns %TRUE if the child widget is revealed.
      Returns:
      the current state of the expander
    • getLabel

      public Str getLabel()
      Fetches the text from a label widget.

      This is including any embedded underlines indicating mnemonics and
      Pango markup, as set by [method@Gtk.Expander.set_label]. If the label
      text has not been set the return value will be %NULL. This will be the
      case if you create an empty button with gtk_button_new() to use as a
      container.
      Returns:
      The text of the label widget. This string is owned by the widget and must not be modified or freed.
    • getLabelWidget

      public Widget getLabelWidget()
      Retrieves the label widget for the frame.
      Returns:
      the label widget
    • getResizeToplevel

      public boolean getResizeToplevel()
      Returns whether the expander will resize the toplevel widget
      containing the expander upon resizing and collpasing.
      Returns:
      the “resize toplevel” setting.
    • getUseMarkup

      public boolean getUseMarkup()
      Returns whether the label’s text is interpreted as Pango markup.
      Returns:
      %TRUE if the label’s text will be parsed for markup
    • getUseUnderline

      public boolean getUseUnderline()
      Returns whether an underline in the text indicates a mnemonic.
      Returns:
      %TRUE if an embedded underline in the expander label indicates the mnemonic accelerator keys
    • setChild

      public void setChild(@Nullable Widget child)
      Sets the child widget of @expander.
      Parameters:
      child - the child widget
    • setExpanded

      public void setExpanded(boolean expanded)
      Sets the state of the expander.

      Set to %TRUE, if you want the child widget to be revealed,
      and %FALSE if you want the child widget to be hidden.
      Parameters:
      expanded - whether the child widget is revealed
    • setLabel

      public void setLabel(@Nullable Str label)
      Sets the text of the label of the expander to @label.

      This will also clear any previously set labels.
      Parameters:
      label - a string
    • setLabel

      public void setLabel(String label)
      Sets the text of the label of the expander to @label.

      This will also clear any previously set labels.
      Parameters:
      label - a string
    • setLabelWidget

      public void setLabelWidget(@Nullable Widget label_widget)
      Set the label widget for the expander.

      This is the widget that will appear embedded alongside
      the expander arrow.
      Parameters:
      label_widget - the new label widget
    • setResizeToplevel

      public void setResizeToplevel(boolean resize_toplevel)
      Sets whether the expander will resize the toplevel widget
      containing the expander upon resizing and collpasing.
      Parameters:
      resize_toplevel - whether to resize the toplevel
    • setUseMarkup

      public void setUseMarkup(boolean use_markup)
      Sets whether the text of the label contains Pango markup.
      Parameters:
      use_markup - %TRUE if the label’s text should be parsed for markup
    • setUseUnderline

      public void setUseUnderline(boolean use_underline)
      If true, an underline in the text indicates a mnemonic.
      Parameters:
      use_underline - %TRUE if underlines in the text indicate mnemonics
    • onActivate

      public SignalHandler onActivate(Expander.OnActivate signal)
      Connect to signal "activate".
      See Expander.OnActivate.onActivate() for signal description.
      Field SIGNAL_ON_ACTIVATE contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • 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()