Class Sidebar
- All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy
Adaptive sidebar widget.
AdwSidebar contains SidebarSection objects, which in turn contain
SidebarItem objects.
To add sections, use append(SidebarSection), prepend(SidebarSection) or
insert(SidebarSection, int).
To remove sections, use remove(SidebarSection) or
removeAll().
To inspect the items, use getItem(int) or
Sidebar:items.
To inspect sections themselves, use getSection(int) or
Sidebar:sections.
Selection and activation
AdwSidebar has zero or one selected items. The index of the item can be
accessed and changed via Sidebar:selected. Set it to
Gtk.INVALID_LIST_POSITION to remove selection.
Selection cannot be permanently disabled.
Sidebar:selected-item can be used to access the selected item.
Connect to the Sidebar::activated signal to run code when an item
has been activated. This can be used to toggle the visible pane when used in
a split view.
See also: ViewSwitcherSidebar.
Modes
AdwSidebar is adaptive and can act as either a regular sidebar, or a page
of boxed lists.
Use the Sidebar:mode to determine its look and behavior.
A typical use case involves using AdwSidebar inside the sidebar pane of a
NavigationSplitView, and switching mode to page whenever it's
collapsed, as follows:
<object class="AdwWindow">
<property name="default-width">800</property>
<property name="default-height">600</property>
<child>
<object class="AdwBreakpoint">
<condition>max-width: 400sp</condition>
<setter object="split_view" property="collapsed">True</setter>
<setter object="sidebar" property="mode">page</setter>
</object>
</child>
<property name="content">
<object class="AdwNavigationSplitView" id="split_view">
<property name="sidebar">
<object class="AdwNavigationPage">
<property name="title" translatable="yes">Sidebar</property>
<property name="child">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar"/>
</child>
<property name="content">
<object class="AdwSidebar" id="sidebar">
<!-- Calls adw_navigation_split_view_set_show_content (split_view, TRUE); -->
<signal name="activated" handler="sidebar_activated_cb"/>
<!-- ... -->
</object>
</property>
</object>
</property>
</object>
</property>
<property name="content">
<object class="AdwNavigationPage">
<property name="title" translatable="yes">Content</property>
<property name="child">
<!-- ... -->
</property>
</object>
</property>
</object>
</property>
</object>
When used with OverlaySplitView, the sidebar should stay in sidebar
mode, as the sidebar pane is still a sidebar when collapsed.
Search
AdwSidebar supports filtering items via the Sidebar:filter
property.
Use Sidebar:placeholder to provide an empty state widget. It will
be shown when all items have been filtered out, or the sidebar has no items
otherwise.
Context Menu
To create a context menu for the sidebar items, use the
Sidebar:menu-model property to provide a menu model, and the
Sidebar::setup-menu signal to set up actions for the given item.
To set or override the menu for just one section, use
SidebarSection:menu-model instead.
Drag-and-Drop
AdwSidebar items can have a drop target for arbitrary content.
Use setupDropTarget(Set, Type[]) to set it up, specifying the
supported content types and drag actions, then connect to
Sidebar::drop to handle drops.
In some cases, it may be necessary to determine the used action based on the dragged content, or the hovered item.
To determine it based on the sidebar item, connect to the
Sidebar::drop-enter signal and return the action from its handler.
To determine it based on the content, set Sidebar:drop-preload to
TRUE, then connect to Sidebar::drop-value-loaded signal and return
the action from its handler.
In both cases the action will be passed as a parameter to the
Sidebar::drop signal.
Regardless of whether a drop target was set up, dragging content over sidebar
items activates them after a timeout. To disable this behavior for specific
items, set SidebarItem:drag-motion-activate to FALSE on them.
AdwSidebar as GtkBuildable
AdwSidebar allows adding sections as children.
Example of an AdwSidebar UI definition:
<object class="AdwSidebar">
<child>
<object class="AdwSidebarSection">
<child>
<object class="AdwSidebarItem">
<property name="title" translatable="yes">Recent</property>
<property name="icon-name">document-open-recent-symbolic</property>
</object>
</child>
<child>
<object class="AdwSidebarItem">
<property name="title" translatable="yes">Starred</property>
<property name="icon-name">starred-symbolic</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwSidebarSection">
<property name="title" translatable="yes">Places</property>
<child>
<object class="AdwSidebarItem">
<property name="title" translatable="yes">Music</property>
<property name="icon-name">folder-music-symbolic</property>
</object>
</child>
<child>
<object class="AdwSidebarItem">
<property name="title" translatable="yes">Pictures</property>
<property name="icon-name">folder-pictures-symbolic</property>
</object>
</child>
<child>
<object class="AdwSidebarItem">
<property name="title" translatable="yes">Videos</property>
<property name="icon-name">folder-videos-symbolic</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwSidebarSection">
<child>
<object class="AdwSidebarItem">
<property name="title" translatable="yes">Trash</property>
<property name="icon-name">user-trash-symbolic</property>
</object>
</child>
</object>
</child>
</object>
CSS nodes
AdwSidebar has a main CSS node with the name sidebar.
Internally, it's using a ListBox with the
.navigation-sidebar style class in sidebar
mode, or an PreferencesPage in page mode.
Accessibility
AdwSidebar uses the Gtk.AccessibleRole.generic role.
- Since:
- 1.9
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theActivatedCallbackcallback.static classSidebar.Builder<B extends Sidebar.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theDropCallbackcallback.static interfaceFunctional interface declaration of theDropEnterCallbackcallback.static interfaceFunctional interface declaration of theDropValueLoadedCallbackcallback.static interfaceFunctional interface declaration of theSetupMenuCallbackcallback.static classNested classes/interfaces inherited from class 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 InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface Accessible
Accessible.Accessible$Impl, Accessible.AccessibleInterfaceNested classes/interfaces inherited from interface Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterface -
Constructor Summary
ConstructorsConstructorDescriptionSidebar()Create a new Sidebar.Sidebar(MemorySegment address) Create a Sidebar instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(SidebarSection section) Appendssectiontoself.protected SidebarasParent()Return this instance as if it were its parent type.static Sidebar.Builder<? extends Sidebar.Builder> builder()ASidebar.Builderobject constructs aSidebarwith the specified properties.voidemitActivated(int index) Emits the "activated" signal.booleanemitDrop(int index, @Nullable Value value, Set<DragAction> preferredAction) Emits the "drop" signal.emitDropEnter(int index) Emits the "drop-enter" signal.emitDropValueLoaded(int index, @Nullable Value value) Emits the "drop-value-loaded" signal.voidemitSetupMenu(@Nullable SidebarItem item) Emits the "setup-menu" signal.booleanGets whether drop data should be preloaded on hover.@Nullable FilterGets the item filter forself.@Nullable SidebarItemgetItem(int index) Gets the item atindexwithinself.getItems()Gets a list model withself'sitems.static MemoryLayoutThe memory layout of the native struct.@Nullable MenuModelGets the context menu model forself'sitems.getMode()Getsself'slook and behavior.@Nullable WidgetGets the placeholder widget forself.@Nullable SidebarSectiongetSection(int index) Gets the section atindexwithinself.Gets a list model withself'ssections.intGets the index of the currently selected item.@Nullable SidebarItemGets the currently selected item.static @Nullable TypegetType()Get the GType of the Sidebar class.voidinsert(SidebarSection section, int position) Insertssectionatpositiontoself.onActivated(Sidebar.ActivatedCallback handler) Emitted when an item atindexhas been activated.onDrop(Sidebar.DropCallback handler) Emitted when content is dropped onto the item atindex.onDropEnter(Sidebar.DropEnterCallback handler) Emitted when the pointer enters the item atindex.Emitted when the dropped content is preloaded for the item atindex.onSetupMenu(Sidebar.SetupMenuCallback handler) Emitted when a context menu is opened or closed foritem.voidprepend(SidebarSection section) Prependssectiontoself.voidremove(SidebarSection section) Removessectionfromself.voidRemoves all sections fromself.voidsetDropPreload(boolean preload) Sets whether drop data should be preloaded on hover.voidSets the item filter forself.voidsetMenuModel(@Nullable MenuModel menuModel) Sets the context menu model forself'sitems.voidsetMode(SidebarMode mode) Setsself'slook and behavior.voidsetPlaceholder(@Nullable Widget placeholder) Sets the placeholder widget forself.voidsetSelected(int selected) Selects the item atselected.voidsetupDropTarget(Set<DragAction> actions, @Nullable Type @Nullable [] types) Sets up a drop target on the items.voidsetupDropTarget(DragAction actions, @Nullable Type @Nullable [] types) Sets up a drop target on the items.Methods inherited from class 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, 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 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 TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCodeMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Accessible
announce, getAccessibleId, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateStateMethods inherited from interface Buildable
getBuildableId
-
Constructor Details
-
Sidebar
Create a Sidebar instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Sidebar
public Sidebar()Create a new Sidebar.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
-
append
Appendssectiontoself.- Parameters:
section- a section to append- Since:
- 1.9
-
getDropPreload
public boolean getDropPreload()Gets whether drop data should be preloaded on hover.- Returns:
- whether drop data should be preloaded on hover
- Since:
- 1.9
-
getFilter
Gets the item filter forself.- Returns:
- the item filter
- Since:
- 1.9
-
getItem
Gets the item at
indexwithinself.The index starts from 0 at the top of the sidebar, and is same as the one returned by
SidebarItem.getIndex().Can return
NULLifindexis larger or equal to the number of items.- Parameters:
index- index of the item- Returns:
- the item at
index - Since:
- 1.9
-
getItems
Gets a list model with
self'sitems.This can be used to keep an up-to-date view.
The model implements
SectionModeland creates sections corresponding to the sidebar's sections.The model also implements
SelectionModeland can be used to track and change the selection.To only track sections, use
Sidebar:sectionsinstead.- Returns:
- a model containing the items
- Since:
- 1.9
-
getMenuModel
Gets the context menu model forself'sitems.- Returns:
- the context menu model
- Since:
- 1.9
-
getMode
-
getPlaceholder
Gets the placeholder widget forself.- Returns:
- the placeholder widget
- Since:
- 1.9
-
getSection
Gets the section at
indexwithinself.Can return
NULLifindexis larger or equal to the number of sections.- Parameters:
index- index of the section- Returns:
- the section at
index - Since:
- 1.9
-
getSections
Gets a list model with
self'ssections.This can be used to keep an up-to-date view.
To track items, use
Sidebar:itemsinstead.- Returns:
- a model containing the sections
- Since:
- 1.9
-
getSelected
public int getSelected()Gets the index of the currently selected item.
See also:
getSelectedItem().- Returns:
- index of the currently selected item
- Since:
- 1.9
-
getSelectedItem
Gets the currently selected item.
This is a convenience method, equivalent to calling
getItem(int)withSidebar:selectedprovided as the index.To change selection, use
setSelected(int).- Returns:
- the selected item
- Since:
- 1.9
-
insert
Inserts
sectionatpositiontoself.If
positionis -1, or larger than the total number of sections inself,the section will be appended to the end.- Parameters:
section- a section to insertposition- position to insertsectionat- Since:
- 1.9
-
prepend
Prependssectiontoself.- Parameters:
section- a section to prepend- Since:
- 1.9
-
remove
Removessectionfromself.- Parameters:
section- a section to remove- Since:
- 1.9
-
removeAll
public void removeAll()Removes all sections fromself.- Since:
- 1.9
-
setDropPreload
public void setDropPreload(boolean preload) Sets whether drop data should be preloaded on hover.
See
Gtk.DropTarget:preload.- Parameters:
preload- whether to preload drop data- Since:
- 1.9
-
setFilter
Sets the item filter for
self.Can be used to implement search within the sidebar.
Use
Sidebar:placeholderto provide an empty state.- Parameters:
filter- the item filter- Since:
- 1.9
-
setMenuModel
Sets the context menu model for
self'sitems.When a context menu is shown for an item, it will be constructed from the provided menu model. Use the
Sidebar::setup-menusignal to set up the menu actions for the particular item.Sidebar:menu-modelwill be preferred over this model if set.- Parameters:
menuModel- a menu model- Since:
- 1.9
-
setMode
Sets
self'slook and behavior.
If set to
Adw.SidebarMode.sidebar, behaves like a sidebar: with a sidebar style and a persistent selection.If set to
Adw.SidebarMode.page, behaves like a page of boxed lists. In this mode, the selection is invisible and only tracked to determine the initially selected item once switched back to sidebar mode.The page mode is intended to be used with
NavigationSplitViewwhen collapsed, as the sidebar pane becomes a page there.When used with
OverlaySplitView, the sidebar should stay in sidebar mode, as the sidebar pane is still a sidebar when collapsed.- Parameters:
mode- the new mode- Since:
- 1.9
-
setPlaceholder
Sets the placeholder widget for
self.This widget will be shown if this Sidebar has no items, or all of its items have been filtered out by
Sidebar:filter.- Parameters:
placeholder- the placeholder widget- Since:
- 1.9
-
setSelected
public void setSelected(int selected) Selects the item at
selected.If set to
Gtk.INVALID_LIST_POSITION, no item is selected.If
Sidebar:modeis set toAdw.SidebarMode.page, the selection is invisible, but still tracked, indicating which item will be selected once the mode is changed toAdw.SidebarMode.sidebar.See also:
Sidebar:selected-item.- Parameters:
selected- index of the newly selected item- Since:
- 1.9
-
setupDropTarget
Sets up a drop target on the items.
This allows to drag arbitrary content onto items.
The
Sidebar::dropsignal can be used to handle the drop.- Parameters:
actions- the supported actionstypes- all supportedGTypes that can be dropped- Since:
- 1.9
-
setupDropTarget
Sets up a drop target on the items.
This allows to drag arbitrary content onto items.
The
Sidebar::dropsignal can be used to handle the drop.- Parameters:
actions- the supported actionstypes- all supportedGTypes that can be dropped- Since:
- 1.9
-
onActivated
Emitted when an item atindexhas been activated.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.9
- See Also:
-
emitActivated
public void emitActivated(int index) Emits the "activated" signal. SeeonActivated(Sidebar.ActivatedCallback). -
onDrop
Emitted when content is dropped onto the item at
index.The content must be of one of the types set up via
setupDropTarget(Set, Type[]).See
Gtk.DropTarget::drop.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDrop
Emits the "drop" signal. SeeonDrop(Sidebar.DropCallback). -
onDropEnter
Emitted when the pointer enters the item at
index.Applications can use this to set their default drop action even when
Sidebar:drop-preloadis set toFALSE.See
Gtk.DropTarget::enter.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.9
- See Also:
-
emitDropEnter
Emits the "drop-enter" signal. SeeonDropEnter(Sidebar.DropEnterCallback). -
onDropValueLoaded
public SignalConnection<Sidebar.DropValueLoadedCallback> onDropValueLoaded(Sidebar.DropValueLoadedCallback handler) Emitted when the dropped content is preloaded for the item at
index.In order for data to be preloaded,
Sidebar:drop-preloadmust be set toTRUE.The content must be of one of the types set up via
setupDropTarget(Set, Type[]).See
Gtk.DropTarget:value.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.9
- See Also:
-
emitDropValueLoaded
Emits the "drop-value-loaded" signal. SeeonDropValueLoaded(Sidebar.DropValueLoadedCallback). -
onSetupMenu
Emitted when a context menu is opened or closed for
item.If the menu has been closed,
itemwill be set toNULL.It can be used to set up menu actions before showing the menu, for example disable actions not applicable to
item.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitSetupMenu
Emits the "setup-menu" signal. SeeonSetupMenu(Sidebar.SetupMenuCallback). -
builder
ASidebar.Builderobject constructs aSidebarwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSidebar.Builder.build().- Returns:
- the builder object
-