class Gtk::LayoutManager

Overview

Layout managers are delegate classes that handle the preferred size and the allocation of a widget.

You typically subclass Gtk::LayoutManager if you want to implement a layout policy for the children of a widget, or if you want to determine the size of a widget depending on its contents.

Each Gtk::Widget can only have a Gtk::LayoutManager instance associated to it at any given time; it is possible, though, to replace the layout manager instance using Gtk::Widget#layout_manager=.

Layout properties

A layout manager can expose properties for controlling the layout of each child, by creating an object type derived from Gtk::LayoutChild and installing the properties on it as normal GObject properties.

Each Gtk::LayoutChild instance storing the layout properties for a specific child is created through the Gtk::LayoutManager#layout_child method; a Gtk::LayoutManager controls the creation of its Gtk::LayoutChild instances by overriding the Gtk::LayoutManagerClass.create_layout_child() virtual function. The typical implementation should look like:

WARNING ⚠️ The following code is in c ⚠️

static Gtk::LayoutChild *
create_layout_child (Gtk::LayoutManager *manager,
                     Gtk::Widget        *container,
                     Gtk::Widget        *child)
{
  return g_object_new (your_layout_child_get_type (),
                       "layout-manager", manager,
                       "child-widget", child,
                       NULL);
}

The [property@Gtk.LayoutChild:layout-manager] and [property@Gtk.LayoutChild:child-widget] properties on the newly created Gtk::LayoutChild instance are mandatory. The Gtk::LayoutManager will cache the newly created Gtk::LayoutChild instance until the widget is removed from its parent, or the parent removes the layout manager.

Each Gtk::LayoutManager instance creating a Gtk::LayoutChild should use Gtk::LayoutManager#layout_child every time it needs to query the layout properties; each Gtk::LayoutChild instance should call Gtk::LayoutManager#layout_changed every time a property is updated, in order to queue a new size measuring and allocation.

Direct Known Subclasses

Defined in:

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

Constructors

Class Method Summary

Instance Method Summary

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

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

def self.new #

Initialize a new LayoutManager.


[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 allocate(widget : Gtk::Widget, width : Int32, height : Int32, baseline : Int32) : Nil #

Assigns the given width, height, and baseline to a widget, and computes the position and sizes of the children of the widget using the layout management policy of manager.


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

See Object#hash(hasher)


def layout_changed : Nil #

Queues a resize on the Gtk::Widget using manager, if any.

This function should be called by subclasses of Gtk::LayoutManager in response to changes to their layout management policies.


[View source]
def layout_child(child : Gtk::Widget) : Gtk::LayoutChild #

Retrieves a Gtk::LayoutChild instance for the Gtk::LayoutManager, creating one if necessary.

The child widget must be a child of the widget using manager.

The Gtk::LayoutChild instance is owned by the Gtk::LayoutManager, and is guaranteed to exist as long as child is a child of the Gtk::Widget using the given Gtk::LayoutManager.


[View source]
def measure(widget : Gtk::Widget, orientation : Gtk::Orientation, for_size : Int32) : Nil #

Measures the size of the widget using manager, for the given orientation and size.

See the Gtk::Widget documentation on layout management for more details.


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

Retrieves the request mode of manager.


[View source]
def widget : Gtk::Widget | Nil #

Retrieves the Gtk::Widget using the given Gtk::LayoutManager.


[View source]