Sizing custom widgets
A custom widget doesn’t size itself. The Grid layout
puts each of its children in a cell, and the cell applies the child’s size. Your widget fills
its cell, so its render code doesn’t need to read templateData.size.
gui.layouts.horizontalGrid([ gui.inputs.custom('productRating', 'rating', { size: 1 }), gui.actions.custom('productShare', { size: 2, onClick: () => 'shareEvent' }),]);{ "kind": "layout", "type": "grid", "props": { "direction": "row" }, "children": [ { "kind": "input", "type": "productRating", "path": "rating", "props": { "size": 1 } }, { "kind": "action", "type": "productShare", "props": { "size": 2 }, "on": { "click": "shareEvent" } } ]}Here, the rating widget takes one part of the row and the share widget two.
Where size applies
Section titled “Where size applies”size applies to custom and built-in widgets alike:
- In a row (
direction: 'row'), the children share the width by theirsize. - In numbered columns (
columns: 3, for example), a child spanssizecolumns. - In a stack, in
columns: 'auto'and in a row with ajustify, it has no effect: each child takes the full width, one column, or its own width.
Line up with the fields beside it
Section titled “Line up with the fields beside it”In a row or in columns, the grid lines up the label, the control and the errors of each field with
those of its neighbors. A custom input joins in when its root element has the gui-field class
and its parts have these classes:
<div class="product-rating gui-field"> <label class="gui-label">Rating</label> <div class="gui-widget"><!-- the stars --></div> <div class="gui-validator"><!-- the errors --></div></div>Without them, the widget spans the label, control and error tracks of its row from the top, as a nested layout does. GolemUI Components’ Grid page explains the tracks.
Upgrading from 1.x
Section titled “Upgrading from 1.x”In 1.x, every custom widget set an inline flex style from templateData.size, because the Flex
layout sized its children that way. Remove that code: the
migration guide shows it for each framework.
See also
Section titled “See also”- Grid layout: rows, columns and
size. - Custom Widgets Overview: the full Product Card example.