Layout policy elements

Layout policy elements are descendants of layout items that carry size policy constraints.

A layout item can have one (and only one) layout policy element. A layout item does not have to have any layout policy element (for layout items that do not have any size policy constraints). The layout policy element may be a layout container if the sub-tree of the layout container item has more than one size policy constrained element, or needs a layout container to be laid out. In other words, if several items have a layout policy element, they should have an ascendant that is a container that will collect and re-compute the policy.

The data-g-layout-policy attribute

Table 1. Properties of the data-g-layout-policy attribute
Property Default Value Description
widthHint   A hint for the desired width. See How to specify desired sizes.
widthPolicy All The width policy. See Table 3.
minWidth   The minimum width in pixels. By default, the minimum width is equal to the desired width. To give a specific minimum width, set the minWidth property. See How to specify desired sizes.
heightHint   A hint for the desired height. See How to specify desired sizes.
heightPolicy All The height policy. See Table 3
minHeight   The minimum height in pixels. By default, the minimum height is equal to the desired height. To give a specific minimum height, set the minHeight property. See How to specify desired sizes.
horizontalStretching false Stretch the policy element horizontally so that it fills its parent.
verticalStretching false Stretch the policy element vertically so that it fills its parent.
isScrollView false A value indicating whether the policy-constrained element is also a scroll view.
deferSizing false If true the computing of the desired size by the parent item will be deferred until the InvalidLayout function is called with the value true as the third parameter. Typically used by image widgets for which the computing of the size must be deferred until the image has been loaded.

How to specify desired sizes

Use this format to specify desired sizes for the properties widthHint, and heightHint.
[N['px']]['*']
where:
  • N specifies the number of cells
  • * specifies that you want to add a stretch capacity

The minWidth and minHeight properties expect a number of pixels.

Desired size examples

Table 2. Examples of valid desired size
Example Description
10 Specify a desired size of 10 cells.
* Specify a desired size of zero (0) cells, with a stretch capacity.
7* Specify a desired size of seven (7) cells, with a stretch capacity.
50px Specify a desired size of 50 pixels.
50px* Specify a desired size of 50 pixels, with a stretch capacity.

heightPolicy and widthPolicy properties

Table 3. Possible values for heightPolicy and widthPolicy properties
Value Description
All The size of an element depends on its content only.
AllInitial (the words All + Initial) The size of the element is the size of its initial content.
CanShrink According to its content, the size of the element can shrink compared to the size given by the form definition file.
CanShrinkInitial According to its initial content, the size of the element can shrink compared to the size given by the form definition file.
CanGrow According to its content, the size of the element can grow compared to the size given by the form definition file.
CanGrowInitial According to its initial content, the size of the element can grow compared to the size given by the form definition file.
Fixed The size of the element depends on the size given by the form definition file only.
Container The size of the element is merged with the information provided by the container.

Invalidation of the layout

By default, the layout is invalidated when the markup of the page changes. It may also be invalidated on custom events.

To invalidate a layout:
  • Add a data-g-layout-invalid attribute on an element (server side).
  • Call the GridLayout.invalidLayout(element, refresh, load) function (client side). The GridLayout.invalidLayout function takes 3 parameters:
    • The root element of the subtree to invalidate.
    • A value indicating whether the layout should be refreshed synchronously or asynchronously.
    • A value indicating whether the deferred-loading element has been loaded.
    When the function is called, the second argument is normally false. The third parameter is used by policy-constrained elements that have the deferSizing attribute set to true.Typically, the method should be called as following: GridLayout.invalidLayout(element, false, true)