Class TreeExpander
- All Implemented Interfaces:
Accessible,Buildable,ConstraintTarget,Proxy
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(org.gnome.gtk.TreeListRow) on the expander.
The expander will then watch that row item automatically.
setChild(org.gnome.gtk.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
ShiftorCtrl+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.expandexpands the expander if it can be expanded.listitem.collapsecollapses the expander.listitem.toggle-expandtries 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTreeExpander.Builder<B extends TreeExpander.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.Widget$Impl, Widget.WidgetClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.Accessible$Impl, Accessible.AccessibleInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TreeExpander.TreeExpander(MemorySegment address) Create a TreeExpander proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected TreeExpanderasParent()Returns this instance as if it were its parent type.static TreeExpander.Builder<? extends TreeExpander.Builder> builder()ATreeExpander.Builderobject constructs aTreeExpanderwith the specified properties.@Nullable WidgetgetChild()Gets the child widget displayed byself.booleanGets whether the TreeExpander should be hidden in a GtkTreeListRow.booleanTreeExpander indents each level of depth with an additional indent.booleanTreeExpander indents the child by the width of an expander-icon if it is not expandable.@Nullable GObjectgetItem()Forwards the item set on theGtkTreeListRowthat this TreeExpander is managing.@Nullable TreeListRowGets the list row managed byself.static @Nullable TypegetType()Get the GType of the TreeExpander classvoidSets the content widget to display.voidsetHideExpander(boolean hideExpander) Sets whether the expander icon should be visible in a GtkTreeListRow.voidsetIndentForDepth(boolean indentForDepth) Sets if the TreeExpander should indent the child according to its depth.voidsetIndentForIcon(boolean indentForIcon) Sets if the TreeExpander should indent the child by the width of an expander-icon when it is not expandable.voidsetListRow(@Nullable TreeListRow listRow) Sets the tree list row that this expander should manage.Methods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateDefault, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getLimitEvents, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getMemoryLayout, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setLimitEvents, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlagsMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateStateMethods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
TreeExpander
Create a TreeExpander proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
TreeExpander
public TreeExpander()Creates a new TreeExpander.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getChild
Gets the child widget displayed byself.- 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
Forwards the item set on theGtkTreeListRowthat 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
Gets the list row managed byself.- Returns:
- The list row displayed by this TreeExpander
-
setChild
Sets the content widget to display.- Parameters:
child- aGtkWidget
-
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
Sets the tree list row that this expander should manage.- Parameters:
listRow- aGtkTreeListRow
-
builder
ATreeExpander.Builderobject constructs aTreeExpanderwith the specified properties. Use the variousset...()methods to set properties, and finish construction withTreeExpander.Builder.build().- Returns:
- the builder object
-