Package ch.bailu.gtk.gtk
Class ListView
- All Implemented Interfaces:
PointerInterface
`GtkListView` presents a large dynamic list of items.
`GtkListView` uses its factory to generate one row widget for each visible
item and shows them in a linear display, either vertically or horizontally.
The [property@Gtk.ListView:show-separators] property offers a simple way to
display separators between the rows.
`GtkListView` allows the user to select items according to the selection
characteristics of the model. For models that allow multiple selected items,
it is possible to turn on _rubberband selection_, using
[property@Gtk.ListView:enable-rubberband].
If you need multiple columns with headers, see [class@Gtk.ColumnView].
To learn more about the list widget framework, see the
[overview](section-list-widget.html).
An example of using `GtkListView`:
```c
static void
setup_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
image = gtk_image_new ();
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
gtk_list_item_set_child (list_item, image);
}
static void
bind_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
GAppInfo *app_info;
image = gtk_list_item_get_child (list_item);
app_info = gtk_list_item_get_item (list_item);
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
}
static void
activate_cb (GtkListView *list,
guint position,
gpointer unused)
{
GAppInfo *app_info;
app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
g_app_info_launch (app_info, NULL, NULL, NULL);
g_object_unref (app_info);
}
...
model = create_application_list ();
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
```
# CSS nodes
```
listview[.separators][.rich-list][.navigation-sidebar][.data-table]
├── row[.activatable]
│
├── row[.activatable]
│
┊
╰── [rubberband]
```
`GtkListView` uses a single CSS node named `listview`. It may carry the
`.separators` style class, when [property@Gtk.ListView:show-separators]
property is set. Each child widget uses a single CSS node named `row`.
If the [property@Gtk.ListItem:activatable] property is set, the
corresponding row will have the `.activatable` style class. For
rubberband selection, a node with name `rubberband` is used.
The main listview node may also carry style classes to select
the style of [list presentation](ListContainers.html#list-styles):
.rich-list, .navigation-sidebar or .data-table.
# Accessibility
`GtkListView` uses the %GTK_ACCESSIBLE_ROLE_LIST role, and the list
items use the %GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
`GtkListView` uses its factory to generate one row widget for each visible
item and shows them in a linear display, either vertically or horizontally.
The [property@Gtk.ListView:show-separators] property offers a simple way to
display separators between the rows.
`GtkListView` allows the user to select items according to the selection
characteristics of the model. For models that allow multiple selected items,
it is possible to turn on _rubberband selection_, using
[property@Gtk.ListView:enable-rubberband].
If you need multiple columns with headers, see [class@Gtk.ColumnView].
To learn more about the list widget framework, see the
[overview](section-list-widget.html).
An example of using `GtkListView`:
```c
static void
setup_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
image = gtk_image_new ();
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
gtk_list_item_set_child (list_item, image);
}
static void
bind_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
GAppInfo *app_info;
image = gtk_list_item_get_child (list_item);
app_info = gtk_list_item_get_item (list_item);
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
}
static void
activate_cb (GtkListView *list,
guint position,
gpointer unused)
{
GAppInfo *app_info;
app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
g_app_info_launch (app_info, NULL, NULL, NULL);
g_object_unref (app_info);
}
...
model = create_application_list ();
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
```
# CSS nodes
```
listview[.separators][.rich-list][.navigation-sidebar][.data-table]
├── row[.activatable]
│
├── row[.activatable]
│
┊
╰── [rubberband]
```
`GtkListView` uses a single CSS node named `listview`. It may carry the
`.separators` style class, when [property@Gtk.ListView:show-separators]
property is set. Each child widget uses a single CSS node named `row`.
If the [property@Gtk.ListItem:activatable] property is set, the
corresponding row will have the `.activatable` style class. For
rubberband selection, a node with name `rubberband` is used.
The main listview node may also carry style classes to select
the style of [list presentation](ListContainers.html#list-styles):
.rich-list, .navigation-sidebar or .data-table.
# Accessibility
`GtkListView` uses the %GTK_ACCESSIBLE_ROLE_LIST role, and the list
items use the %GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
ConstructorDescriptionListView
(SelectionModel model, ListItemFactory factory) Creates a new `GtkListView` that uses the given @factory for
mapping items to widgets.ListView
(PointerContainer pointer) -
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.Implements interfaceOrientable
.Implements interfaceScrollable
.static ClassHandler
boolean
Returns whether rows can be selected by dragging with the mouse.Gets the factory that's currently used to populate list items.static int
getModel()
Gets the model that's currently used to read the items displayed.static long
static TypeSystem.TypeSize
boolean
Returns whether the list box should show separators
between rows.boolean
Returns whether rows will be activated on single click and
selected on hover.static long
static TypeSystem.TypeSize
onActivate
(ListView.OnActivate signal) Connect to signal "activate".void
setEnableRubberband
(boolean enable_rubberband) Sets whether selections can be changed by dragging with the mouse.void
setFactory
(ListItemFactory factory) Sets the `GtkListItemFactory` to use for populating list items.void
setModel
(SelectionModel model) Sets the model to use.void
setShowSeparators
(boolean show_separators) Sets whether the list box should show separators
between rows.void
setSingleClickActivate
(boolean single_click_activate) Sets whether rows should be activated on single click and
selected on hover.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, 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, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_ACTIVATE
- See Also:
-
-
Constructor Details
-
ListView
-
ListView
Creates a new `GtkListView` that uses the given @factory for
mapping items to widgets.
The function takes ownership of the
arguments, so you can write code like
```c
list_view = gtk_list_view_new (create_model (),
gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
```- Parameters:
model
- the model to usefactory
- The factory to populate items with
-
-
Method Details
-
getClassHandler
-
getEnableRubberband
public boolean getEnableRubberband()Returns whether rows can be selected by dragging with the mouse.- Returns:
- %TRUE if rubberband selection is enabled
-
getFactory
Gets the factory that's currently used to populate list items.- Returns:
- The factory in use
-
getModel
Gets the model that's currently used to read the items displayed.- Returns:
- The model in use
-
getShowSeparators
public boolean getShowSeparators()Returns whether the list box should show separators
between rows.- Returns:
- %TRUE if the list box shows separators
-
getSingleClickActivate
public boolean getSingleClickActivate()Returns whether rows will be activated on single click and
selected on hover.- Returns:
- %TRUE if rows are activated on single click
-
setEnableRubberband
public void setEnableRubberband(boolean enable_rubberband) Sets whether selections can be changed by dragging with the mouse.- Parameters:
enable_rubberband
- %TRUE to enable rubberband selection
-
setFactory
Sets the `GtkListItemFactory` to use for populating list items.- Parameters:
factory
- the factory to use
-
setModel
Sets the model to use.
This must be a [iface@Gtk.SelectionModel] to use.- Parameters:
model
- the model to use
-
setShowSeparators
public void setShowSeparators(boolean show_separators) Sets whether the list box should show separators
between rows.- Parameters:
show_separators
- %TRUE to show separators
-
setSingleClickActivate
public void setSingleClickActivate(boolean single_click_activate) Sets whether rows should be activated on single click and
selected on hover.- Parameters:
single_click_activate
- %TRUE to activate items on single click
-
onActivate
Connect to signal "activate".
SeeListView.OnActivate.onActivate(int)
for signal description.
FieldSIGNAL_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
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classListBase
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classListBase
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classListBase
- Returns:
ConstraintTarget
-
asOrientable
Implements interfaceOrientable
. Call this to get access to interface functions.- Overrides:
asOrientable
in classListBase
- Returns:
Orientable
-
asScrollable
Implements interfaceScrollable
. Call this to get access to interface functions.- Overrides:
asScrollable
in classListBase
- Returns:
Scrollable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-