Gtk2::CellRenderer(3)

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

πŸ’– 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::Rectangle or 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 $cell is rendering
  • $cell_area (Gtk2::Gdk::Rectangle or undef) β€” the area a cell will be allocated, or undef

Return values:

  • x_offset β€” x offset of cell relative to $cell_area
  • y_offset β€” y offset of cell relative to $cell_area
  • width β€” width needed to render cell
  • height β€” 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 a Gtk2::TreeView, a string representation of a Gtk2::TreePath
  • $background_area (Gtk2::Gdk::Rectangle) β€” background area as passed to RENDER
  • $cell_area (Gtk2::Gdk::Rectangle) β€” cell area as passed to RENDER
  • $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 a Gtk2::TreeView, a string representation of a Gtk2::TreePath
  • $background_area (Gtk2::Gdk::Rectangle) β€” background area as passed to RENDER
  • $cell_area (Gtk2::Gdk::Rectangle) β€” cell area as passed to RENDER
  • $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 πŸ‘€πŸ’œ

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