Class IconView

All Implemented Interfaces:
PointerInterface

public class IconView extends Widget
`GtkIconView` is a widget which displays data in a grid of icons.

`GtkIconView` provides an alternative view on a `GtkTreeModel`.
It displays the model as a grid of icons with labels. Like
[class@Gtk.TreeView], it allows to select one or multiple items
(depending on the selection mode, see [method@Gtk.IconView.set_selection_mode]).
In addition to selection with the arrow keys, `GtkIconView` supports
rubberband selection, which is controlled by dragging the pointer.

Note that if the tree model is backed by an actual tree store (as
opposed to a flat list where the mapping to icons is obvious),
`GtkIconView` will only display the first level of the tree and
ignore the tree’s branches.

# CSS nodes

```
iconview.view
╰── [rubberband]
```

`GtkIconView` has a single CSS node with name iconview and style class .view.
For rubberband selection, a subnode with name rubberband is used.

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

  • Field Details

  • Constructor Details

    • IconView

      public IconView(PointerContainer pointer)
    • IconView

      public IconView()
      Creates a new `GtkIconView` widget
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newWithAreaIconView

      public static IconView newWithAreaIconView(@Nonnull CellArea area)
      Creates a new `GtkIconView` widget using the
      specified @area to layout cells inside the icons.
      Parameters:
      area - the `GtkCellArea` to use to layout cells
      Returns:
      A newly created `GtkIconView` widget
    • newWithModelIconView

      public static IconView newWithModelIconView(@Nonnull TreeModel model)
      Creates a new `GtkIconView` widget with the model @model.
      Parameters:
      model - The model.
      Returns:
      A newly created `GtkIconView` widget.
    • createDragIcon

      public Paintable createDragIcon(@Nonnull TreePath path)
      Creates a `GdkPaintable` representation of the item at @path.
      This image is used for a drag icon.
      Parameters:
      path - a `GtkTreePath` in @icon_view
      Returns:
      a newly-allocated `GdkPaintable` of the drag icon.
    • enableModelDragDest

      public void enableModelDragDest(@Nonnull ContentFormats formats, int actions)
      Turns @icon_view into a drop destination for automatic DND. Calling this
      method sets `GtkIconView`:reorderable to %FALSE.
      Parameters:
      formats - the formats that the drag will support
      actions - the bitmask of possible actions for a drag to this widget
    • enableModelDragSource

      public void enableModelDragSource(int start_button_mask, @Nonnull ContentFormats formats, int actions)
      Turns @icon_view into a drag source for automatic DND. Calling this
      method sets `GtkIconView`:reorderable to %FALSE.
      Parameters:
      start_button_mask - Mask of allowed buttons to start drag
      formats - the formats that the drag will support
      actions - the bitmask of possible actions for a drag from this widget
    • getActivateOnSingleClick

      public boolean getActivateOnSingleClick()
      Gets the setting set by gtk_icon_view_set_activate_on_single_click().
      Returns:
      %TRUE if item-activated will be emitted on a single click
    • getCellRect

      public boolean getCellRect(@Nonnull TreePath path, @Nullable CellRenderer cell, @Nonnull Rectangle rect)
      Fills the bounding rectangle in widget coordinates for the cell specified by
      @path and @cell. If @cell is %NULL the main cell area is used.

      This function is only valid if @icon_view is realized.
      Parameters:
      path - a `GtkTreePath`
      cell - a `GtkCellRenderer`
      rect - rectangle to fill with cell rect
      Returns:
      %FALSE if there is no such item, %TRUE otherwise
    • getColumnSpacing

      public int getColumnSpacing()
      Returns the value of the ::column-spacing property.
      Returns:
      the space between columns
    • getColumns

      public int getColumns()
      Returns the value of the ::columns property.
      Returns:
      the number of columns, or -1
    • getItemColumn

      public int getItemColumn(@Nonnull TreePath path)
      Gets the column in which the item @path is currently
      displayed. Column numbers start at 0.
      Parameters:
      path - the `GtkTreePath` of the item
      Returns:
      The column in which the item is displayed
    • getItemOrientation

      public int getItemOrientation()
      Returns the value of the ::item-orientation property which determines
      whether the labels are drawn beside the icons instead of below.
      Returns:
      the relative position of texts and icons
    • getItemPadding

      public int getItemPadding()
      Returns the value of the ::item-padding property.
      Returns:
      the padding around items
    • getItemRow

      public int getItemRow(@Nonnull TreePath path)
      Gets the row in which the item @path is currently
      displayed. Row numbers start at 0.
      Parameters:
      path - the `GtkTreePath` of the item
      Returns:
      The row in which the item is displayed
    • getItemWidth

      public int getItemWidth()
      Returns the value of the ::item-width property.
      Returns:
      the width of a single item, or -1
    • getMargin

      public int getMargin()
      Returns the value of the ::margin property.
      Returns:
      the space at the borders
    • getMarkupColumn

      public int getMarkupColumn()
      Returns the column with markup text for @icon_view.
      Returns:
      the markup column, or -1 if it’s unset.
    • getModel

      public TreeModel getModel()
      Returns the model the `GtkIconView` is based on. Returns %NULL if the
      model is unset.
      Returns:
      The currently used `GtkTreeModel`
    • getPathAtPos

      public TreePath getPathAtPos(int x, int y)
      Gets the path for the icon at the given position.
      Parameters:
      x - The x position to be identified
      y - The y position to be identified
      Returns:
      The `GtkTreePath` corresponding to the icon or %NULL if no icon exists at that position.
    • getPixbufColumn

      public int getPixbufColumn()
      Returns the column with pixbufs for @icon_view.
      Returns:
      the pixbuf column, or -1 if it’s unset.
    • getReorderable

      public boolean getReorderable()
      Retrieves whether the user can reorder the list via drag-and-drop.
      See gtk_icon_view_set_reorderable().
      Returns:
      %TRUE if the list can be reordered.
    • getRowSpacing

      public int getRowSpacing()
      Returns the value of the ::row-spacing property.
      Returns:
      the space between rows
    • getSelectedItems

      public List getSelectedItems()
      Creates a list of paths of all selected items. Additionally, if you are
      planning on modifying the model after calling this function, you may
      want to convert the returned list into a list of `GtkTreeRowReferences`.
      To do this, you can use gtk_tree_row_reference_new().

      To free the return value, use `g_list_free_full`:
      <!-- language="C" -->
       GtkWidget *icon_view = gtk_icon_view_new ();
       // Use icon_view
       
       GList *list = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (icon_view));
       
       // use list
       
       g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
       
      Returns:
      A `GList` containing a `GtkTreePath` for each selected row.
    • getSelectionMode

      public int getSelectionMode()
      Gets the selection mode of the @icon_view.
      Returns:
      the current selection mode
    • getSpacing

      public int getSpacing()
      Returns the value of the ::spacing property.
      Returns:
      the space between cells
    • getTextColumn

      public int getTextColumn()
      Returns the column with text for @icon_view.
      Returns:
      the text column, or -1 if it’s unset.
    • getTooltipColumn

      public int getTooltipColumn()
      Returns the column of @icon_view’s model which is being used for
      displaying tooltips on @icon_view’s rows.
      Returns:
      the index of the tooltip column that is currently being used, or -1 if this is disabled.
    • itemActivated

      public void itemActivated(@Nonnull TreePath path)
      Activates the item determined by @path.
      Parameters:
      path - The `GtkTreePath` to be activated
    • pathIsSelected

      public boolean pathIsSelected(@Nonnull TreePath path)
      Returns %TRUE if the icon pointed to by @path is currently
      selected. If @path does not point to a valid location, %FALSE is returned.
      Parameters:
      path - A `GtkTreePath` to check selection on.
      Returns:
      %TRUE if @path is selected.
    • scrollToPath

      public void scrollToPath(@Nonnull TreePath path, boolean use_align, float row_align, float col_align)
      Moves the alignments of @icon_view to the position specified by @path.
      @row_align determines where the row is placed, and @col_align determines
      where @column is placed. Both are expected to be between 0.0 and 1.0.
      0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
      center.

      If @use_align is %FALSE, then the alignment arguments are ignored, and the
      tree does the minimum amount of work to scroll the item onto the screen.
      This means that the item will be scrolled to the edge closest to its current
      position. If the item is currently visible on the screen, nothing is done.

      This function only works if the model is set, and @path is a valid row on
      the model. If the model changes before the @icon_view is realized, the
      centered path will be modified to reflect this change.
      Parameters:
      path - The path of the item to move to.
      use_align - whether to use alignment arguments, or %FALSE.
      row_align - The vertical alignment of the item specified by @path.
      col_align - The horizontal alignment of the item specified by @path.
    • selectAll

      public void selectAll()
      Selects all the icons. @icon_view must has its selection mode set
      to %GTK_SELECTION_MULTIPLE.
    • selectPath

      public void selectPath(@Nonnull TreePath path)
      Selects the row at @path.
      Parameters:
      path - The `GtkTreePath` to be selected.
    • selectedForeach

      public void selectedForeach(IconView.OnIconViewForeachFunc func, @Nullable Pointer data)
      Calls a function for each selected icon. Note that the model or
      selection cannot be modified from within this function.
      Parameters:
      func - The function to call for each selected icon.
      data - User data to pass to the function.
    • setActivateOnSingleClick

      public void setActivateOnSingleClick(boolean single)
      Causes the `GtkIconView`::item-activated signal to be emitted on
      a single click instead of a double click.
      Parameters:
      single - %TRUE to emit item-activated on a single click
    • setColumnSpacing

      public void setColumnSpacing(int column_spacing)
      Sets the ::column-spacing property which specifies the space
      which is inserted between the columns of the icon view.
      Parameters:
      column_spacing - the column spacing
    • setColumns

      public void setColumns(int columns)
      Sets the ::columns property which determines in how
      many columns the icons are arranged. If @columns is
      -1, the number of columns will be chosen automatically
      to fill the available area.
      Parameters:
      columns - the number of columns
    • setCursor

      public void setCursor(@Nonnull TreePath path, @Nullable CellRenderer cell, boolean start_editing)
      Sets the current keyboard focus to be at @path, and selects it. This is
      useful when you want to focus the user’s attention on a particular item.
      If @cell is not %NULL, then focus is given to the cell specified by
      it. Additionally, if @start_editing is %TRUE, then editing should be
      started in the specified cell.

      This function is often followed by `gtk_widget_grab_focus
      (icon_view)` in order to give keyboard focus to the widget.
      Please note that editing can only happen when the widget is realized.
      Parameters:
      path - A `GtkTreePath`
      cell - One of the cell renderers of @icon_view
      start_editing - %TRUE if the specified cell should start being edited.
    • setDragDestItem

      public void setDragDestItem(@Nullable TreePath path, int pos)
      Sets the item that is highlighted for feedback.
      Parameters:
      path - The path of the item to highlight
      pos - Specifies where to drop, relative to the item
    • setItemOrientation

      public void setItemOrientation(int orientation)
      Sets the ::item-orientation property which determines whether the labels
      are drawn beside the icons instead of below.
      Parameters:
      orientation - the relative position of texts and icons
    • setItemPadding

      public void setItemPadding(int item_padding)
      Sets the `GtkIconView`:item-padding property which specifies the padding
      around each of the icon view’s items.
      Parameters:
      item_padding - the item padding
    • setItemWidth

      public void setItemWidth(int item_width)
      Sets the ::item-width property which specifies the width
      to use for each item. If it is set to -1, the icon view will
      automatically determine a suitable item size.
      Parameters:
      item_width - the width for each item
    • setMargin

      public void setMargin(int margin)
      Sets the ::margin property which specifies the space
      which is inserted at the top, bottom, left and right
      of the icon view.
      Parameters:
      margin - the margin
    • setMarkupColumn

      public void setMarkupColumn(int column)
      Sets the column with markup information for @icon_view to be
      @column. The markup column must be of type `G_TYPE_STRING`.
      If the markup column is set to something, it overrides
      the text column set by gtk_icon_view_set_text_column().
      Parameters:
      column - A column in the currently used model, or -1 to display no text
    • setModel

      public void setModel(@Nullable TreeModel model)
      Sets the model for a `GtkIconView`.
      If the @icon_view already has a model set, it will remove
      it before setting the new model. If @model is %NULL, then
      it will unset the old model.
      Parameters:
      model - The model.
    • setPixbufColumn

      public void setPixbufColumn(int column)
      Sets the column with pixbufs for @icon_view to be @column. The pixbuf
      column must be of type `GDK_TYPE_PIXBUF`
      Parameters:
      column - A column in the currently used model, or -1 to disable
    • setReorderable

      public void setReorderable(boolean reorderable)
      This function is a convenience function to allow you to reorder models that
      support the `GtkTreeDragSourceIface` and the `GtkTreeDragDestIface`. Both
      `GtkTreeStore` and `GtkListStore` support these. If @reorderable is %TRUE, then
      the user can reorder the model by dragging and dropping rows. The
      developer can listen to these changes by connecting to the model's
      row_inserted and row_deleted signals. The reordering is implemented by setting up
      the icon view as a drag source and destination. Therefore, drag and
      drop can not be used in a reorderable view for any other purpose.

      This function does not give you any degree of control over the order -- any
      reordering is allowed. If more control is needed, you should probably
      handle drag and drop manually.
      Parameters:
      reorderable - %TRUE, if the list of items can be reordered.
    • setRowSpacing

      public void setRowSpacing(int row_spacing)
      Sets the ::row-spacing property which specifies the space
      which is inserted between the rows of the icon view.
      Parameters:
      row_spacing - the row spacing
    • setSelectionMode

      public void setSelectionMode(int mode)
      Sets the selection mode of the @icon_view.
      Parameters:
      mode - The selection mode
    • setSpacing

      public void setSpacing(int spacing)
      Sets the ::spacing property which specifies the space
      which is inserted between the cells (i.e. the icon and
      the text) of an item.
      Parameters:
      spacing - the spacing
    • setTextColumn

      public void setTextColumn(int column)
      Sets the column with text for @icon_view to be @column. The text
      column must be of type `G_TYPE_STRING`.
      Parameters:
      column - A column in the currently used model, or -1 to display no text
    • setTooltipCell

      public void setTooltipCell(@Nonnull Tooltip tooltip, @Nonnull TreePath path, @Nullable CellRenderer cell)
      Sets the tip area of @tooltip to the area which @cell occupies in
      the item pointed to by @path. See also gtk_tooltip_set_tip_area().

      See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
      Parameters:
      tooltip - a `GtkTooltip`
      path - a `GtkTreePath`
      cell - a `GtkCellRenderer`
    • setTooltipColumn

      public void setTooltipColumn(int column)
      If you only plan to have simple (text-only) tooltips on full items, you
      can use this function to have `GtkIconView` handle these automatically
      for you. @column should be set to the column in @icon_view’s model
      containing the tooltip texts, or -1 to disable this feature.

      When enabled, `GtkWidget:has-tooltip` will be set to %TRUE and
      @icon_view will connect a `GtkWidget::query-tooltip` signal handler.

      Note that the signal handler sets the text with gtk_tooltip_set_markup(),
      so &, <, etc have to be escaped in the text.
      Parameters:
      column - an integer, which is a valid column number for @icon_view’s model
    • setTooltipItem

      public void setTooltipItem(@Nonnull Tooltip tooltip, @Nonnull TreePath path)
      Sets the tip area of @tooltip to be the area covered by the item at @path.
      See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
      See also gtk_tooltip_set_tip_area().
      Parameters:
      tooltip - a `GtkTooltip`
      path - a `GtkTreePath`
    • unselectAll

      public void unselectAll()
      Unselects all the icons.
    • unselectPath

      public void unselectPath(@Nonnull TreePath path)
      Unselects the row at @path.
      Parameters:
      path - The `GtkTreePath` to be unselected.
    • unsetModelDragDest

      public void unsetModelDragDest()
      Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
      method sets `GtkIconView`:reorderable to %FALSE.
    • unsetModelDragSource

      public void unsetModelDragSource()
      Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
      method sets `GtkIconView`:reorderable to %FALSE.
    • onActivateCursorItem

      public SignalHandler onActivateCursorItem(IconView.OnActivateCursorItem signal)
      Connect to signal "activate-cursor-item".
      See IconView.OnActivateCursorItem.onActivateCursorItem() for signal description.
      Field SIGNAL_ON_ACTIVATE_CURSOR_ITEM 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.
    • onItemActivated

      public SignalHandler onItemActivated(IconView.OnItemActivated signal)
      Connect to signal "item-activated".
      See IconView.OnItemActivated.onItemActivated(ch.bailu.gtk.gtk.TreePath) for signal description.
      Field SIGNAL_ON_ITEM_ACTIVATED 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.
    • onMoveCursor

      public SignalHandler onMoveCursor(IconView.OnMoveCursor signal)
      Connect to signal "move-cursor".
      See IconView.OnMoveCursor.onMoveCursor(int, int, boolean, boolean) for signal description.
      Field SIGNAL_ON_MOVE_CURSOR 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.
    • onSelectAll

      public SignalHandler onSelectAll(IconView.OnSelectAll signal)
      Connect to signal "select-all".
      See IconView.OnSelectAll.onSelectAll() for signal description.
      Field SIGNAL_ON_SELECT_ALL 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.
    • onSelectCursorItem

      public SignalHandler onSelectCursorItem(IconView.OnSelectCursorItem signal)
      Connect to signal "select-cursor-item".
      See IconView.OnSelectCursorItem.onSelectCursorItem() for signal description.
      Field SIGNAL_ON_SELECT_CURSOR_ITEM 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.
    • onSelectionChanged

      public SignalHandler onSelectionChanged(IconView.OnSelectionChanged signal)
      Connect to signal "selection-changed".
      See IconView.OnSelectionChanged.onSelectionChanged() for signal description.
      Field SIGNAL_ON_SELECTION_CHANGED 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.
    • onToggleCursorItem

      public SignalHandler onToggleCursorItem(IconView.OnToggleCursorItem signal)
      Connect to signal "toggle-cursor-item".
      See IconView.OnToggleCursorItem.onToggleCursorItem() for signal description.
      Field SIGNAL_ON_TOGGLE_CURSOR_ITEM 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.
    • onUnselectAll

      public SignalHandler onUnselectAll(IconView.OnUnselectAll signal)
      Connect to signal "unselect-all".
      See IconView.OnUnselectAll.onUnselectAll() for signal description.
      Field SIGNAL_ON_UNSELECT_ALL 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 Widget
      Returns:
      Accessible
    • asBuildable

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

      public CellLayout asCellLayout()
      Implements interface CellLayout. Call this to get access to interface functions.
      Returns:
      CellLayout
    • asConstraintTarget

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

      public Scrollable asScrollable()
      Implements interface Scrollable. Call this to get access to interface functions.
      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()