Class: Gtk::ConstraintLayout

Inherits:
LayoutManager show all
Defined in:
(unknown)

Instance Method Summary collapse

Methods inherited from LayoutManager

#allocate, #get_layout_child, #layout_changed, #measure, #request_mode, #widget

Constructor Details

#initializeGtk::LayoutManager

Creates a new GtkConstraintLayout layout manager.

Instance Method Details

#add_constraint(constraint) ⇒ nil

Adds a constraint to the layout manager.

The [propertyGtk.Constraint:source] and [propertyGtk.Constraint:target] properties of constraint can be:

  • set to NULL to indicate that the constraint refers to the widget using layout
  • set to the [classGtk.Widget] using layout
  • set to a child of the [classGtk.Widget] using layout
  • set to a [classGtk.ConstraintGuide] that is part of layout

The layout acquires the ownership of constraint after calling this function.

Parameters:

Returns:

  • (nil)

#add_constraints_from_description(lines, n_lines, hspacing, vspacing, error, first_view, array) ⇒ GLib::List<Gtk::Constraint>

Creates a list of constraints from a VFL description.

This function is a convenience wrapper around [methodGtk.ConstraintLayout.add_constraints_from_descriptionv], using variadic arguments to populate the view/target map.

Parameters:

  • lines (Array<String>)

    an array of Visual Format Language lines defining a set of constraints

  • n_lines (Integer)

    the number of lines

  • hspacing (Integer)

    default horizontal spacing value, or -1 for the fallback value

  • vspacing (Integer)

    default vertical spacing value, or -1 for the fallback value

  • error (GLib::Error)

    return location for a GError

  • first_view (String)

    the name of a view in the VFL description, followed by the [ifaceGtk.ConstraintTarget] to which it maps

  • array (Array)

    a NULL-terminated list of view names and [ifaceGtk.ConstraintTarget]s

Returns:

  • (GLib::List<Gtk::Constraint>)

    the list of [classGtk.Constraint]s that were added to the layout

#add_constraints_from_descriptionv(lines, n_lines, hspacing, vspacing, views) ⇒ GLib::List<Gtk::Constraint>

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 [ifaceGtk.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(100<b>strong</b>)]

  // 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:

  • lines (Array<String>)

    an array of Visual Format Language lines defining a set of constraints

  • n_lines (Integer)

    the number of lines

  • hspacing (Integer)

    default horizontal spacing value, or -1 for the fallback value

  • vspacing (Integer)

    default vertical spacing value, or -1 for the fallback value

  • views (GLib::HashTable<String>)

    a 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 GtkConstraintLayout, or guides

Returns:

  • (GLib::List<Gtk::Constraint>)

    the list of [classGtk.Constraint] instances that were added to the layout

#add_guide(guide) ⇒ nil

Adds a guide to layout.

A guide can be used as the source or target of constraints, like a widget, but it is not visible.

The layout acquires the ownership of guide after calling this function.

Parameters:

Returns:

  • (nil)

#observe_constraintsGio::ListModel

Returns a GListModel to track the constraints that are part of the layout.

Calling this function will enable extra internal bookkeeping to track constraints and emit signals on the returned listmodel. It may slow down operations a lot.

Applications should try hard to avoid calling this function because of the slowdowns.

Returns:

  • (Gio::ListModel)

    a GListModel tracking the layout's constraints

#observe_guidesGio::ListModel

Returns a GListModel to track the guides that are part of the layout.

Calling this function will enable extra internal bookkeeping to track guides and emit signals on the returned listmodel. It may slow down operations a lot.

Applications should try hard to avoid calling this function because of the slowdowns.

Returns:

  • (Gio::ListModel)

    a GListModel tracking the layout's guides

#remove_all_constraintsnil

Removes all constraints from the layout manager.

Returns:

  • (nil)

#remove_constraint(constraint) ⇒ nil

Removes constraint from the layout manager, so that it no longer influences the layout.

Parameters:

Returns:

  • (nil)

#remove_guide(guide) ⇒ nil

Removes guide from the layout manager, so that it no longer influences the layout.

Parameters:

Returns:

  • (nil)