About all my projects
Gnome::Gtk4::LayoutManager

Gnome::Gtk4::LayoutManager

Description

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

You typically subclass Gnome::Gtk4::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 Gnome::Gtk4::Widget can only have a Gnome::Gtk4::LayoutManager instance associated to it at any given time; it is possible, though, to replace the layout manager instance using .set-layout-manager() in class Gnome::Gtk4::Widget.

Layout properties

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

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

The layout-manager defined in Gnome::Gtk4::LayoutChild and child-widget defined in Gnome::Gtk4::LayoutChild properties on the newly created Gnome::Gtk4::LayoutChild instance are mandatory. The Gnome::Gtk4::LayoutManager will cache the newly created Gnome::Gtk4::LayoutChild instance until the widget is removed from its parent, or the parent removes the layout manager.

Each Gnome::Gtk4::LayoutManager instance creating a Gnome::Gtk4::LayoutChild should use .get-layout-child() every time it needs to query the layout properties; each Gnome::Gtk4::LayoutChild instance should call .layout-changed() every time a property is updated, in order to queue a new size measuring and allocation.

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

Methods

allocate

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.

method allocate ( N-Object() $widget, Int() $width, Int() $height, Int() $baseline )
  • $widget; the Gnome::Gtk4::Widget using $manager.

  • $width; the new width of the $widget.

  • $height; the new height of the $widget.

  • $baseline; the baseline position of the $widget, or -1.

get-layout-child

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

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

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

method get-layout-child ( N-Object() $child --> N-Object )
  • $child; a Gnome::Gtk4::Widget.

Return value; a Gnome::Gtk4::LayoutChild.

get-request-mode

Retrieves the request mode of $manager.

method get-request-mode (--> GtkSizeRequestMode )

Return value; a enumeration GtkSizeRequestMode defined in Gnome::Gtk4::T-enums.

get-widget

Retrieves the Gnome::Gtk4::Widget using the given Gnome::Gtk4::LayoutManager.

method get-widget (--> N-Object )

Return value; a Gnome::Gtk4::Widget.

layout-changed

Queues a resize on the Gnome::Gtk4::Widget using $manager, if any.

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

method layout-changed ( )

measure

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

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

method measure ( N-Object() $widget, GtkOrientation $orientation, Int() $for-size, Array[Int] $minimum, Array[Int] $natural, Array[Int] $minimum-baseline, Array[Int] $natural-baseline )
  • $widget; the Gnome::Gtk4::Widget using $manager.

  • $orientation; the orientation to measure.

  • $for-size; Size for the opposite of $orientation; for instance, if the $orientation is GTK_ORIENTATION_HORIZONTAL, this is the height of the widget; if the $orientation is GTK_ORIENTATION_VERTICAL, this is the width of the widget. This allows to measure the height for the given width, and the width for the given height. Use -1 if the size is not known.

  • $minimum; (transfer ownership: full) the minimum size for the given size and orientation.

  • $natural; (transfer ownership: full) the natural, or preferred size for the given size and orientation.

  • $minimum-baseline; (transfer ownership: full) the baseline position for the minimum size.

  • $natural-baseline; (transfer ownership: full) the baseline position for the natural size.