Gtk2::CellRenderer(3)
π Gtk2::CellRenderer π
okay bestie, welcome to the user contributed perl documentation corner of the universe, specifically the Gtk2::CellRenderer(3) page. buckle up, this one's a chonker, and it's only part 1. π
β¨ NAME β¨
Gtk2::CellRenderer β an object that renders a single cell onto a Gtk2::Gdk::Drawable
πΈ DESCRIPTION πΈ
So. Gtk2::CellRenderer is the base class for all the little objects that render cells onto drawables. They're mostly used by Gtk2::TreeView, but likeβ¦ they're not tied to it, no strings attached, they can vibe elsewhere. π¦
Typically, one cell renderer is used to draw many cells onto the screen. Which means β plot twist β the cell renderer doesn't keep state. none. zero. instead, any state gets set immediately right before use through the object property system. the cell gets measured with get_size, and then rendered with render. that's the whole loop, slay. β¨
π HIERARCHY π
Glib::Object
+----Glib::InitiallyUnowned
+----Gtk2::Object
+----Gtk2::CellRenderer
the family tree, literally. π
π METHODS π
boolean = $cell->activate ($event, $widget, $path, $background_area, $cell_area, $flags)
$event(Gtk2::Gdk::Event)$widget(Gtk2::Widget)$path(string)$background_area(Gtk2::Gdk::Rectangle)$cell_area(Gtk2::Gdk::Rectangle)$flags(Gtk2::CellRendererState)
(xalign, yalign) = $cell->get_alignment
Since: gtk+ 2.18
$cell->set_alignment ($xalign, $yalign)
$xalign(double)$yalign(double)
Since: gtk+ 2.18
$cell->editing_canceled
Since: gtk+ 2.4
(width, height) = $cell->get_fixed_size
Fetch the fixed size of $cell. values of -1 mean "this dimension is not fixed", i.e. it's free-range, it does what it wants. π¦
$cell->set_fixed_size ($width, $height)
$width(integer)$height(integer)
Sets the renderer's size explicitly, independent of object properties. a value of -1 means "don't use a fixed size for this dimension." no cap.
(xpad, ypad) = $cell->get_padding
Since: gtk+ 2.18
$cell->set_padding ($xpad, $ypad)
$xpad(integer)$ypad(integer)
Since: gtk+ 2.18
$cell->render ($drawable, $widget, $background_area, $cell_area, $expose_area, $flags)
$drawable(Gtk2::Gdk::Drawable)$widget(Gtk2::Widget)$background_area(Gtk2::Gdk::Rectangle)$cell_area(Gtk2::Gdk::Rectangle)$expose_area(Gtk2::Gdk::Rectangle)$flags(Gtk2::CellRendererState)
boolean = $cell->get_sensitive
Since: gtk+ 2.18
$cell->set_sensitive ($sensitive)
$sensitive(boolean)
Since: gtk+ 2.18
(x_offset, y_offset, width, height) = $cell->get_size ($widget, $cell_area)
$widget(Gtk2::Widget)$cell_area(Gtk2::Gdk::Rectangleor undef)
celleditable or undef = $cell->start_editing ($event, $widget, $path, $background_area, $cell_area, $flags)
$event(Gtk2::Gdk::Event)$widget(Gtk2::Widget)$path(string)$background_area(Gtk2::Gdk::Rectangle)$cell_area(Gtk2::Gdk::Rectangle)$flags(Gtk2::CellRendererState)
$cell->stop_editing ($canceled)
$canceled(boolean)
Since: gtk+ 2.6
boolean = $cell->get_visible
Since: gtk+ 2.18
$cell->set_visible ($visible)
$visible(boolean)
Since: gtk+ 2.18
π PROPERTIES π
'cell-background'(string : default undef : writable / private / static-nick / static-blurb) β the cell background color, as a string π'cell-background-gdk'(Gtk2::Gdk::Color: default undef : readable / writable / private / static-nick / static-blurb) β the cell background color, but as a GdkColor this time'cell-background-set'(boolean : default false : readable / writable / private / static-nick / static-blurb) β whether this tag affects the cell background color'editing'(boolean : default false : readable / private / static-nick / static-blurb) β whether the cell renderer is currently in editing mode'height'(integer : default -1 : readable / writable / private / static-nick / static-blurb) β the fixed height'is-expanded'(boolean : default false : readable / writable / private / static-nick / static-blurb) β row is an expander row, and is expanded'is-expander'(boolean : default false : readable / writable / private / static-nick / static-blurb) β row has children'mode'(Gtk2::CellRendererMode: default "inert" : readable / writable / private / static-nick / static-blurb) β the editable mode of the CellRenderer'sensitive'(boolean : default true : readable / writable / private / static-nick / static-blurb) β display the cell sensitive'visible'(boolean : default true : readable / writable / private / static-nick / static-blurb) β display the cell'width'(integer : default -1 : readable / writable / private / static-nick / static-blurb) β the fixed width'xalign'(float : default 0.5 : readable / writable / private / static-nick / static-blurb) β the x-align'xpad'(Glib::UInt: default 0 : readable / writable / private / static-nick / static-blurb) β the xpad'yalign'(float : default 0.5 : readable / writable / private / static-nick / static-blurb) β the y-align'ypad'(Glib::UInt: default 0 : readable / writable / private / static-nick / static-blurb) β the ypad
π SIGNALS π
editing-canceled(Gtk2::CellRenderer)editing-started(Gtk2::CellRenderer,Gtk2::CellEditable, string)
π ENUMS AND FLAGS π
enum Gtk2::CellRendererMode
'inert'/'GTK_CELL_RENDERER_MODE_INERT''activatable'/'GTK_CELL_RENDERER_MODE_ACTIVATABLE''editable'/'GTK_CELL_RENDERER_MODE_EDITABLE'
flags Gtk2::CellRendererState
'selected'/'GTK_CELL_RENDERER_SELECTED''prelit'/'GTK_CELL_RENDERER_PRELIT''insensitive'/'GTK_CELL_RENDERER_INSENSITIVE''sorted'/'GTK_CELL_RENDERER_SORTED''focused'/'GTK_CELL_RENDERER_FOCUSED'
π§ DERIVING NEW CELL RENDERERS π§
Gtk+ hands you three cell renderers already: Gtk2::CellRendererText, Gtk2::CellRendererToggle, and Gtk2::CellRendererPixbuf. you can derive a new renderer from any of those, or straight from Gtk2::CellRenderer itself if you're feeling brave. π
now, there are rules. a whole set of them. first and foremost, it's important that a certain set of properties always yields a cell of the same size, barring a Gtk2::Style change. consistency is the vibe. also, the cell renderer has a bunch of generic properties that all children are expected to honor. π
the new renderer must be a GObject, so you follow the normal procedure for creating a new Glib::Object β that's either Glib::Object::Subclass or Glib::Type::register_object, pick your fighter. the new subclass can customize the object's behavior by providing new implementations of these four methods:
(x_offset, y_offset, width, height) = GET_SIZE ($cell, $widget, $cell_area)
$cell(Gtk2::CellRenderer)$widget(Gtk2::Widget) β widget to which$cellis rendering$cell_area(Gtk2::Gdk::Rectangleor undef) β the area a cell will be allocated, or undef
Return values:
x_offsetβ x offset of cell relative to$cell_areay_offsetβ y offset of cell relative to$cell_areawidthβ width needed to render cellheightβ height needed to render cell
this one is called to calculate the size of the cell for display, taking into account the padding and alignment properties of the parent. and bestie, it gets called very often. if you need to know your cell's data, grab it from the appropriate object properties, because those will be set accordingly before this method is called. π«Ά
RENDER ($cell, $drawable, $widget, $background_area, $cell_area, $expose_area, $flags)
$cell(Gtk2::CellRenderer)$drawable(Gtk2::Gdk::Drawable) β window on which to draw$widget(Gtk2::Widget) β widget owning$drawable$background_area(Gtk2::Gdk::Rectangle) β entire cell area (including tree expanders and maybe padding on the sides)$cell_area(Gtk2::Gdk::Rectangle) β area normally rendered by a cell renderer$expose_area(Gtk2::Gdk::Rectangle) β area that actually needs updating$flags(Gtk2::CellRendererState) β flags that affect rendering
called to render the cell onto the screen. same deal as GET_SIZE: the data for the cell comes from object properties. in general you'll want to make use of Gtk2::Style methods for drawing anything fancy. β¨
the three passed-in rectangles are areas of $drawable. most renderers draw within $cell_area; the xalign, yalign, xpad, and ypad fields of the cell renderer 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 cover the entire $drawable. and $expose_area is a clip rectangle. noted. π
boolean = ACTIVATE ($cell, $event, $widget, $path, $background_area, $cell_area, $flags)
$cell(Gtk2::CellRenderer)$event(Gtk2::Gdk::Event)$widget(Gtk2::Widget) β widget that received the event$path(string) β widget-dependent string representation of the event location; e.g. for aGtk2::TreeView, a string representation of aGtk2::TreePath$background_area(Gtk2::Gdk::Rectangle) β background area as passed toRENDER$cell_area(Gtk2::Gdk::Rectangle) β cell area as passed toRENDER$flags(Gtk2::CellRendererState) β render flags
this method is called when an event occurs on a cell. implementing it is not mandatory, so no pressure. the return value should be TRUE if the event was consumed/handled. π―
celleditable or undef = START_EDITING ($cell, $event, $widget, $path, $background_area, $cell_area, $flags)
$cell(Gtk2::CellRenderer)$event(Gtk2::Gdk::Event)$widget(Gtk2::Widget) β widget that received the event$path(string) β widget-dependent string representation of the event location; e.g. for aGtk2::TreeView, a string representation of aGtk2::TreePath$background_area(Gtk2::Gdk::Rectangle) β background area as passed toRENDER$cell_area(Gtk2::Gdk::Rectangle) β cell area as passed toRENDER$flags(Gtk2::CellRendererState) β render flags
for cells that are editable, this is called to put the cell into editing mode. if the return value is an object that's a Gtk2::CellEditable, that widget will be used to edit the value β the calling code takes care of sizing, placing, and showing the editable, you just need to return it. if the return value is undef, the editing is aborted. that simple. π
Note: for backward compatibility, the bizarre and non-standard scheme used for this in 1.02x is still supported, but it is deprecated and should not be used in new code, and since i don't want people to use it any more i will not document it here. π
π SEE ALSO π
Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object
okay that's it for this half, bestie β don't go anywhere, there's more coming ππ
π COPYRIGHT π
okay bestie, legal era incoming, but it's short and sweet so we're fine π«Ά
- Copyright (C) 2003-2011 by the gtk2-perl team. β¨
- This software is licensed under the LGPL. See Gtk2 for a full notice. π
that's it, that's the whole vibe check. no cap. π
so like, this lil page came from perl v5.42.0 and got its glow-up on 2025-07-25 β and honestly? iconic of it. πΈπ¦ go read the actual docs, mwah, bye bestie ππ
π¦ where this page comes from
- fedora 43: perl-Gtk2 1.24993-23.fc43 Β· LicenseRef-Callaway-LGPLv2+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms