Gtk2::CellLayout(3)

πŸ“¦
version 1.24993 Β· 2 versions
, in fedora 43

πŸ’– Gtk2::CellLayout β€” bestie edition πŸ’–

okay so this page is Gtk2::CellLayout(3), from the User Contributed Perl Documentation corner of the internet, and it's literally the wrapper for GtkCellLayout. sit down, grab a boba, we're doing this πŸ§‹βœ¨


✨ NAME ✨

Gtk2::CellLayout β€” it's the wrapper for GtkCellLayout, periodt.


🌸 SYNOPSIS 🌸

no cap, here's the whole vibe in code:

# This is an abstract interface; the CellLayout interface is
# implemented by concrete classes like ComboBox and TreeViewColumn.
# See the discussion for details on creating your own CellLayout.
# This synopsis assumes you already have an instance in $cell_layout.

# Add a cell renderer that shows the pixbuf in column 2 of the
# associated TreeModel.  It will take up only the necessary space
# ("expand" => FALSE).
my $cell = Gtk2::CellRendererPixbuf->new ();
$cell_layout->pack_start ($cell, FALSE);
$cell_layout->add_attribute ($cell, pixbuf => 2);

# Add another cell renderer that gets the "text" property from
# column 3 of the associated TreeModel, and takes up all remaining
# horizontal space ("expand" => TRUE).
my $cell = Gtk2::CellRendererText->new ();
$cell_layout->pack_start ($cell, TRUE);
$cell_layout->add_attribute ($cell, text => 3);

like… iconic behavior honestly πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so Gtk2::CellLayout is an interface, okay? every single object that wants to serve a Gtk2::TreeViewColumn-like API β€” you know, packing cells, setting attributes, setting data funcs β€” implements this. it's giving "template for the girlies who want the TreeViewColumn energy" πŸ‘‘


🌈 HIERARCHY 🌈

Glib::Interface
+----Gtk2::CellLayout

she comes from Glib::Interface, that's her lineage bestie 🫢


πŸ’… METHODS πŸ’…

🌟 $cell_layout->add_attribute ($cell, $attribute, $column)

  • $cell (Gtk2::CellRenderer)
  • $attribute (string)
  • $column (integer)

adds an attribute mapping to the list that lives in $cell_layout. the $column is the column of the model you're pulling a value from, and $attribute is the property of $cell that value gets assigned to. so like, say column 2 of the model is full of strings β€” you could have the "text" attribute of a Gtk2::CellRendererText get its values from column 2. match made in heaven fr fr πŸ˜­πŸ’–

🌟 $cell_layout->set_attributes ($cell, ...)

  • $cell (Gtk2::CellRenderer)
  • ... (list) β€” a list of property name and column number pairs.

sets the pairs in that ... list as the attributes of $cell_layout, exactly like you'd get from calling add_attribute over and over. heads up though: all existing attributes get removed and replaced with the new ones. out with the old, in with the new ✨

🌟 $cell_layout->set_cell_data_func ($cell, $func, $func_data=undef)

  • $cell (Gtk2::CellRenderer)
  • $func (scalar)
  • $func_data (scalar)

sets up $cell_layout to call $func to set up the attributes of $cell, instead of doing the standard attribute mapping thing. $func can be undef if you wanna remove an older callback, no hard feelings πŸŽ€

$func will receive these parameters:

$cell_layout  The cell layout instance
$cell         The cell renderer to set up
$model        The tree model
$iter         TreeIter of the row for which to set the values
$data         The $func_data passed to "set_cell_data_func"

🌟 list = $cell_layout->get_cells

fetches all the cell renderers that have been added to $cell_layout. slay.

⚠️ okay important: if there are no cells, this function returns 'undef' instead of an empty list. not a vibe, but it's the truth πŸ’€

Since: gtk+ 2.12

🌟 $cell_layout->clear

unsets all the mappings on all renderers on $cell_layout, and removes all renderers attached to it. full reset, clean slate, main character fresh start 🌸

🌟 $cell_layout->clear_attributes ($cell)

  • $cell (Gtk2::CellRenderer)

clears all existing attributes that were previously set for $cell with "add_attribute" or "set_attributes". bye bye attributes πŸ‘‹

🌟 $cell_layout->pack_end ($cell, $expand)

  • $cell (Gtk2::CellRenderer)
  • $expand (boolean)

just like "pack_start", except it adds from the end of the layout instead of the beginning. same energy, different direction πŸ”₯

🌟 $cell_layout->pack_start ($cell, $expand)

  • $cell (Gtk2::CellRenderer)
  • $expand (boolean)

packs $cell into the beginning of $cell_layout. if $expand is false, then $cell gets allocated no more space than it needs. any unused space is divided evenly between the cells where $expand is true. sharing is caring 🫢

🌟 $cell_layout->reorder ($cell, $position)

  • $cell (Gtk2::CellRenderer)
  • $position (integer)

re-inserts $cell at $position. and ngl, $cell must already be packed into $cell_layout β€” that's not optional bestie, don't try it πŸ™ˆ


πŸ‘‘ CREATING A CUSTOM CELL LAYOUT πŸ‘‘

GTK+ already gives you several CellLayout implementations, like Gtk2::TreeViewColumn and Gtk2::ComboBox. but if you wanna create your own object that implements the CellLayout interface β€” and therefore can be used to display CellRenderers β€” you need to add Gtk2::CellLayout to your class's "interfaces" list, like this:

package MyLayout;
use Gtk2;
use Glib::Object::Subclass
    Gtk2::Widget::,
    interfaces => [ Gtk2::CellLayout:: ],
    ;

this will cause perl to call several virtual methods with ALL_CAPS_NAMES when GTK+ attempts to perform certain actions. you just provide (or override) those methods with perl code. the methods map pretty directly to the object interface, so honestly it should be easy to figure out what they should do. those methods are:

PACK_START ($cell_layout, $cell, $expand)
PACK_END ($cell_layout, $cell, $expand)
CLEAR ($cell_layout)
ADD_ATTRIBUTE ($cell_layout, $cell, $attribute, $column)
SET_CELL_DATA_FUNC ($cell_layout, $cell, $func, $data)
CLEAR_ATTRIBUTES ($cell_layout, $cell)
REORDER ($cell_layout, $cell, $position)
list = GET_CELLS ($cell_layout)

that's the whole roster, go off πŸ’œ


🌈 SEE ALSO 🌈

Gtk2, Glib::Interface


Copyright (C) 2003-2011 by the gtk2-perl team.

This software is licensed under the LGPL. See Gtk2 for a full notice.


and that's the tea, bestie πŸ“ this was perl v5.42.0, dated 2025-07-25, from the gtk2-perl girlies β€” stan them, they ate πŸ’–βœ¨πŸ‘‘

πŸ“¦ where this page comes from