ConstraintLayout.addConstraintsFromDescription

gtk.constraint.Constraint[] addConstraintsFromDescription(string[] lines, int hspacing, int vspacing, gtk.constraint_target.ConstraintTarget[string] views)

Creates a list of constraints from a VFL description.

The Visual Format Language, VFL, is based on Apple's AutoLayout VFL.

The views dictionary is used to match [gtk.constraint_target.ConstraintTarget] instances to the symbolic view name inside the VFL.

The VFL grammar is:

<visualFormatString> = (<orientation>)?
                             (<superview><connection>)?
                             <view>(<connection><view>)*
                             (<connection><superview>)?
             <orientation> = 'H' | 'V'
               <superview> = '|'
              <connection> = '' | '-' <predicateList> '-' | '-'
           <predicateList> = <simplePredicate> | <predicateListWithParens>
         <simplePredicate> = <metricName> | <positiveNumber>
 <predicateListWithParens> = '(' <predicate> (',' <predicate>)* ')'
               <predicate> = (<relation>)? <objectOfPredicate> (<operatorList>)? ('@' <priority>)?
                <relation> = '==' | '<=' | '>='
       <objectOfPredicate> = <constant> | <viewName> | ('.' <attributeName>)?
                <priority> = <positiveNumber> | 'required' | 'strong' | 'medium' | 'weak'
                <constant> = <number>
            <operatorList> = (<multiplyOperator>)? (<addOperator>)?
        <multiplyOperator> = [ '*' | '/' ] <positiveNumber>
             <addOperator> = [ '+' | '-' ] <positiveNumber>
                <viewName> = [A-Za-z_]([A-Za-z0-9_]*) // A C identifier
              <metricName> = [A-Za-z_]([A-Za-z0-9_]*) // A C identifier
           <attributeName> = 'top' | 'bottom' | 'left' | 'right' | 'width' | 'height' |
                             'start' | 'end' | 'centerX' | 'centerY' | 'baseline'
          <positiveNumber> // A positive real number parseable by g_ascii_strtod()
                  <number> // A real number parseable by g_ascii_strtod()

Note: The VFL grammar used by GTK is slightly different than the one

defined by Apple, as it can use symbolic values for the constraint's strength instead of numeric values; additionally, GTK allows adding simple arithmetic operations inside predicates.

Examples of VFL descriptions are:

// Default spacing
 [button]-[textField]

 // Width constraint
 [button(>=50)]

 // Connection to super view
 |-50-[purpleBox]-50-|

 // Vertical layout
 V:[topField]-10-[bottomField]

 // Flush views
 [maroonView][blueView]

 // Priority
 [button(100strong)]

 // Equal widths
 [button1(==button2)]

 // Multiple predicates
 [flexibleButton(>=70,<=100)]

 // A complete line of layout
 |-[find]-[findNext]-[findField(>=20)]-|

 // Operators
 [button1(button2 / 3 + 50)]

 // Named attributes
 [button1(==button2.height)]

Parameters

linesan array of Visual Format Language lines defining a set of constraints
hspacingdefault horizontal spacing value, or -1 for the fallback value
vspacingdefault vertical spacing value, or -1 for the fallback value
viewsa dictionary of [ name, target ] pairs; the name keys map to the view names in the VFL lines, while the target values map to children of the widget using a [gtk.constraint_layout.ConstraintLayout], or guides

Returns

the list of

[gtk.constraint.Constraint] instances that were added to the layout

Throws

[ErrorWrap]