class Gtk::CellRenderer

Overview

An object for rendering a single cell

The Gtk::CellRenderer 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 Gtk::TreeView widget, though they aren’t tied to them in any specific way. It is worth noting that Gtk::CellRenderer is not a Gtk::Widget and cannot be treated as such.

The primary use of a Gtk::CellRenderer 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 GObjects 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 Gtk::CellRenderer. 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 Gtk::CellRenderer 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 Gtk::CellRendererToggle, which toggles when it gets activated by a mouse click, or it can be “editable” like Gtk::CellRendererText, which allows the user to edit the text using a widget implementing the Gtk::CellEditable interface, e.g. Gtk::Entry. To make a cell renderer activatable or editable, you have to implement the Gtk::CellRendererClass.activate or Gtk::CellRendererClass.start_editing virtual functions, respectively.

Many properties of Gtk::CellRenderer 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.

Direct Known Subclasses

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/cell_renderer.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor methods inherited from class GObject::InitiallyUnowned

new new

Class methods inherited from class GObject::InitiallyUnowned

g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new #

Initialize a new CellRenderer.


def self.new(*, cell_background : String? = nil, cell_background_rgba : Gdk::RGBA? = nil, cell_background_set : Bool? = nil, editing : Bool? = nil, height : Int32? = nil, is_expanded : Bool? = nil, is_expander : Bool? = nil, mode : Gtk::CellRendererMode? = nil, sensitive : Bool? = nil, visible : Bool? = nil, width : Int32? = nil, xalign : Float32? = nil, xpad : UInt32? = nil, yalign : Float32? = nil, ypad : UInt32? = nil) #

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def activate(event : Gdk::Event, widget : Gtk::Widget, path : String, background_area : Gdk::Rectangle, cell_area : Gdk::Rectangle, flags : Gtk::CellRendererState) : Bool #

Passes an activate event to the cell renderer for possible processing. Some cell renderers may use events; for example, Gtk::CellRendererToggle toggles when it gets a mouse click.


def aligned_area(widget : Gtk::Widget, flags : Gtk::CellRendererState, cell_area : Gdk::Rectangle) : Gdk::Rectangle #

Gets the aligned area used by @cell inside @cell_area. Used for finding the appropriate edit and focus rectangle.


def alignment : Nil #

Fills in @xalign and @yalign with the appropriate values of @cell.


def cell_background=(value : String) : String #

def cell_background_rgba : Gdk::RGBA? #

def cell_background_rgba=(value : Gdk::RGBA?) : Gdk::RGBA? #

def cell_background_set=(value : Bool) : Bool #

def cell_background_set? : Bool #

def editing? : Bool #

def editing_canceled_signal #

def editing_started_signal #

def fixed_size : Nil #

Fills in @width and @height with the appropriate size of @cell.


def height : Int32 #

def height=(value : Int32) : Int32 #

def is_activatable : Bool #

Checks whether the cell renderer can do something when activated.


def is_expanded : Bool #

Checks whether the given Gtk::CellRenderer is expanded.


def is_expanded=(is_expanded : Bool) : Nil #

Sets whether the given Gtk::CellRenderer is expanded.


def is_expanded? : Bool #

def is_expander : Bool #

Checks whether the given Gtk::CellRenderer is an expander.


def is_expander=(is_expander : Bool) : Nil #

Sets whether the given Gtk::CellRenderer is an expander.


def is_expander? : Bool #



def padding : Nil #

Fills in @xpad and @ypad with the appropriate values of @cell.


def preferred_height(widget : Gtk::Widget) : Nil #

Retrieves a renderer’s natural size when rendered to @widget.


def preferred_height_for_width(widget : Gtk::Widget, width : Int32) : Nil #

Retrieves a cell renderers’s minimum and natural height if it were rendered to @widget with the specified @width.


def preferred_size(widget : Gtk::Widget) : Gtk::Requisition #

Retrieves the minimum and natural size of a cell taking into account the widget’s preference for height-for-width management.


def preferred_width(widget : Gtk::Widget) : Nil #

Retrieves a renderer’s natural size when rendered to @widget.


def preferred_width_for_height(widget : Gtk::Widget, height : Int32) : Nil #

Retrieves a cell renderers’s minimum and natural width if it were rendered to @widget with the specified @height.


def request_mode : Gtk::SizeRequestMode #

Gets whether the cell renderer prefers a height-for-width layout or a width-for-height layout.


def sensitive : Bool #

Returns the cell renderer’s sensitivity.


def sensitive=(sensitive : Bool) : Nil #

Sets the cell renderer’s sensitivity.


def sensitive? : Bool #

def set_alignment(xalign : Float32, yalign : Float32) : Nil #

Sets the renderer’s alignment within its available space.


def set_fixed_size(width : Int32, height : Int32) : Nil #

Sets the renderer size to be explicit, independent of the properties set.


def set_padding(xpad : Int32, ypad : Int32) : Nil #

Sets the renderer’s padding.


def snapshot(snapshot : Gtk::Snapshot, widget : Gtk::Widget, background_area : Gdk::Rectangle, cell_area : Gdk::Rectangle, flags : Gtk::CellRendererState) : Nil #

Invokes the virtual render function of the Gtk::CellRenderer. 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 Gtk::CellRenderer 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.


def start_editing(event : Gdk::Event?, widget : Gtk::Widget, path : String, background_area : Gdk::Rectangle, cell_area : Gdk::Rectangle, flags : Gtk::CellRendererState) : Gtk::CellEditable? #

Starts editing the contents of this @cell, through a new Gtk::CellEditable widget created by the Gtk::CellRendererClass.start_editing virtual function.


def state(widget : Gtk::Widget?, cell_state : Gtk::CellRendererState) : Gtk::StateFlags #

Translates the cell renderer state to Gtk::StateFlags, based on the cell renderer and widget sensitivity, and the given Gtk::CellRendererState.


def stop_editing(canceled : Bool) : Nil #

Informs the cell renderer that the editing is stopped. If @canceled is true, the cell renderer will emit the Gtk::CellRenderer::editing-canceled signal.

This function should be called by cell renderer implementations in response to the Gtk::CellEditable::editing-done signal of Gtk::CellEditable.


def visible : Bool #

Returns the cell renderer’s visibility.


def visible=(visible : Bool) : Nil #

Sets the cell renderer’s visibility.


def visible? : Bool #

def width : Int32 #

def width=(value : Int32) : Int32 #

def xalign : Float32 #

def xalign=(value : Float32) : Float32 #

def xpad : UInt32 #

def xpad=(value : UInt32) : UInt32 #

def yalign : Float32 #

def yalign=(value : Float32) : Float32 #

def ypad : UInt32 #

def ypad=(value : UInt32) : UInt32 #