class Gtk::LayoutManager

Overview

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

You typically subclass GtkLayoutManager 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 GtkWidget can only have a GtkLayoutManager 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 GtkLayoutChild instance storing the layout properties for a specific child is created through the Gtk::LayoutManager#layout_child method; a GtkLayoutManager controls the creation of its GtkLayoutChild instances by overriding the GtkLayoutManagerClass.create_layout_child() virtual function. The typical implementation should look like:

WARNING ⚠️ The following code is in c ⚠️

static GtkLayoutChild *
create_layout_child (GtkLayoutManager *manager,
                     GtkWidget        *container,
                     GtkWidget        *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 GtkLayoutChild instance are mandatory. The GtkLayoutManager will cache the newly created GtkLayoutChild instance until the widget is removed from its parent, or the parent removes the layout manager.

Each GtkLayoutManager instance creating a GtkLayoutChild should use Gtk::LayoutManager#layout_child every time it needs to query the layout properties; each GtkLayoutChild 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

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, 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 LayoutManager.


Class Method Detail

def self.g_type : UInt64 #

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


Instance Method Detail

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.


def layout_changed : Nil #

Queues a resize on the GtkWidget using @manager, if any.

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


def layout_child(child : Gtk::Widget) : Gtk::LayoutChild #

Retrieves a GtkLayoutChild instance for the GtkLayoutManager, creating one if necessary.

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

The GtkLayoutChild instance is owned by the GtkLayoutManager, and is guaranteed to exist as long as @child is a child of the GtkWidget using the given GtkLayoutManager.


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.


def request_mode : Gtk::SizeRequestMode #

Retrieves the request mode of @manager.


def widget : Gtk::Widget? #

Retrieves the GtkWidget using the given GtkLayoutManager.