Moved these here from inside metasoy.

Grid changed into GridUtil.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@143 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2007-02-02 19:44:04 +00:00
parent dddf409ad7
commit 7ff794343c
3 changed files with 149 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
package com.threerings.flex {
import mx.containers.Grid;
import mx.containers.GridItem;
import mx.containers.GridRow;
import mx.controls.Label;
import mx.core.UIComponent;
/**
* Convenience methods for adding children to Grids.
*/
public class GridUtil
{
/**
* Add a new row to the grid, containing the specified
* components.
*
* @param specs a list of components or Strings, or you can follow
* any component with a two-dimensional array that specifies
* grid width/height.
*
* Example: addRow(grid, "labeltxt", _entryField, _bigThing, [2, 2], _smallThing);
*
* All will be put in the same row, but bigThing will have
* colspan=2 rowspan=2
*/
public static function addRow (grid :Grid, ... specs) :GridRow
{
var row :GridRow = new GridRow();
var lastItem :GridItem;
for each (var o :Object in specs) {
if (o is String) {
var lbl :Label = new Label();
lbl.text = String(o);
o = lbl;
}
if (o is UIComponent) {
lastItem = addToRow(row, UIComponent(o));
} else if (o is Array) {
var arr :Array = (o as Array);
lastItem.colSpan = int(arr[0]);
lastItem.rowSpan = int(arr[1]);
} else {
throw new ArgumentError();
}
}
grid.addChild(row);
return row;
}
/**
* A convenience function to the specified component to the
* specified row.
*/
public static function addToRow (row :GridRow, comp :UIComponent) :GridItem
{
var item :GridItem = new GridItem();
item.addChild(comp);
row.addChild(item);
return item;
}
}
}
@@ -0,0 +1,40 @@
//
// $Id$
package com.threerings.flex {
import flash.display.DisplayObjectContainer;
import mx.core.ContainerCreationPolicy;
import mx.core.UIComponent;
import mx.containers.VBox;
public class LazyContainer extends VBox
{
/**
* Create a lazy container that will not create its children
* until needed.
*
* @param creation a function that takes no args and returns
* a UIComponent to be added to the container.
*/
public function LazyContainer (creation :Function)
{
_creation = creation;
creationPolicy = ContainerCreationPolicy.NONE;
}
override public function createComponentsFromDescriptors (
recurse :Boolean = true) :void
{
super.createComponentsFromDescriptors(recurse);
if (_creation != null) {
addChild(_creation() as UIComponent);
_creation = null; // assist gc
}
}
protected var _creation :Function;
}
}
@@ -0,0 +1,42 @@
package com.threerings.flex {
import mx.core.ContainerCreationPolicy;
import mx.core.UIComponent;
import mx.containers.TabNavigator;
import mx.containers.VBox;
/**
* A tab navigator that is specially set up for lazy-creating the
* content in each tab.
*/
public class LazyTabNavigator extends TabNavigator
{
public function LazyTabNavigator ()
{
super();
}
/**
* Add a tab to the container. The creation function takes no args and
* returns a UIComponent.
*/
public function addTab (label :String, creation :Function) :void
{
addTabAt(label, creation, numChildren);
}
/**
* Add a tab to the container at the specified index.
* The creation function takes no args and returns a UIComponent.
*/
public function addTabAt (
label :String, creation :Function, index :int) :void
{
var box :LazyContainer = new LazyContainer(creation);
box.label = label;
addChildAt(box, index);
}
}
}