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

Instance methods inherited from class GObject::InitiallyUnowned

==(other : self) ==, hash(hasher) hash

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

==(other : self) ==, 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) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, 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) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil 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, 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

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : 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.


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

[View source]

Class Method Detail

def self.g_type : UInt64 #

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


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


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.


[View source]
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.


[View source]
def alignment : Nil #

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


[View source]
def cell_background=(value : String) : String #

[View source]
def cell_background_rgba : Gdk::RGBA | Nil #

[View source]
def cell_background_rgba=(value : Gdk::RGBA | Nil) : Gdk::RGBA | Nil #

[View source]
def cell_background_set=(value : Bool) : Bool #

[View source]
def cell_background_set? : Bool #

[View source]
def editing? : Bool #

[View source]
def editing_canceled_signal #

[View source]
def editing_started_signal #

[View source]
def fixed_size : Nil #

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


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def height : Int32 #

[View source]
def height=(value : Int32) : Int32 #

[View source]
def is_activatable : Bool #

Checks whether the cell renderer can do something when activated.


[View source]
def is_expanded : Bool #

Checks whether the given Gtk::CellRenderer is expanded.


[View source]
def is_expanded=(is_expanded : Bool) : Nil #

Sets whether the given Gtk::CellRenderer is expanded.


[View source]
def is_expanded? : Bool #

[View source]
def is_expander : Bool #

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


[View source]
def is_expander=(is_expander : Bool) : Nil #

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


[View source]
def is_expander? : Bool #

[View source]

[View source]

[View source]
def padding : Nil #

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


[View source]
def preferred_height(widget : Gtk::Widget) : Nil #

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


[View source]
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.


[View source]
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.


[View source]
def preferred_width(widget : Gtk::Widget) : Nil #

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


[View source]
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.


[View source]
def request_mode : Gtk::SizeRequestMode #

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


[View source]
def sensitive : Bool #

Returns the cell renderer’s sensitivity.


[View source]
def sensitive=(sensitive : Bool) : Nil #

Sets the cell renderer’s sensitivity.


[View source]
def sensitive? : Bool #

[View source]
def set_alignment(xalign : Float32, yalign : Float32) : Nil #

Sets the renderer’s alignment within its available space.


[View source]
def set_fixed_size(width : Int32, height : Int32) : Nil #

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


[View source]
def set_padding(xpad : Int32, ypad : Int32) : Nil #

Sets the renderer’s padding.


[View source]
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.


[View source]
def start_editing(event : Gdk::Event | Nil, widget : Gtk::Widget, path : String, background_area : Gdk::Rectangle, cell_area : Gdk::Rectangle, flags : Gtk::CellRendererState) : Gtk::CellEditable | Nil #

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


[View source]
def state(widget : Gtk::Widget | Nil, 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.


[View source]
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.


[View source]
def visible : Bool #

Returns the cell renderer’s visibility.


[View source]
def visible=(visible : Bool) : Nil #

Sets the cell renderer’s visibility.


[View source]
def visible? : Bool #

[View source]
def width : Int32 #

[View source]
def width=(value : Int32) : Int32 #

[View source]
def xalign : Float32 #

[View source]
def xalign=(value : Float32) : Float32 #

[View source]
def xpad : UInt32 #

[View source]
def xpad=(value : UInt32) : UInt32 #

[View source]
def yalign : Float32 #

[View source]
def yalign=(value : Float32) : Float32 #

[View source]
def ypad : UInt32 #

[View source]
def ypad=(value : UInt32) : UInt32 #

[View source]