Class: HtmlLayout
- Package: saf.GUI
- Author: John Luxford <lux@simian.ca>
- Copyright: Copyright (C) 2001-2003, Simian Systems Inc.
- License: http://www.sitellite.org/index/license Simian Open Software License
- Version: 1.2, 2002-08-18, $Id: Layout.php,v 1.4 2007/10/06 00:06:30 lux Exp $
- Access: public
HtmlLayout is an editable grid layout system using HTML tables, allowing
for more complex GUIs to be developed more easily or at least in a more
automated fashion.
Note: Always reads from top-down *then* left to right. Take for example the
following 3 x 3 grid:
<pre>
a1 | b1 | c1
----+----+----
a2 | b2 | c2
----+----+----
a3 | b3 | c3
</pre>
This grid can also be expressed as:
<pre>
0,0 | 1,0 | 2,0
-----+-----+-----
0,1 | 1,1 | 2,1
-----+-----+-----
0,2 | 1,2 | 2,2
</pre>
This would read a1, a2, a3, b1, b2, b3, etc. Be mindful of this when looping.
Also of note when referring to cells is that you can refer to them in two
different ways. The 'a1' notation is acceptable, and you can also pass an array
of two values containing the column (x) and row (y) position of the cell. Please
note that the first notation starts at 'a' and '1', but the second way starts at
(0, 0). You can use the translate() method to convert between the two.
Also note that there is a cell limit of 701 cols (from a to zz), regardless of
which way you refer to them. This is probably way more than you should ever
need anyway. However, should you need more columns, you can use the sub()
method to create sub-layouts inside any cell for practically unlimited depth.
There is no limit on the number of rows available.
New in 1.2:
- Fixed a bug in the render() output that was causing some cells not to appear.
- Increased the column limit from 26 to 701.
Usage Example
<?php
$layout = new HtmlLayout (3, 3);
// assign a template to cell a1
$layout->assign ('a1', 'test test test');
// assign a template to c3
$layout->assign ('c3', 'foo bar');
// create a sub-layout in b2
$b2 =& $layout->sub ('b2');
// expand b2 one down
$layout->spanRows ('b2', 2);
// expand a1 two across
$layout->spanCols ('a1', 3);
// set some table properties
$layout->set ('table', 'border', '1');
$layout->set ('table', 'width', '50%');
$layout->set ('table', 'height', '50%');
$layout->set ('table', 'cellspacing', '2');
$layout->set ('table', 'cellpadding', '2');
// assign b2 (the sub-layout)'s a1 cell a template
$b2->assign ('a1', 'qwerty');
// render
echo $layout->render ();
?>
Properties
$template
- Access: public
The template to use to generate the menu item.
$fill
- Access: public
The object or associative array to use to fill the template with upon
calling render().
$span
- Access: public
The span of this cell. Set to -1 and the cell will disappear. Use
$this->attrs['colspan'] or ['rowspan'] to set these properties in the
corresponding HTML <td> tag.
$attrs = array ()
- Access: public
Contains all HTML <td> properties for the current object.
$default
- Access: public
$default is an optional default value to place in cells whose
templates result in no output.
$type = 'db'
$collection
$limit
$fields
$total = 0
$list = false
$remember = array ()
$skipHeaders = array ()
$header = ''
$footer = ''
$editUrl = false
$addUrl = false
$deleteUrl = false
$error
$name
- Access: public
The name of the menu.
$xpos
- Access: public
The x position of the drop menu this item is a part of. Used for
inheriting to a child menu.
$ypos
- Access: public
The y position of the drop menu this item is a part of. Used for
inheriting to a child menu.
$menuWidth
- Access: public
The width of the drop menu this item is a part of. Used for
inheriting to a child menu.
$lineHeight
- Access: public
The height of this item and each item in its parent drop menu.
Used for inheriting to a child menu.
$itemTemplate
- Access: public
The template used to draw each drop menu item.
$direction = 'right'
- Access: public
The direction of the drop menu this item is a part of. Used for
inheriting to a child menu.
$items = array ()
- Access: public
An array of DropMenuItem objects
$extraMouseOver = ''
- Access: public
Optional extra JavaScript to call when the item is in focus.
$extraMouseOut = ''
- Access: public
Optional extra JavaScript to call when the item loses focus.
$text
- Access: public
The text of the menu item.
$link
- Access: public
The URL to link this item to.
$menu_tpl
- Access: public
The menu template to use to generate child drop menus.
$child
- Access: public
The child DropMenu object of this item.
$mouseover
- Access: private
The private mouseover data detailing this item's behaviour.
$matrix = array ()
- Access: public
Contains the grid.
$table = array ()
- Access: public
Contains all HTML <table> properties for the current object.
$row = array ()
- Access: public
Contains all HTML <tr> properties for the current object.
$cell = array ()
- Access: public
Contains all HTML <td> properties for the current object,
if this layout is not the top-level layout object.
Methods
HtmlLayout ($x = 1, $y = 1)
- Access: public
Constructor method.
assign ($part, $template)
- Access: public
Assigns a template to the specified child HtmlCell object.
$part may be either a string of the format 'a1', or an array with
two numeric values denoting the cell's x and y position.
append ($part, $template)
- Access: public
Appends more to the template of the specified child HtmlCell
object. $part may be either a string of the format 'a1', or an
array with two numeric values denoting the cell's x and y position.
addCol ()
- Access: public
Increases the number of columns by 1.
addRow ()
- Access: public
Increases the number of rows by 1.
set ($part, $property, $value)
- Access: public
Increases the number of columns by 1. Note that $part may be either
'table', 'row', or 'cell' to refer to internal properties, or 'a1, a2, etc'
or an array of x and y to refer to pass the property/value pair on to the
set() method of individual cells.
col ($num = 0)
- Access: public
- Return: array
Returns the specified column as an array of cells.
row ($num = 0)
- Access: public
- Return: array
Returns the specified row as an array of cells.
walk ()
- Access: public
- Return: array
Returns the entire grid as an array of cells, going
top-to-bottom, then left-to-right.
&sub ($x, $xx = 1, $yy = 1)
- Access: public
- Return: reference
Create and return a sub HtmlLayout object in the
specified cell. The number of columns and rows for the
sub-layout can be specified in $xx as an array, or in $xx
and $yy. $x is the position of the cell to put the sub-
layout in, in either method of notation.
render ($td = 0)
- Access: public
- Return: string
Renders this layout and all of its cells as well.
$td is set to 1 automatically if the layout is a sub-layout
of the top-most layout, otherwise you shouldn't need to change
it at all.
spanRows ($part, $num = 1)
- Access: public
Sets the rowspan on the specified cell, and set the cells that
would be in the way to false. $num is the rowspan.
spanCols ($part, $num = 1)
- Access: public
Sets the colspan on the specified cell, and set the cells that
would be in the way to false. $num is the colspan.
translate ($x, $y = '')
- Access: public
- Return: mixed
Translates between the 'a1, a2, b1, b2' notation and the
array (0, 0), array (0, 1), array (1, 0), array (1, 1) notation.
