Class SidebarSection
A section within Sidebar.
AdwSidebarSection contains SidebarItem objects.
Section can optionally have a title, set with the
SidebarSection:title property. If a title is not set, the section
will have a separator in front of it, or just spacing in the
Adw.SidebarMode.page mode.
To add items, use append(SidebarItem),
prepend(SidebarItem) or insert(SidebarItem, int).
To remove items, use remove(SidebarItem) or
removeAll().
To inspect the items, use getItem(int) or
SidebarSection:items.
To get the sidebar the section is in, useSidebarSection:sidebar.
Binding models
AdwSidebarSection can show items from a provided ListModel,
using bindModel(ListModel, SidebarSectionCreateItemFunc). It works the same way as
ListBox#bindModel, except the provided function creates an
SidebarItem rather than a ListBoxRow.
While a model is bound, adding or removing items manually is not allowed. Inspecting them is still allowed, but discouraged.
AdwSidebarSection as GtkBuildable
AdwSidebarSection allows adding items as children.
Example of an AdwSidebarSection UI definition:
<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>
Result:
- Since:
- 1.9
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSidebarSection.Builder<B extends SidebarSection.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface Buildable
Buildable.Buildable$Impl, Buildable.BuildableIface -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new SidebarSection.SidebarSection(MemorySegment address) Create a SidebarSection instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(SidebarItem item) Appendsitemtoself.protected SidebarSectionasParent()Return this instance as if it were its parent type.voidbindModel(@Nullable ListModel model, @Nullable SidebarSectionCreateItemFunc createItemFunc) Bindsmodeltoself.static SidebarSection.Builder<? extends SidebarSection.Builder> builder()ASidebarSection.Builderobject constructs aSidebarSectionwith the specified properties.@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.@Nullable SidebarGets the sidebar this SidebarSection is in.@Nullable StringgetTitle()Gets the title ofself.static @Nullable TypegetType()Get the GType of the SidebarSection class.voidinsert(SidebarItem item, int position) Insertsitematpositiontoself.voidprepend(SidebarItem item) Prependsitemtoself.voidremove(SidebarItem item) Removesitemfromself.voidRemoves all items fromself.voidsetMenuModel(@Nullable MenuModel menuModel) Sets the context menu model forself'sitems.voidSets the title ofself.Methods 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 Buildable
getBuildableId
-
Constructor Details
-
SidebarSection
Create a SidebarSection instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
SidebarSection
public SidebarSection()Create a new SidebarSection.
-
-
Method Details
-
getType
Get the GType of the SidebarSection class.- Returns:
- the GType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code. -
append
Appends
itemtoself.Cannot be used while a model is bound via
bindModel(ListModel, SidebarSectionCreateItemFunc).- Parameters:
item- an item to append- Since:
- 1.9
-
bindModel
public void bindModel(@Nullable ListModel model, @Nullable SidebarSectionCreateItemFunc createItemFunc) Binds
modeltoself.If this SidebarSection was already bound to a model, that previous binding is destroyed.
The contents of this SidebarSection are cleared and then filled with items that represent items from
model.this SidebarSection is updated whenevermodelchanges.If
modelisNULL, this SidebarSection is left empty.Calling
prepend(SidebarItem),insert(SidebarItem, int),append(SidebarItem),remove(SidebarItem)orremoveAll()while a model is bound is not allowed.Accessing items and modifying them is allowed, but the changes will be erased whenever that part of the model changes, so it's not recommended.
- Parameters:
model- the model to be boundcreateItemFunc- a function that createsSidebarItemfor model items, orNULLin casemodelis alsoNULL- Since:
- 1.9
-
getItem
Gets the item at
indexwithinself.The index starts from 0 at the top of the section, and is same as the one returned by
SidebarItem.getSectionIndex().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.
- 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
-
getSidebar
Gets the sidebar this SidebarSection is in.- Returns:
- the sidebar of this SidebarSection
- Since:
- 1.9
-
getTitle
-
insert
Inserts
itematpositiontoself.If
positionis -1, or larger than the total number of items inself,the item will be appended to the end.Cannot be used while a model is bound via
bindModel(ListModel, SidebarSectionCreateItemFunc).- Parameters:
item- an item to insertposition- position to insertitemat- Since:
- 1.9
-
prepend
Prepends
itemtoself.Cannot be used while a model is bound via
bindModel(ListModel, SidebarSectionCreateItemFunc).- Parameters:
item- an item to prepend- Since:
- 1.9
-
remove
Removes
itemfromself.Cannot be used while a model is bound via
bindModel(ListModel, SidebarSectionCreateItemFunc).- Parameters:
item- an item to remove- Since:
- 1.9
-
removeAll
public void removeAll()Removes all items from
self.Cannot be used while a model is bound via
bindModel(ListModel, SidebarSectionCreateItemFunc).- 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.If not set,
Sidebar:menu-modelwill be used instead.- Parameters:
menuModel- a menu model- Since:
- 1.9
-
setTitle
Sets the title of
self.If set, it will be displayed instead of the separator before the section.
- Parameters:
title- the title- Since:
- 1.9
-
builder
ASidebarSection.Builderobject constructs aSidebarSectionwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSidebarSection.Builder.build().- Returns:
- the builder object
-