LayoutManager#
Superclasses: Object
Subclasses: BinLayout, BoxLayout, CenterLayout, ConstraintLayout, CustomLayout, FixedLayout, GridLayout, OverlayLayout
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 set_layout_manager.
Layout properties#
A layout manager can expose properties for controlling the layout of
each child, by creating an object type derived from 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 get_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:
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 layout_manager and
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
get_layout_child every time it needs to query
the layout properties; each GtkLayoutChild instance should call
layout_changed every time a property is
updated, in order to queue a new size measuring and allocation.
Methods#
- class LayoutManager
- allocate(widget: Widget, width: int, height: int, baseline: int) None#
Assigns the given
width,height, andbaselineto awidget, and computes the position and sizes of the children of thewidgetusing the layout management policy ofmanager.- Parameters:
widget – the
GtkWidgetusingmanagerwidth – the new width of the
widgetheight – the new height of the
widgetbaseline – the baseline position of the
widget, or -1
- do_allocate(self, widget: Widget, width: int, height: int, baseline: int) None#
- Parameters:
widget
width
height
baseline
- do_create_layout_child(self, widget: Widget, for_child: Widget) LayoutChild#
- Parameters:
widget
for_child
- do_get_request_mode(self, widget: Widget) SizeRequestMode#
- Parameters:
widget
- do_measure(self, widget: Widget, orientation: Orientation, for_size: int) tuple[int, int, int, int]#
- Parameters:
widget
orientation
for_size
- get_layout_child(child: Widget) LayoutChild#
Retrieves a
GtkLayoutChildinstance for theGtkLayoutManager, creating one if necessary.The
childwidget must be a child of the widget usingmanager.The
GtkLayoutChildinstance is owned by theGtkLayoutManager, and is guaranteed to exist as long aschildis a child of theGtkWidgetusing the givenGtkLayoutManager.- Parameters:
child – a
GtkWidget
- get_request_mode() SizeRequestMode#
Retrieves the request mode of
manager.
- layout_changed() None#
Queues a resize on the
GtkWidgetusingmanager, if any.This function should be called by subclasses of
GtkLayoutManagerin response to changes to their layout management policies.
- measure(widget: Widget, orientation: Orientation, for_size: int) tuple[int, int, int, int]#
Measures the size of the
widgetusingmanager, for the givenorientationand size.See the
Widgetdocumentation on layout management for more details.- Parameters:
widget – the
GtkWidgetusingmanagerorientation – the orientation to measure
for_size – Size for the opposite of
orientation; for instance, if theorientationisHORIZONTAL, this is the height of the widget; if theorientationisVERTICAL, 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
Virtual Methods#
- class LayoutManager
- do_allocate(widget: Widget, width: int, height: int, baseline: int) None#
Assigns the given
width,height, andbaselineto awidget, and computes the position and sizes of the children of thewidgetusing the layout management policy ofmanager.- Parameters:
widget – the
GtkWidgetusingmanagerwidth – the new width of the
widgetheight – the new height of the
widgetbaseline – the baseline position of the
widget, or -1
- do_create_layout_child(widget: Widget, for_child: Widget) LayoutChild#
The type of the None singleton.
- Parameters:
widget – the widget using the
managerfor_child – the child of
widget
- do_get_request_mode(widget: Widget) SizeRequestMode#
- a virtual function, used to return the preferred
request mode for the layout manager; for instance, “width for height” or “height for width”; see
GtkSizeRequestMode
- Parameters:
widget
- do_measure(widget: Widget, orientation: Orientation, for_size: int) tuple[int, int, int, int]#
Measures the size of the
widgetusingmanager, for the givenorientationand size.See the
Widgetdocumentation on layout management for more details.- Parameters:
widget – the
GtkWidgetusingmanagerorientation – the orientation to measure
for_size – Size for the opposite of
orientation; for instance, if theorientationisHORIZONTAL, this is the height of the widget; if theorientationisVERTICAL, 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
Fields#
- class LayoutManager
- parent_instance#