Added getCellCount() and getCellAt(), inspired by SimpleGrid.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@618 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2008-08-08 23:11:40 +00:00
parent 5de8a3acf7
commit ce7a1c9cb8
+29
View File
@@ -84,5 +84,34 @@ public class GridUtil
row.addChild(item);
return item;
}
/**
* Get the number of cells in a grid.
*/
public static function getCellCount (grid :Grid) :int
{
var count :int = 0;
for (var ii :int = 0; ii < grid.numChildren; ii++) {
count += (grid.getChildAt(ii) as GridRow).numChildren;
}
return count;
}
/**
* Return the contents of the specified cell. Not super fast, as it
* checks each row in order.
*/
public static function getCellAt (grid :Grid, index :int) :UIComponent
{
for (var ii :int = 0; ii < grid.numChildren; ii++) {
var row :GridRow = grid.getChildAt(ii) as GridRow;
if (index < row.numChildren) {
return (row.getChildAt(index) as GridItem).getChildAt(0) as UIComponent;
} else {
index -= row.numChildren; // and then on to the next row
}
}
return null; // never found it. throw an out-of-range error?
}
}
}