Gnome::Gtk4::R-CellLayout
Description
An interface for packing cells
Gnome::Gtk4::R-CellLayout is an interface to be implemented by all objects which want to provide a Gnome::Gtk4::TreeViewColumn like API for packing cells, setting attributes and data funcs.
One of the notable features provided by implementations of Gnome::Gtk4::R-CellLayout are attributes. Attributes let you set the properties in flexible ways. They can just be set to constant values like regular properties. But they can also be mapped to a column of the underlying tree model with .set-attributes()
, which means that the value of the attribute can change from cell to cell as they are rendered by the cell renderer. Finally, it is possible to specify a function with .set-cell-data-func()
that is called to determine the value of the attribute for each cell that is rendered.
GtkCellLayouts as GtkBuildable
Implementations of GtkCellLayout which also implement the GtkBuildable interface (Gnome::Gtk4::CellView, Gnome::Gtk4::IconView, Gnome::Gtk4::ComboBox, Gnome::Gtk4::EntryCompletion, Gnome::Gtk4::TreeViewColumn) accept Gnome::Gtk4::CellRenderer objects as `<child>` elements in UI definitions. They support a custom `<attributes>` element for their children, which can contain multiple `<attribute>` elements. Each `<attribute>` element has a name attribute which specifies a property of the cell renderer; the content of the element is the attribute value.
This is an example of a UI definition fragment specifying attributes:
Furthermore for implementations of Gnome::Gtk4::R-CellLayout that use a Gnome::Gtk4::CellArea to lay out cells (all Gnome::Gtk4::R-CellLayouts in GTK use a Gnome::Gtk4::CellArea) [cell properties](class.CellArea.html#cell-properties) can also be defined in the format by specifying the custom `<cell-packing>` attribute which can contain multiple `<property>` elements.
Here is a UI definition fragment specifying cell properties:
Subclassing GtkCellLayout implementations
When subclassing a widget that implements Gnome::Gtk4::R-CellLayout like Gnome::Gtk4::IconView or Gnome::Gtk4::ComboBox, there are some considerations related to the fact that these widgets internally use a Gnome::Gtk4::CellArea. The cell area is exposed as a construct-only property by these widgets. This means that it is possible to e.g. do
to use a custom cell area with a combo box. But construct properties are only initialized after instance init()` functions have run, which means that using functions which rely on the existence of the cell area in your subclass init()` function will cause the default cell area to be instantiated. In this case, a provided construct property value will be ignored (with a warning, to alert you to the problem).
If supporting alternative cell areas with your derived widget is not important, then this does not have to concern you. If you want to support alternative cell areas, you can do so by moving the problematic calls out of init()` and into a constructor()` for your class.
Methods
add-attribute
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Adds an attribute mapping to the list in $cell-layout
.
The $column
is the column of the model to get a value from, and the $attribute
is the property on $cell
to be set from that value. So for example if column 2 of the model contains strings, you could have the “text” attribute of a Gnome::Gtk4::CellRendererText get its values from column 2. In this context "attribute" and "property" are used interchangeably.
method add-attribute ( N-Object() $cell, Str $attribute, Int() $column )
$cell; a Gnome::Gtk4::CellRenderer.
$attribute; a property on the renderer.
$column; the column position on the model to get the attribute from.
clear
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Unsets all the mappings on all renderers on $cell-layout
and removes all renderers from $cell-layout
.
method clear ( )
clear-attributes
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Clears all existing attributes previously set with .set-attributes()
.
method clear-attributes ( N-Object() $cell )
$cell; a Gnome::Gtk4::CellRenderer to clear the attribute mapping on.
get-area
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Returns the underlying Gnome::Gtk4::CellArea which might be $cell-layout
if called on a Gnome::Gtk4::CellArea or might be undefined if no Gnome::Gtk4::CellArea is used by $cell-layout
.
method get-area (--> N-Object )
Return value; the cell area used by $cell-layout
.
get-cells
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Returns the cell renderers which have been added to $cell-layout
.
method get-cells (--> N-List )
Return value; a list of cell renderers. The list, but not the renderers has been newly allocated and should be freed with g_list_free() when no longer needed..
pack-end
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Adds the $cell
to the end of $cell-layout
. If $expand
is False
, then the $cell
is allocated no more space than it needs. Any unused space is divided evenly between cells for which $expand
is True
.
Note that reusing the same cell renderer is not supported.
method pack-end ( N-Object() $cell, Bool() $expand )
$cell; a Gnome::Gtk4::CellRenderer.
$expand;
True
if$cell
is to be given extra space allocated to$cell-layout
.
pack-start
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Packs the $cell
into the beginning of $cell-layout
. If $expand
is False
, then the $cell
is allocated no more space than it needs. Any unused space is divided evenly between cells for which $expand
is True
.
Note that reusing the same cell renderer is not supported.
method pack-start ( N-Object() $cell, Bool() $expand )
$cell; a Gnome::Gtk4::CellRenderer.
$expand;
True
if$cell
is to be given extra space allocated to$cell-layout
.
reorder
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Re-inserts $cell
at $position
.
Note that $cell
has already to be packed into $cell-layout
for this to function properly.
method reorder ( N-Object() $cell, Int() $position )
$cell; a Gnome::Gtk4::CellRenderer to reorder.
$position; new position to insert
$cell
at.
set-attributes This function is not yet available
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Sets the attributes in the parameter list as the attributes of $cell-layout
.
See .add-attribute()
for more details.
The attributes should be in attribute/column order, as in .add-attribute()
. All existing attributes are removed, and replaced with the new attributes.
method set-attributes ( N-Object() $cell, … )
$cell; a Gnome::Gtk4::CellRenderer.
…; …. Note that each argument must be specified as a type followed by its value!
set-cell-data-func This function is not yet available
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Sets the Gnome::Gtk4::R-CellLayoutDataFunc to use for $cell-layout
.
This function is used instead of the standard attributes mapping for setting the column value, and should set the value of $cell-layout
’s cell renderer(s) as appropriate. $func
may be undefined to remove a previously set function.
method set-cell-data-func ( N-Object() $cell, &func, gpointer $func-data, … )
$cell; a Gnome::Gtk4::CellRenderer.
&func; the Gnome::Gtk4::R-CellLayoutDataFunc to use. Tthe function must be specified with following signature;
:( N-Object $cell-layout, N-Object $cell, N-Object $tree-model, N-Object $iter, gpointer $data )
.$func-data; user data for
$func
.destroy; destroy notify for
$func-data
. Note that each argument must be specified as a type followed by its value!