Class TreeExpander

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

@Generated("org.javagi.JavaGI") public class TreeExpander extends Widget implements Accessible, Buildable, ConstraintTarget

Provides an expander for a tree-like list.

It is typically placed as a bottommost child into a GtkListView to allow users to expand and collapse children in a list with a TreeListModel. GtkTreeExpander provides the common UI elements, gestures and keybindings for this purpose.

On top of this, the "listitem.expand", "listitem.collapse" and "listitem.toggle-expand" actions are provided to allow adding custom UI for managing expanded state.

It is important to mention that you want to set the Gtk.ListItem:focusable property to FALSE when using this widget, as you want the keyboard focus to be in the treexpander, and not inside the list to make use of the keybindings.

The GtkTreeListModel must be set to not be passthrough. Then it will provide TreeListRow items which can be set via setListRow(TreeListRow) on the expander. The expander will then watch that row item automatically. setChild(Widget) sets the widget that displays the actual row contents.

GtkTreeExpander can be modified with properties such as Gtk.TreeExpander:indent-for-icon, Gtk.TreeExpander:indent-for-depth, and Gtk.TreeExpander:hide-expander to achieve a different appearance. This can even be done to influence individual rows, for example by binding the Gtk.TreeExpander:hide-expander property to the item count of the model of the treelistrow, to hide the expander for rows without children, even if the row is expandable.

Shortcuts and Gestures

GtkTreeExpander supports the following keyboard shortcuts:

  • + or * expands the expander.
  • - or / collapses the expander.
  • Left and right arrow keys, when combined with Shift or Ctrl+Shift, will expand or collapse, depending on the locale's text direction.
  • Ctrl+ toggles the expander state.

The row can also expand on drag gestures.

Actions

GtkTreeExpander defines a set of built-in actions:

  • listitem.expand expands the expander if it can be expanded.
  • listitem.collapse collapses the expander.
  • listitem.toggle-expand tries to expand the expander if it was collapsed or collapses it if it was expanded.

CSS nodes

treeexpander
├── [indent]*
├── [expander]
╰── <child>

GtkTreeExpander has zero or one CSS nodes with the name "expander" that should display the expander icon. The node will be :checked when it is expanded. If the node is not expandable, an "indent" node will be displayed instead.

For every level of depth, another "indent" node is prepended.

Accessibility

Until GTK 4.10, GtkTreeExpander used the Gtk.AccessibleRole.group role.

Since GTK 4.12, GtkTreeExpander uses the Gtk.AccessibleRole.button role. Toggling it will change the GTK_ACCESSIBLE_STATE_EXPANDED state.

  • Constructor Details

    • TreeExpander

      public TreeExpander(MemorySegment address)
      Create a TreeExpander instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • TreeExpander

      public TreeExpander()
      Create a new TreeExpander.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the TreeExpander class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected TreeExpander asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • getChild

      public @Nullable Widget getChild()
      Gets the child widget displayed by self.
      Returns:
      The child displayed by this TreeExpander
    • getHideExpander

      public boolean getHideExpander()
      Gets whether the TreeExpander should be hidden in a GtkTreeListRow.
      Returns:
      TRUE if the expander icon should be hidden. Otherwise FALSE.
      Since:
      4.10
    • getIndentForDepth

      public boolean getIndentForDepth()
      TreeExpander indents each level of depth with an additional indent.
      Returns:
      TRUE if the child should be indented . Otherwise FALSE.
      Since:
      4.10
    • getIndentForIcon

      public boolean getIndentForIcon()
      TreeExpander indents the child by the width of an expander-icon if it is not expandable.
      Returns:
      TRUE if the child should be indented when not expandable. Otherwise FALSE.
      Since:
      4.6
    • getItem

      public @Nullable GObject getItem()

      Forwards the item set on the GtkTreeListRow that this TreeExpander is managing.

      This call is essentially equivalent to calling:

      gtk_tree_list_row_get_item (gtk_tree_expander_get_list_row (@self));
      
      Returns:
      The item of the row
    • getListRow

      public @Nullable TreeListRow getListRow()
      Gets the list row managed by self.
      Returns:
      The list row displayed by this TreeExpander
    • setChild

      public void setChild(@Nullable Widget child)
      Sets the content widget to display.
      Parameters:
      child - a GtkWidget
    • setHideExpander

      public void setHideExpander(boolean hideExpander)
      Sets whether the expander icon should be visible in a GtkTreeListRow.
      Parameters:
      hideExpander - TRUE if the expander should be hidden. Otherwise FALSE.
      Since:
      4.10
    • setIndentForDepth

      public void setIndentForDepth(boolean indentForDepth)
      Sets if the TreeExpander should indent the child according to its depth.
      Parameters:
      indentForDepth - TRUE if the child should be indented. Otherwise FALSE.
      Since:
      4.10
    • setIndentForIcon

      public void setIndentForIcon(boolean indentForIcon)
      Sets if the TreeExpander should indent the child by the width of an expander-icon when it is not expandable.
      Parameters:
      indentForIcon - TRUE if the child should be indented without expander. Otherwise FALSE.
      Since:
      4.6
    • setListRow

      public void setListRow(@Nullable TreeListRow listRow)
      Sets the tree list row that this expander should manage.
      Parameters:
      listRow - a GtkTreeListRow
    • builder

      public static TreeExpander.Builder<? extends TreeExpander.Builder> builder()
      A TreeExpander.Builder object constructs a TreeExpander with the specified properties. Use the various set...() methods to set properties, and finish construction with TreeExpander.Builder.build().
      Returns:
      the builder object