Package: gtk
Class gtk:constraint-layout
Superclassesgtk:layout-manager, gobject:object, common-lisp:standard-object, common-lisp:t Documented Subclasses
None
Direct Slots
None
Details The gtk:constraint-layout object is a layout manager that uses relations between widget attributes, expressed via gtk:constraint
instances, to measure and allocate widgets. How do constraints workBy taking multiple constraints and applying them to the children of a widget using the gtk:constraint-layout object, it is 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 strength property to "nudge" the layout towards a solution. GtkConstraintLayout as GtkBuildableAn example of a UI definition fragment specifying a constraint: <object class="GtkConstraintLayout"> <constraints> <constraint target="button" target-attribute="start" relation="eq" source="super" source-attribute="start" constant="12" strength="required" /> <constraint target="button" target-attribute="width" relation="ge" constant="250" strength="strong" /> </constraints> </object>The definition above will add two constraints to the gtk:constraint-layout object:
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 gtk:constraint-layout object. There can be "constant" and "multiplier" attributes. Additionally, the "constraints" element can also contain a description of the gtk:constraint-guide object used by the layout: <constraints> <guide min-width="100" max-width="500" name="hspace"/> <guide min-height="64" nat-height="128" name="vspace" strength="strong"/> </constraints>The "guide" element has the following optional attributes:
Using the Visual Format LanguageThe 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 gtk:constraint-target object. For instance: [button]-[textField]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: // Width must be greater than, or equal to 50 [button(>=50)]The default orientation for a VFL description is horizontal, unless otherwise specified: // horizontal orientation, default attribute: width H:[button(>=150)]It is also possible to specify multiple predicates, as well as their strength: // minimum width of button must be 150 // natural width of button can be 250 [button(>=150@required, ==250@medium)]Finally, it is also possible to use simple arithmetic operators: // width of button1 must be equal to width of button2 // divided by 2 plus 12 [button1(button2 / 2 + 12)] | Returned byInherited Slot Access FunctionsSee also |
2024-4-23