Grid Layout
SmartUI Grid Layout Behavior operation and ACEs.
Rows and columns can have different width and height, set the properties: Cols Width, and Rows Height. See Changing Columns and Rows Size
Properties
Layouter Mode
Layouter mode provides a quick arrangement of static objects in the scene. By static, we mean all the existing objects in the scene that are children of the Grid Layout container. Layouter is the default mode for the Grid Layout component.
By simply linking the child objects in the scene, the Grid Layout component will automatically identify what’s in its hierarchy and the grid configuration to arrange them instantly after the layout is created.
By design, Layouter's mode main purpose is to quickly arrange objects in a scene without the need to handle additional data sources, not to render dynamic data. For that purpose, see Renderer mode.
Grid Layouter will use the Document Flow determine the order of the components. Objects are handled in a list data structure, and their indexes are automatically mapped against the grid to render them in the correct cell."
Each object in the hierarchy is iterated. If the grid determines that it doesn’t use any of the SmartUI behaviors, the sequence index is omitted, and the object’s position becomes the only relevant attribute to determine the order.
Any world object can become a cell of the grid; you are not restricted to using only the Smart UI behaviors.
After running the scene, the objects are arranged as show below:
Notice how the content of each cell does not match the size of the Grid Layout object. This is because, by default, the layouter will render the objects' original size in the layout you are designing. You can change the Scale Mode property of the Grid Layout from None to either fit the cell size or stretch the content to match the cell size.
Changing Columns and Rows Size
Grid Layout supports multiple sizes for rows and columns. To change them, set the Cols Width and Rows Height properties. The input for those attributes is a list of values between 0 and 1, where 1 represents 100% of either the width or height of the Grid Layout's size.
For instance, if you have a 4x4 grid and want to add a titles row at the top, and also set the first column to contain a numeric ID, you can achieve this by keeping in mind the document flow logic to semi-arrange your objects in the layout. Your scene might look like the following to set up your Grid Layout.
Notice how the rows and columns have an approximate location, but are not quite precise, and that's perfectly fine. We are taking advantage of how the Document Flow iterates the objects in the scene.
The next step is to set up the width and height sizes as follows:
The sum of the values for the rows height and columns width properties must be 1. If the sum is above 1, the values will be normalized, and the Grid Layout component will try to fit them within its rendering area
According to the image, we’ve indicated that the first column is 10% of the total width of the Grid Layout. Rows will follow the same structure, so the first row will also have 10% of the Grid Layout's height.
If you fail to enter a value for either a column width or a row height in their respective lists, the component will default to an approximate even distribution of sizes for all the cells.
Layouter also supports dynamic insertion of objects; nevertheless, keep in mind that objects are still treated as a list but displayed in a grid arrangement. Therefore, if you add an object to a cell, all subsequent objects will be pushed down in the list, causing the grid to recalculate their positions using the Document Flow.
Renderer Mode
Renderer mode is designed to handle dynamic data and object creation based on a Grid Renderer Configuration File. The file can be imported into the Grid Layout component by calling the Set Datasource
action, which takes a JSON
object as input. The rendering features used by Layouter mode are still valid for Renderer mode.
Construct already provides AJAX
, JSON
, and file management capabilities. For this reason, the plugin considers the input throught the existing built-in plugins.
The action Set Datasource
reads the JSON
data, and creates a copy that is later stored in the Grid Layout component for rendering.
If you change by any mean the JSON plugin data, you must then call the Set Datasource
action again and refresh the Grid Layout to render the information.
Data-change listeners attached to construct objects are not supported, primarily because construct does not have event triggers to attach these listeners to. Therefore, the data flow to the Grid Layout remains manual.
Grid Renderer Configuration File
The configuration file has two main keys in its structure: data
and meta-data
. Both keys have a 1-to-1 cardinality, meaning there should be the same number of entries.
data
(mandatory) key holds an array of objects containing the information you want to flow from the Grid Layout object to each cell.meta-data
(mandatory) key describes how each cell should be rendered, allowing you to combine multiple different objects in the same grid.default-object
(mandatory) key describes the object to render by default when there is no matching record between thedata
andmeta-data
arrays. This feature is useful in scenarios where you want to render the same object for all data rows. In such cases, theobject-list
key can be an empty array ([]
).object-name
(mandatory) key describes the world-instance object that should be created.create-hierarchy
(mandatory) key indicates whether the object is created alone or with all its children.template
(mandatory) is applicable only ifcreate-hierarchy
is set to true. The instances will use the provided hierarchy template to create the instance.
object-list
(mandatory) key contains an array of objects. Its cardinality must be 1-to-1 with thedata
. However, you can still passnull
values for each row. When the grid is rendering, if themeta-data
row is either not found or null, the object to render will default to what is indicated in thedefault-object
key. Each entry in this array has the same structure as thedefault-object
key.
Rendering Objects
Renderer mode, by default, destroys any children in the hierarchy and then takes the information from the configuration file. Objects will render automatically once the datasource is assigned. In contrast to Layouter mode, objects do not have to be children of the Grid Layout because they are created at runtime.
All children attributes (x, y, width, height, etc.) are transformed whenever the parent object changes.
You can customize the way you render the data source
by adjusting any of the Grid Layout attributes.
The component supports paging and a set of ACEs (Actions, Commands, and Events) to navigate between the pages created for the data. To enable paging, set the paging attribute to enabled
and specify the total number of items to render per page.
Every time a cell is rendered, the information from the data
field is passed to the data listener. To access it, use the expression Value
followed by the name of the key you want to retrieve.
On Render is called just once per cell.
The DataListener behavior must be attached to the top-level object being rendered.
Using the configuration file example, we can render the contact information of a phone list in a Grid Layout component.
The event sheet might look like below:
The MyBoxData has a child Text plugin attached to it, whenever the MyBoxData On Render event is called, the child Text plugin is picked and its value is then set from the DataListener.Value
expression.
Smart UI Grid-Layout behavior groups UI components, provides focusing abilities and default interactions to navigate within the Grid-Layout and its children components that uses Smart UI behaviors, and handles cascading Enabling/Disabling events. It also responds to pointer interactions prioritizing by zIndex. https://smartui-docs.pixelperfectstudio.mx/
Actions
Set Enabled
Set Enabled
Disable/Enable the Grid-Layout
Set Name
Set Name
Sets the name of the Grid-Layout.
Set Sequence
Set Sequence
Sets the sequence index to influence the selection of components.
Set Focusable
Set Focusable
Sets the component to be able to receive the focus
Set Focus
Set Focus
Request the focus for this Grid-Layout
Focus First Element
Focus First Element
Request the focus for the first interactable element of the Grid-Layout.
Focus Last Element
Focus Last Element
Request the focus for the last interactable element of the Grid-Layout.
Set Invisible Component
Set Invisible Component
Sets whether the component should be processed when it's invisible. Opacity is not taken in consideration.It doesn't affect the visibility attribute of the object, you are responsible of turning it visible or invisible when needed.
Refresh
Refresh
Refreshes the layout, and arranges all the children in their corresponding cells. On Layouter mode, the grid-layout will try to determine the objects position sequentially. On Renderer mode, it will read all the entries from the datasource to render them in sequence.
Set Datasource
Set Datasource
Sets the JSON plugin object that will provide the information to render the grid.
Set Columns
Set Columns
Sets the number of columns the grid will render.
Set Rows
Set Rows
Sets the number of rows the grid will render.
Set Column Padding
Set Column Padding
Sets padding between columns.
Set Row Padding
Set Row Padding
Sets padding between rows.
Set Scaling
Set Scaling
Sets the type of scaling the grid-layout will perform over all its content.
Insert At
Insert At
In Layouter mode, inserts an object in the specified column and row, displacing the following components on cell.
Set Page
Set Page
In Renderer mode, changes the page. Page numberes are zero-index based.
Set Items per Page
Set Items per Page
Sets the total number of items to render per page.
Next Page
Next Page
Switches to the next page available.
Previous Page
Previous Page
Switches to the previous page available.
Conditions
Is Enabled
Is Enabled
Returns true if the Grid-Layout is enabled
Is Invisible Component
Is Invisible Component
Returns true if the Grid-Layout is configured as an invisible component.
Compare Name
Compare Name
Returns true if the component's name equals the parameter
Is Focused
Is Focused
Returns true if the Grid-Layout has the focus
Has Control
Has Control
True if the Grid-Layout has the control to navigate over components.
On Focus
On Focus
Triggered when the Grid-Layout gets the focus
On Focus Lost
On Focus Lost
Triggered when the Grid-Layout loses focus
Expressions
Name
Name
Component name
Columns
Columns
Total Columns
Rows
Rows
Total rows
ColumnPadding
ColumnPadding
Column padding
RowPadding
RowPadding
Component name
CellHeight
CellHeight
Cell's height of the given coordinates (column,row)
CellWidth
CellWidth
Cell's width of the given coordinates (column,row)
Page
Page
Current Page
MaxPages
MaxPages
Maximum Pages
(c) Pixel Perfect Studio 2024
Last updated