|
|
The layout class is used to arrange items on a web page. Given a set of items as its vector fields, it arranges them in an order depending on the attribute values. The content of a layout is the set of objects which are to be arranged. These may consist of biz, ui_view, or hypertext objects, or any other object which can be represented in html. (Objects other than a biz or ui_view will be wrapped in a ui_view for purposes of positioning.) A layout may also contain other layouts.
The layout arranges hierarchies as well as flat lists of items: when presented with a hierarchical set of items to arrange, it will first arrange an item, then arrange its children recursively, then return to arrange the next item on the level of the parent. This is accomplished by using an additional layout object which arranges the children, which is called by the layout of the parent. Thus, complex arrangements may be created by using a different subclass of layout for the children than the parent. A typical use case for layout of hierarchical content would be items in a menu.
The layout class assumes that the programmer will provide sufficient input to generate a useful result, but doesn't require any attributes:
<layout> <p>One</p> <p>Two</p> <p>Three</p> </layout>
Technically, this will generate valid HTML. However, what it will actually do is lay out the three paragraphs on top of each other and shove them in the upper left corner of the page. (It isn't pretty.) In order to get useful functionality, the layout must have an origin, and some properties that cause it to make things not appear on top of each other.
If we want to arrange these three items in a row, we could specify that we want to add the width of the items to the x_spacer, which is the space between objects horizontally. This would cause each object to be positioned to the right of its predecessor, as follows:
<layout add_width_to_x_spacer=true> <p>One</p> <p>Two</p> <p>Three</p> </layout>This returns a nice neat row looking something like this:
| One | Two | Three |
An easier method for doing this would be to use the row subclass:
layout.<row> <p>One</p> <p>Two</p> <p>Three</p> </row>
This would yield the same result. Indeed, all the row subclass does is set different default values for the standard layout engine.
If we want to arrange these three items in a column, we could specify that we want to add the height of the items to the y_spacer, which is the space between objects vertically. This would cause each object to be positioned below its predecessor, as follows:
<layout add_height_to_y_spacer=true> <p>One</p> <p>Two</p> <p>Three</p> </layout>This returns a nice neat column looking something like this:
One
Two
three
An easier method for doing this would be to use the column subclass:
layout.<column> <p>One</p> <p>Two</p> <p>Three</p> </column>
As before, this would yield the same result.
Objects of class biz accept an optional layout as their _layout attribute. The biz object contains
method <arrange/> which synchronizes the content of the biz object with the content of its layout object, and
then calls the <arrange/> method on its layout object. See the biz documentation for further details.
biz.menu functionality works.
biz.<menu _layout=layout.<row/> >
biz.<menu_item label="A1" task=<echo "You clicked A1"/> >
biz.<menu_item label="B1" task=<echo "You clicked B1"/> />
biz.<menu_item label="B2" task=<echo "You clicked B2"/> >
biz.<menu_item label="C1" task=<echo "You clicked C1"/> />
</menu_item>
biz.<menu_item label="B3" task=<echo "You clicked B3"/> />
</menu_item>
biz.<menu_item label="A2" task=<echo "You clicked A2"/> />
</menu>
layout.row and passed it to a biz.menu object. The biz.menu object will pass
its vector content to the layout to be arranged.
Items are arranged in order from first to last in the order in which they are listed in the vector keys, so the first item listed will appear in the upper left. The origin is the x,y location on the page at which the upper left corner of the arranged items will appear.
The origin can be set manually using the origin_x and origin_y attributes. However, this isn't always necessary. If the first item (.0) of an instance of layout is a ui_view or a biz, and it has an x,y location already, the layout will use that x,y if origin_x and origin_y are not set. (If they are set, .0 will not be searched for coordinates.) Also, this may be overriden by passing origin_x and origin_y attributes to the arrange method.
| Parameter key | Default value | Type |
| origin_x | opt | number |
| Parameter key | Default value | Type |
| origin_y | opt | number |
Width and height are required for the items to be arranged. Because of this, if an item to be arranged does not have width and height, they will be set for it. If the item does not have a container such as a ui_view object to contain its width and height, one will be created for it. You may also optionally force all arranged objects to have the same size.
| Parameter key | Default value | Type |
| item_width | 100 | number |
| Parameter key | Default value | Type |
| item_height | 100 | number |
| Parameter key | Default value | Type |
| force_item_size | false | boolean |
When the layout arranges its objects, it places the first object at the origin x,y, and each successive object's location is determined in relation to the location of its predecessor.
| Parameter key | Default value | Type |
| x_spacer | 0 | number |
| Parameter key | Default value | Type |
| y_spacer | 0 | number |
| Parameter key | Default value | Type |
| add_width_to_x_spacer | false | boolean |
| Parameter key | Default value | Type |
| add_height_to_y_spacer | false | boolean |
When the layout prepares to arrange child objects, it determines the origin of the child set in relation to the parent object of the child set. For example, if a layout is arranging objects A, B, and C, and item B has two children B1 and B2, when the layout of A, B, and C attempts to call the layout of B1 and B2 to arrange them, the origin of the layout of B1 and B2 will be determined as an offset from the x,y coordinates of B.
| Parameter key | Default value | Type |
| x_offset | 0 | number |
| Parameter key | Default value | Type |
| y_offset | 0 | number |
| Parameter key | Default value | Type |
| add_width_to_x_offset | false | boolean |
| Parameter key | Default value | Type |
| add_height_to_y_offset | false | boolean |
© Copyright 2007 Clear Methods, Inc.