TablePacker

A dead simple library for laying out objects in pure JS It makes no use of any browser APIs.  This library is intended for use in HTML5 canvas UIs and in non-browser based JavaScript applications.

Summary
TablePackerA dead simple library for laying out objects in pure JS It makes no use of any browser APIs.
Functions
TablePackerCreate a new TablePacker.
addAdds a new item.
rowMove to a new line.
setBoundsResize the table.
eachCalls the passed method for each item in the table.
layoutSet the positions of all the objects in the table.
CellContains items in the table.
Functions
leftSet this cell alignment to left.
rightSet this cell alignment to right.
marginSets all the margins to m, or if you specify a side, set only that side.
getMarginGet the margin on some side.

Functions

TablePacker

function TablePacker(x,
y,
w,
h)

Create a new TablePacker.  Takes the position and size of the usable area.

Parameters

xleft bound.
ytop bound.
wwidth.
hheight.

add

TablePacker.prototype.add = function (item)

Adds a new item.

Parameters

itemthe item to add.

Returns

A cell containg the item.

row

TablePacker.prototype.row = function ()

Move to a new line.  All calls to add will now add objects to the new row.

setBounds

TablePacker.prototype.setBounds = function (x,
y,
w,
h)

Resize the table.

Parameters

xleft bound.
ytop bound.
wwidth.
hheight.

each

TablePacker.prototype.each = function (f)

Calls the passed method for each item in the table.

Parameters

fThe function to call for each item.

layout

TablePacker.prototype.layout = function ()

Set the positions of all the objects in the table.

Cell

Contains items in the table.  Used for setting alignments and margins.  All setter methods return this.

Parameters

itemthe item to be contained in this cell.
Summary
Functions
leftSet this cell alignment to left.
rightSet this cell alignment to right.
marginSets all the margins to m, or if you specify a side, set only that side.
getMarginGet the margin on some side.

Functions

left

Cell.prototype.left = function ()

Set this cell alignment to left.

right

Cell.prototype.right = function ()

Set this cell alignment to right.

margin

Cell.prototype.margin = function (m,
side)

Sets all the margins to m, or if you specify a side, set only that side.

Parameters

mthe margin.
sidewhich side the margin goes.

getMargin

Cell.prototype.getMargin = function (side)

Get the margin on some side.

Parameters

sidewhich side the margin goes.
function TablePacker(x,
y,
w,
h)
Create a new TablePacker.
TablePacker.prototype.add = function (item)
Adds a new item.
TablePacker.prototype.row = function ()
Move to a new line.
TablePacker.prototype.setBounds = function (x,
y,
w,
h)
Resize the table.
TablePacker.prototype.each = function (f)
Calls the passed method for each item in the table.
TablePacker.prototype.layout = function ()
Set the positions of all the objects in the table.
Cell.prototype.left = function ()
Set this cell alignment to left.
Cell.prototype.right = function ()
Set this cell alignment to right.
Cell.prototype.margin = function (m,
side)
Sets all the margins to m, or if you specify a side, set only that side.
Cell.prototype.getMargin = function (side)
Get the margin on some side.
Close