Class GridView

All Implemented Interfaces:
PointerInterface

public class GridView extends ListBase
`GtkGridView` presents a large dynamic grid of items.

`GtkGridView` uses its factory to generate one child widget for each
visible item and shows them in a grid. The orientation of the grid view
determines if the grid reflows vertically or horizontally.

`GtkGridView` 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.GridView:enable-rubberband].

To learn more about the list widget framework, see the
[overview](section-list-widget.html).

# CSS nodes

```
gridview
├── child[.activatable]

├── child[.activatable]


╰── [rubberband]
```

`GtkGridView` uses a single CSS node with name `gridview`. Each child uses
a single CSS node with name `child`. If the [property@Gtk.ListItem:activatable]
property is set, the corresponding row will have the `.activatable` style
class. For rubberband selection, a subnode with name `rubberband` is used.

# Accessibility

`GtkGridView` uses the %GTK_ACCESSIBLE_ROLE_GRID role, and the items
use the %GTK_ACCESSIBLE_ROLE_GRID_CELL role.

https://docs.gtk.org/gtk4/class.GridView.html

  • Field Details

  • Constructor Details

    • GridView

      public GridView(PointerContainer pointer)
    • GridView

      public GridView(@Nullable SelectionModel model, @Nullable ListItemFactory factory)
      Creates a new `GtkGridView` that uses the given @factory for
      mapping items to widgets.

      The function takes ownership of the
      arguments, so you can write code like
      ```c
      grid_view = gtk_grid_view_new (create_model (),
      gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
      ```
      Parameters:
      model - the model to use
      factory - The factory to populate items with
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getEnableRubberband

      public boolean getEnableRubberband()
      Returns whether rows can be selected by dragging with the mouse.
      Returns:
      %TRUE if rubberband selection is enabled
    • getFactory

      public ListItemFactory getFactory()
      Gets the factory that's currently used to populate list items.
      Returns:
      The factory in use
    • getMaxColumns

      public int getMaxColumns()
      Gets the maximum number of columns that the grid will use.
      Returns:
      The maximum number of columns
    • getMinColumns

      public int getMinColumns()
      Gets the minimum number of columns that the grid will use.
      Returns:
      The minimum number of columns
    • getModel

      public SelectionModel getModel()
      Gets the model that's currently used to read the items displayed.
      Returns:
      The model in use
    • getSingleClickActivate

      public boolean getSingleClickActivate()
      Returns whether items will be activated on single click and
      selected on hover.
      Returns:
      %TRUE if items 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

      public void setFactory(@Nullable ListItemFactory factory)
      Sets the `GtkListItemFactory` to use for populating list items.
      Parameters:
      factory - the factory to use
    • setMaxColumns

      public void setMaxColumns(int max_columns)
      Sets the maximum number of columns to use.

      This number must be at least 1.

      If @max_columns is smaller than the minimum set via
      [method@Gtk.GridView.set_min_columns], that value is used instead.
      Parameters:
      max_columns - The maximum number of columns
    • setMinColumns

      public void setMinColumns(int min_columns)
      Sets the minimum number of columns to use.

      This number must be at least 1.

      If @min_columns is smaller than the minimum set via
      [method@Gtk.GridView.set_max_columns], that value is ignored.
      Parameters:
      min_columns - The minimum number of columns
    • setModel

      public void setModel(@Nullable SelectionModel model)
      Sets the imodel to use.

      This must be a [iface@Gtk.SelectionModel].
      Parameters:
      model - the model to use
    • setSingleClickActivate

      public void setSingleClickActivate(boolean single_click_activate)
      Sets whether items should be activated on single click and
      selected on hover.
      Parameters:
      single_click_activate - %TRUE to activate items on single click
    • onActivate

      public SignalHandler onActivate(GridView.OnActivate signal)
      Connect to signal "activate".
      See GridView.OnActivate.onActivate(int) for signal description.
      Field SIGNAL_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

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class ListBase
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class ListBase
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class ListBase
      Returns:
      ConstraintTarget
    • asOrientable

      public Orientable asOrientable()
      Implements interface Orientable. Call this to get access to interface functions.
      Overrides:
      asOrientable in class ListBase
      Returns:
      Orientable
    • asScrollable

      public Scrollable asScrollable()
      Implements interface Scrollable. Call this to get access to interface functions.
      Overrides:
      asScrollable in class ListBase
      Returns:
      Scrollable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()