Objective Toolkit : Chapter 23 Layout Manager Framework : Layout Algorithms
Layout Algorithms
This section describes each of the default layout algorithms provided with the Objective Toolkit Layout Manager component. You can create your own custom layouts, which is addressed in a later section.
Alignment Layout
The Alignment layout aligns a child node relative to the parent alignment node. The child node can be aligned with the left, right, top, bottom, horizontal center, vertical center, or both centers. You can also specify top, left, right, and bottom margins. You can use this layout algorithm as a nested layout.
Figure 162 – Example of the Alignment Layout
Scale Layout
The Scale layout maintains every child with a constant aspect ratio to the parent scale node. In other words, the child node’s top, left, right, and bottom coordinates are stored as percentages of the parent node’s size and are resolved to actual pixel values with each recalculation. This guarantees a constant aspect ratio regardless of the size of the parent node.
Figure 163 – Example of the Scale Layout
Grid Layout
Inspired by the Java Grid Layout, this algorithm allows you to position child nodes in a two-dimensional grid of specific or arbitrary size. You can initialize the grid to a specific two-dimensional matrix, or set it to grow arbitrarily in one direction (rows or columns).
Figure 164 – Example Grid Layout
GridBag Layout
Inspired by the Java GridBag Layout, GridBag supports:
Node spanning of multiple rows or columns or both.
Variable width columns.
Variable height rows.
Variable row/column resize weights that control the rate of change.
Grid cell insets, grid fill modes, and grid cell anchoring.
Figure 165 – Example Gridbag Layout
Relative Layout
The Relative Layout allows a logical organization of layout nodes. You can set constraints with English-like semantics. For example:
“Set the left side of node 1 equal to the right side of node 2 plus 10 pixels.”
“Set the bottom of node 1 to 25 percent of the height of node 2.”
“Move node 1 such that its bottom is equal to the top of node 2 minus 10 pixels.”
This algorithm also guarantees device independent positioning.
Figure 166 – Example Relative Layout