Class CellRenderer

All Implemented Interfaces:
PointerInterface
Direct Known Subclasses:
CellRendererPixbuf, CellRendererProgress, CellRendererSpinner, CellRendererText, CellRendererToggle

public class CellRenderer extends InitiallyUnowned
An object for rendering a single cell

The `GtkCellRenderer` is a base class of a set of objects used for
rendering a cell to a `cairo_t`. These objects are used primarily by
the `GtkTreeView` widget, though they aren’t tied to them in any
specific way. It is worth noting that `GtkCellRenderer` is not a
`GtkWidget` and cannot be treated as such.

The primary use of a `GtkCellRenderer` is for drawing a certain graphical
elements on a `cairo_t`. Typically, one cell renderer is used to
draw many cells on the screen. To this extent, it isn’t expected that a
CellRenderer keep any permanent state around. Instead, any state is set
just prior to use using `GObject`s property system. Then, the
cell is measured using gtk_cell_renderer_get_preferred_size(). Finally, the cell
is rendered in the correct location using gtk_cell_renderer_snapshot().

There are a number of rules that must be followed when writing a new
`GtkCellRenderer`. First and foremost, it’s important that a certain set
of properties will always yield a cell renderer of the same size,
barring a style change. The `GtkCellRenderer` also has a number of
generic properties that are expected to be honored by all children.

Beyond merely rendering a cell, cell renderers can optionally
provide active user interface elements. A cell renderer can be
“activatable” like `GtkCellRenderer`Toggle,
which toggles when it gets activated by a mouse click, or it can be
“editable” like `GtkCellRenderer`Text, which
allows the user to edit the text using a widget implementing the
`GtkCellEditable` interface, e.g. `GtkEntry`.
To make a cell renderer activatable or editable, you have to
implement the `GtkCellRenderer`Class.activate or
`GtkCellRenderer`Class.start_editing virtual functions, respectively.

Many properties of `GtkCellRenderer` and its subclasses have a
corresponding “set” property, e.g. “cell-background-set” corresponds
to “cell-background”. These “set” properties reflect whether a property
has been set or not. You should not set them independently.

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

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • activate

      public boolean activate(@Nonnull Event event, @Nonnull Widget widget, @Nonnull Str path, @Nonnull Rectangle background_area, @Nonnull Rectangle cell_area, int flags)
      Passes an activate event to the cell renderer for possible processing.
      Some cell renderers may use events; for example, `GtkCellRendererToggle`
      toggles when it gets a mouse click.
      Parameters:
      event - a `GdkEvent`
      widget - widget that received the event
      path - widget-dependent string representation of the event location; e.g. for `GtkTreeView`, a string representation of `GtkTreePath`
      background_area - background area as passed to gtk_cell_renderer_render()
      cell_area - cell area as passed to gtk_cell_renderer_render()
      flags - render flags
      Returns:
      %TRUE if the event was consumed/handled
    • activate

      public boolean activate(@Nonnull Event event, @Nonnull Widget widget, String path, @Nonnull Rectangle background_area, @Nonnull Rectangle cell_area, int flags)
      Passes an activate event to the cell renderer for possible processing.
      Some cell renderers may use events; for example, `GtkCellRendererToggle`
      toggles when it gets a mouse click.
      Parameters:
      event - a `GdkEvent`
      widget - widget that received the event
      path - widget-dependent string representation of the event location; e.g. for `GtkTreeView`, a string representation of `GtkTreePath`
      background_area - background area as passed to gtk_cell_renderer_render()
      cell_area - cell area as passed to gtk_cell_renderer_render()
      flags - render flags
      Returns:
      %TRUE if the event was consumed/handled
    • getAlignedArea

      public void getAlignedArea(@Nonnull Widget widget, int flags, @Nonnull Rectangle cell_area, @Nonnull Rectangle aligned_area)
      Gets the aligned area used by @cell inside @cell_area. Used for finding
      the appropriate edit and focus rectangle.
      Parameters:
      widget - the `GtkWidget` this cell will be rendering to
      flags - render flags
      cell_area - cell area which would be passed to gtk_cell_renderer_render()
      aligned_area - the return location for the space inside @cell_area that would actually be used to render.
    • getAlignment

      public void getAlignment(@Nullable Flt xalign, @Nullable Flt yalign)
      Fills in @xalign and @yalign with the appropriate values of @cell.
      Parameters:
      xalign - location to fill in with the x alignment of the cell
      yalign - location to fill in with the y alignment of the cell
    • getFixedSize

      public void getFixedSize(@Nullable Int width, @Nullable Int height)
      Fills in @width and @height with the appropriate size of @cell.
      Parameters:
      width - location to fill in with the fixed width of the cell
      height - location to fill in with the fixed height of the cell
    • getIsExpanded

      public boolean getIsExpanded()
      Checks whether the given `GtkCellRenderer` is expanded.
      Returns:
      %TRUE if the cell renderer is expanded
    • getIsExpander

      public boolean getIsExpander()
      Checks whether the given `GtkCellRenderer` is an expander.
      Returns:
      %TRUE if @cell is an expander, and %FALSE otherwise
    • getPadding

      public void getPadding(@Nullable Int xpad, @Nullable Int ypad)
      Fills in @xpad and @ypad with the appropriate values of @cell.
      Parameters:
      xpad - location to fill in with the x padding of the cell
      ypad - location to fill in with the y padding of the cell
    • getPreferredHeight

      public void getPreferredHeight(@Nonnull Widget widget, @Nullable Int minimum_size, @Nullable Int natural_size)
      Retrieves a renderer’s natural size when rendered to @widget.
      Parameters:
      widget - the `GtkWidget` this cell will be rendering to
      minimum_size - location to store the minimum size
      natural_size - location to store the natural size
    • getPreferredHeightForWidth

      public void getPreferredHeightForWidth(@Nonnull Widget widget, int width, @Nullable Int minimum_height, @Nullable Int natural_height)
      Retrieves a cell renderers’s minimum and natural height if it were rendered to
      @widget with the specified @width.
      Parameters:
      widget - the `GtkWidget` this cell will be rendering to
      width - the size which is available for allocation
      minimum_height - location for storing the minimum size
      natural_height - location for storing the preferred size
    • getPreferredSize

      public void getPreferredSize(@Nonnull Widget widget, @Nullable Requisition minimum_size, @Nullable Requisition natural_size)
      Retrieves the minimum and natural size of a cell taking
      into account the widget’s preference for height-for-width management.
      Parameters:
      widget - the `GtkWidget` this cell will be rendering to
      minimum_size - location for storing the minimum size
      natural_size - location for storing the natural size
    • getPreferredWidth

      public void getPreferredWidth(@Nonnull Widget widget, @Nullable Int minimum_size, @Nullable Int natural_size)
      Retrieves a renderer’s natural size when rendered to @widget.
      Parameters:
      widget - the `GtkWidget` this cell will be rendering to
      minimum_size - location to store the minimum size
      natural_size - location to store the natural size
    • getPreferredWidthForHeight

      public void getPreferredWidthForHeight(@Nonnull Widget widget, int height, @Nullable Int minimum_width, @Nullable Int natural_width)
      Retrieves a cell renderers’s minimum and natural width if it were rendered to
      @widget with the specified @height.
      Parameters:
      widget - the `GtkWidget` this cell will be rendering to
      height - the size which is available for allocation
      minimum_width - location for storing the minimum size
      natural_width - location for storing the preferred size
    • getRequestMode

      public int getRequestMode()
      Gets whether the cell renderer prefers a height-for-width layout
      or a width-for-height layout.
      Returns:
      The `GtkSizeRequestMode` preferred by this renderer.
    • getSensitive

      public boolean getSensitive()
      Returns the cell renderer’s sensitivity.
      Returns:
      %TRUE if the cell renderer is sensitive
    • getState

      public int getState(@Nullable Widget widget, int cell_state)
      Translates the cell renderer state to `GtkStateFlags`,
      based on the cell renderer and widget sensitivity, and
      the given `GtkCellRenderer`State.
      Parameters:
      widget - a `GtkWidget`
      cell_state - cell renderer state
      Returns:
      the widget state flags applying to @cell
    • getVisible

      public boolean getVisible()
      Returns the cell renderer’s visibility.
      Returns:
      %TRUE if the cell renderer is visible
    • isActivatable

      public boolean isActivatable()
      Checks whether the cell renderer can do something when activated.
      Returns:
      %TRUE if the cell renderer can do anything when activated
    • setAlignment

      public void setAlignment(float xalign, float yalign)
      Sets the renderer’s alignment within its available space.
      Parameters:
      xalign - the x alignment of the cell renderer
      yalign - the y alignment of the cell renderer
    • setFixedSize

      public void setFixedSize(int width, int height)
      Sets the renderer size to be explicit, independent of the properties set.
      Parameters:
      width - the width of the cell renderer, or -1
      height - the height of the cell renderer, or -1
    • setIsExpanded

      public void setIsExpanded(boolean is_expanded)
      Sets whether the given `GtkCellRenderer` is expanded.
      Parameters:
      is_expanded - whether @cell should be expanded
    • setIsExpander

      public void setIsExpander(boolean is_expander)
      Sets whether the given `GtkCellRenderer` is an expander.
      Parameters:
      is_expander - whether @cell is an expander
    • setPadding

      public void setPadding(int xpad, int ypad)
      Sets the renderer’s padding.
      Parameters:
      xpad - the x padding of the cell renderer
      ypad - the y padding of the cell renderer
    • setSensitive

      public void setSensitive(boolean sensitive)
      Sets the cell renderer’s sensitivity.
      Parameters:
      sensitive - the sensitivity of the cell
    • setVisible

      public void setVisible(boolean visible)
      Sets the cell renderer’s visibility.
      Parameters:
      visible - the visibility of the cell
    • snapshot

      public void snapshot(@Nonnull Snapshot snapshot, @Nonnull Widget widget, @Nonnull Rectangle background_area, @Nonnull Rectangle cell_area, int flags)
      Invokes the virtual render function of the `GtkCellRenderer`. The three
      passed-in rectangles are areas in @cr. Most renderers will draw within
      @cell_area; the xalign, yalign, xpad, and ypad fields of the `GtkCellRenderer`
      should be honored with respect to @cell_area. @background_area includes the
      blank space around the cell, and also the area containing the tree expander;
      so the @background_area rectangles for all cells tile to cover the entire
      @window.
      Parameters:
      snapshot - a `GtkSnapshot` to draw to
      widget - the widget owning @window
      background_area - entire cell area (including tree expanders and maybe padding on the sides)
      cell_area - area normally rendered by a cell renderer
      flags - flags that affect rendering
    • startEditing

      public CellEditable startEditing(@Nullable Event event, @Nonnull Widget widget, @Nonnull Str path, @Nonnull Rectangle background_area, @Nonnull Rectangle cell_area, int flags)
      Starts editing the contents of this @cell, through a new `GtkCellEditable`
      widget created by the `GtkCellRenderer`Class.start_editing virtual function.
      Parameters:
      event - a `GdkEvent`
      widget - widget that received the event
      path - widget-dependent string representation of the event location; e.g. for `GtkTreeView`, a string representation of `GtkTreePath`
      background_area - background area as passed to gtk_cell_renderer_render()
      cell_area - cell area as passed to gtk_cell_renderer_render()
      flags - render flags
      Returns:
      A new `GtkCellEditable` for editing this @cell, or %NULL if editing is not possible
    • startEditing

      public CellEditable startEditing(@Nullable Event event, @Nonnull Widget widget, String path, @Nonnull Rectangle background_area, @Nonnull Rectangle cell_area, int flags)
      Starts editing the contents of this @cell, through a new `GtkCellEditable`
      widget created by the `GtkCellRenderer`Class.start_editing virtual function.
      Parameters:
      event - a `GdkEvent`
      widget - widget that received the event
      path - widget-dependent string representation of the event location; e.g. for `GtkTreeView`, a string representation of `GtkTreePath`
      background_area - background area as passed to gtk_cell_renderer_render()
      cell_area - cell area as passed to gtk_cell_renderer_render()
      flags - render flags
      Returns:
      A new `GtkCellEditable` for editing this @cell, or %NULL if editing is not possible
    • stopEditing

      public void stopEditing(boolean canceled)
      Informs the cell renderer that the editing is stopped.
      If @canceled is %TRUE, the cell renderer will emit the
      `GtkCellRenderer`::editing-canceled signal.

      This function should be called by cell renderer implementations
      in response to the `GtkCellEditable::editing-done` signal of
      `GtkCellEditable`.
      Parameters:
      canceled - %TRUE if the editing has been canceled
    • onEditingCanceled

      public SignalHandler onEditingCanceled(CellRenderer.OnEditingCanceled signal)
      Connect to signal "editing-canceled".
      See CellRenderer.OnEditingCanceled.onEditingCanceled() for signal description.
      Field SIGNAL_ON_EDITING_CANCELED 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.
    • onEditingStarted

      public SignalHandler onEditingStarted(CellRenderer.OnEditingStarted signal)
      Connect to signal "editing-started".
      See CellRenderer.OnEditingStarted.onEditingStarted(ch.bailu.gtk.gtk.CellEditable, ch.bailu.gtk.type.Str) for signal description.
      Field SIGNAL_ON_EDITING_STARTED 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.
    • 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()