Class GridView

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Orientable, Scrollable, Proxy

@Generated("org.javagi.JavaGI") public class GridView extends ListBase implements Accessible, Buildable, ConstraintTarget, Orientable, Scrollable

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 Gtk.GridView:enable-rubberband.

To learn more about the list widget framework, see the overview.

Actions

GtkGridView defines a set of built-in actions:

  • list.activate-item activates the item at given position by emitting the the Gtk.GridView::activate signal.

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 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.AccessibleRole.grid role, and the items use the Gtk.AccessibleRole.grid_cell role.

  • Constructor Details

    • GridView

      public GridView(MemorySegment address)
      Create a GridView instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • 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

      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
    • GridView

      public GridView()
      Create a new GridView.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the GridView class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected GridView asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class ListBase
      Returns:
      the instance as if it were its parent type
    • getEnableRubberband

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

      public @Nullable 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 @Nullable 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
    • getTabBehavior

      public ListTabBehavior getTabBehavior()
      Gets the behavior set for the Tab key.
      Returns:
      The behavior of the Tab key
      Since:
      4.12
    • scrollTo

      public void scrollTo(int pos, Set<ListScrollFlags> flags, @Nullable ScrollInfo scroll)

      Scrolls to the item at the given position and performs the actions specified in flags.

      This function works no matter if the gridview is shown or focused. If it isn't, then the changes will take effect once that happens.

      Parameters:
      pos - position of the item. Must be less than the number of items in the view.
      flags - actions to perform
      scroll - details of how to perform the scroll operation or null to scroll into view
      Since:
      4.12
    • scrollTo

      public void scrollTo(int pos, ListScrollFlags flags, @Nullable ScrollInfo scroll)

      Scrolls to the item at the given position and performs the actions specified in flags.

      This function works no matter if the gridview is shown or focused. If it isn't, then the changes will take effect once that happens.

      Parameters:
      pos - position of the item. Must be less than the number of items in the view.
      flags - actions to perform
      scroll - details of how to perform the scroll operation or null to scroll into view
      Since:
      4.12
    • setEnableRubberband

      public void setEnableRubberband(boolean enableRubberband)
      Sets whether selections can be changed by dragging with the mouse.
      Parameters:
      enableRubberband - 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 maxColumns)

      Sets the maximum number of columns to use.

      This number must be at least 1.

      If maxColumns is smaller than the minimum set via setMinColumns(int), that value is used instead.

      Parameters:
      maxColumns - The maximum number of columns
    • setMinColumns

      public void setMinColumns(int minColumns)

      Sets the minimum number of columns to use.

      This number must be at least 1.

      If minColumns is smaller than the minimum set via setMaxColumns(int), that value is ignored.

      Parameters:
      minColumns - The minimum number of columns
    • setModel

      public void setModel(@Nullable SelectionModel model)

      Sets the model to use.

      This must be a SelectionModel.

      Parameters:
      model - the model to use
    • setSingleClickActivate

      public void setSingleClickActivate(boolean singleClickActivate)
      Sets whether items should be activated on single click and selected on hover.
      Parameters:
      singleClickActivate - true to activate items on single click
    • setTabBehavior

      public void setTabBehavior(ListTabBehavior tabBehavior)
      Sets the behavior of the Tab and Shift+Tab keys.
      Parameters:
      tabBehavior - The desired tab behavior
      Since:
      4.12
    • onActivate

      Emitted when a cell has been activated by the user, usually via activating the GtkGridView|list.activate-item action.

      This allows for a convenient way to handle activation in a gridview. See Gtk.ListItem:activatable for details on how to use this signal.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitActivate

      public void emitActivate(int position)
      Emits the "activate" signal. See onActivate(GridView.ActivateCallback).
    • builder

      public static GridView.Builder<? extends GridView.Builder> builder()
      A GridView.Builder object constructs a GridView with the specified properties. Use the various set...() methods to set properties, and finish construction with GridView.Builder.build().
      Returns:
      the builder object