Sets our main struct and passes it to the parent class.
Creates a new GtkConstraintLayout layout manager.
Adds a constraint to the layout manager.
Creates a list of constraints from a VFL description.
Adds a guide to layout.
Get the main Gtk struct
the main Gtk struct as a void*
Returns a GListModel to track the constraints that are part of the layout.
Returns a GListModel to track the guides that are part of the layout.
Removes all constraints from the layout manager.
Removes constraint from the layout manager, so that it no longer influences the layout.
Removes guide from the layout manager, so that it no longer influences the layout.
the main Gtk struct
the main Gtk struct
Get the main Gtk struct
the main Gtk struct as a void*
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.
Retrieves a GtkLayoutChild instance for the GtkLayoutManager, creating one if necessary.
Retrieves the request mode of @manager.
Retrieves the GtkWidget using the given GtkLayoutManager.
Queues a resize on the GtkWidget using @manager, if any.
Measures the size of the @widget using @manager, for the given @orientation and size.
Get the main Gtk struct
the main Gtk struct as a void*
Gets the ID of the @buildable object.
A layout manager using constraints to describe relations between widgets.
GtkConstraintLayout is a layout manager that uses relations between widget attributes, expressed via [class@Gtk.Constraint] instances, to measure and allocate widgets.
How do constraints work
Constraints are objects defining the relationship between attributes of a widget; you can read the description of the [class@Gtk.Constraint] class to have a more in depth definition.
By taking multiple constraints and applying them to the children of a widget using GtkConstraintLayout, it's possible to describe complex layout policies; each constraint applied to a child or to the parent widgets contributes to the full description of the layout, in terms of parameters for resolving the value of each attribute.
It is important to note that a layout is defined by the totality of constraints; removing a child, or a constraint, from an existing layout without changing the remaining constraints may result in an unstable or unsolvable layout.
Constraints have an implicit "reading order"; you should start describing each edge of each child, as well as their relationship with the parent container, from the top left (or top right, in RTL languages), horizontally first, and then vertically.
A constraint-based layout with too few constraints can become "unstable", that is: have more than one solution. The behavior of an unstable layout is undefined.
A constraint-based layout with conflicting constraints may be unsolvable, and lead to an unstable layout. You can use the [property@Gtk.Constraint:strength] property of [class@Gtk.Constraint] to "nudge" the layout towards a solution.
GtkConstraintLayout as GtkBuildable
GtkConstraintLayout implements the [iface@Gtk.Buildable] interface and has a custom "constraints" element which allows describing constraints in a [class@Gtk.Builder] UI file.
An example of a UI definition fragment specifying a constraint:
The definition above will add two constraints to the GtkConstraintLayout:
- a required constraint between the leading edge of "button" and the leading edge of the widget using the constraint layout, plus 12 pixels - a strong, constant constraint making the width of "button" greater than, or equal to 250 pixels
The "target" and "target-attribute" attributes are required.
The "source" and "source-attribute" attributes of the "constraint" element are optional; if they are not specified, the constraint is assumed to be a constant.
The "relation" attribute is optional; if not specified, the constraint is assumed to be an equality.
The "strength" attribute is optional; if not specified, the constraint is assumed to be required.
The "source" and "target" attributes can be set to "super" to indicate that the constraint target is the widget using the GtkConstraintLayout.
There can be "constant" and "multiplier" attributes.
Additionally, the "constraints" element can also contain a description of the #GtkConstraintGuides used by the layout:
The "guide" element has the following optional attributes:
- "min-width", "nat-width", and "max-width", describe the minimum, natural, and maximum width of the guide, respectively - "min-height", "nat-height", and "max-height", describe the minimum, natural, and maximum height of the guide, respectively - "strength" describes the strength of the constraint on the natural size of the guide; if not specified, the constraint is assumed to have a medium strength - "name" describes a name for the guide, useful when debugging
Using the Visual Format Language
Complex constraints can be described using a compact syntax called VFL, or *Visual Format Language*.
The Visual Format Language describes all the constraints on a row or column, typically starting from the leading edge towards the trailing one. Each element of the layout is composed by "views", which identify a [iface@Gtk.ConstraintTarget].
For instance:
Describes a constraint that binds the trailing edge of "button" to the leading edge of "textField", leaving a default space between the two.
Using VFL is also possible to specify predicates that describe constraints on attributes like width and height:
The default orientation for a VFL description is horizontal, unless otherwise specified:
It's also possible to specify multiple predicates, as well as their strength:
Finally, it's also possible to use simple arithmetic operators: