\r
package com.badlogic.gdx.scenes.scene2d.ui;\r
\r
+import com.esotericsoftware.tablelayout.BaseTableLayout.Debug;\r
+import com.esotericsoftware.tablelayout.Cell;\r
+import com.esotericsoftware.tablelayout.Toolkit;\r
+\r
import com.badlogic.gdx.math.Rectangle;\r
import com.badlogic.gdx.scenes.scene2d.Actor;\r
import com.badlogic.gdx.scenes.scene2d.Group;\r
import com.badlogic.gdx.scenes.scene2d.utils.Layout;\r
import com.badlogic.gdx.utils.Array;\r
-import com.esotericsoftware.tablelayout.BaseTableLayout.Debug;\r
-import com.esotericsoftware.tablelayout.Toolkit;\r
+import com.badlogic.gdx.utils.Pool;\r
+import com.badlogic.gdx.utils.ReflectionPool;\r
\r
/** The libgdx implementation of the table layout functionality.\r
* @author Nathan Sweet */\r
class TableToolkit extends Toolkit<Actor, Table, TableLayout> {\r
static boolean drawDebug;\r
+ static Pool<Cell> cellPool = new Pool() {\r
+ protected Cell newObject () {\r
+ return new Cell();\r
+ }\r
+ };\r
+\r
+ public Cell obtainCell (TableLayout layout) {\r
+ Cell cell = cellPool.obtain();\r
+ cell.setLayout(layout);\r
+ return cell;\r
+ }\r
+\r
+ public void freeCell (Cell cell) {\r
+ cell.setLayout(null);\r
+ cellPool.free(cell);\r
+ }\r
\r
public void addChild (Actor parent, Actor child) {\r
child.remove();\r
\r
/** Adds a new cell to the table with the specified widget. */\r
public Cell<C> add (C widget) {\r
- Cell cell = new Cell(this);\r
+ Cell cell = toolkit.obtainCell((L)this);\r
cell.widget = widget;\r
\r
if (cells.size() > 0) {\r
* for all cells in the new row. */\r
public Cell row () {\r
if (cells.size() > 0) endRow();\r
- rowDefaults = new Cell(this);\r
+ rowDefaults = toolkit.obtainCell((L)this);\r
return rowDefaults;\r
}\r
\r
public Cell columnDefaults (int column) {\r
Cell cell = columnDefaults.size() > column ? columnDefaults.get(column) : null;\r
if (cell == null) {\r
- cell = new Cell(this);\r
+ cell = toolkit.obtainCell((L)this);\r
if (column >= columnDefaults.size()) {\r
for (int i = columnDefaults.size(); i < column; i++)\r
columnDefaults.add(null);\r
if (prefWidth < minWidth) prefWidth = minWidth;\r
if (maxWidth > 0 && prefWidth > maxWidth) prefWidth = maxWidth;\r
\r
- float spannedMinWidth = 0, spannedPrefWidth = 0;\r
+ float spannedMinWidth = -(c.computedPadLeft + c.computedPadRight), spannedPrefWidth = spannedMinWidth;\r
for (int column = c.column, nn = column + c.colspan; column < nn; column++) {\r
spannedMinWidth += columnMinWidth[column];\r
spannedPrefWidth += columnPrefWidth[column];\r
float hpadding = w(padLeft) + w(padRight);\r
float vpadding = h(padTop) + h(padBottom);\r
\r
- // totalMinWidth/totalMinHeight are needed because tableMinWidth/tableMinHeight could be based on this.width or this.height.\r
- float totalMinWidth = 0, totalMinHeight = 0;\r
float totalExpandWidth = 0, totalExpandHeight = 0;\r
- for (int i = 0; i < columns; i++) {\r
- totalMinWidth += columnMinWidth[i];\r
+ for (int i = 0; i < columns; i++)\r
totalExpandWidth += expandWidth[i];\r
- }\r
- for (int i = 0; i < rows; i++) {\r
- totalMinHeight += rowMinHeight[i];\r
+ for (int i = 0; i < rows; i++)\r
totalExpandHeight += expandHeight[i];\r
- }\r
\r
// Size columns and rows between min and pref size using (preferred - min) size to weight distribution of extra space.\r
float[] columnWeightedWidth;\r
- float totalGrowWidth = tablePrefWidth - totalMinWidth;\r
+ float totalGrowWidth = tablePrefWidth - tableMinWidth;\r
if (totalGrowWidth == 0)\r
columnWeightedWidth = columnMinWidth;\r
else {\r
- float extraWidth = Math.min(totalGrowWidth, Math.max(0, layoutWidth - totalMinWidth));\r
+ float extraWidth = Math.min(totalGrowWidth, Math.max(0, layoutWidth - tableMinWidth));\r
columnWeightedWidth = this.columnWeightedWidth = ensureSize(this.columnWeightedWidth, columns);\r
for (int i = 0; i < columns; i++) {\r
float growWidth = columnPrefWidth[i] - columnMinWidth[i];\r
}\r
\r
float[] rowWeightedHeight;\r
- float totalGrowHeight = tablePrefHeight - totalMinHeight;\r
+ float totalGrowHeight = tablePrefHeight - tableMinHeight;\r
if (totalGrowHeight == 0)\r
rowWeightedHeight = rowMinHeight;\r
else {\r
rowWeightedHeight = this.rowWeightedHeight = ensureSize(this.rowWeightedHeight, rows);\r
- float extraHeight = Math.min(totalGrowHeight, Math.max(0, layoutHeight - totalMinHeight));\r
+ float extraHeight = Math.min(totalGrowHeight, Math.max(0, layoutHeight - tableMinHeight));\r
for (int i = 0; i < rows; i++) {\r
float growHeight = rowPrefHeight[i] - rowMinHeight[i];\r
float growRatio = growHeight / (float)totalGrowHeight;\r
float widgetX, widgetY;\r
float widgetWidth, widgetHeight;\r
\r
- private final BaseTableLayout layout;\r
+ private BaseTableLayout layout;\r
boolean endRow;\r
int column, row;\r
int cellAboveIndex = -1;\r
float computedPadTop, computedPadLeft, computedPadBottom, computedPadRight;\r
\r
- Cell (BaseTableLayout layout) {\r
+ public Cell () {\r
+ }\r
+\r
+ public void setLayout (BaseTableLayout layout) {\r
this.layout = layout;\r
}\r
\r
}\r
\r
static Cell defaults (BaseTableLayout layout) {\r
- Cell defaults = new Cell(layout);\r
+ Cell defaults = new Cell();\r
+ defaults.layout = layout;\r
defaults.minWidth = Value.minWidth;\r
defaults.minHeight = Value.minHeight;\r
defaults.prefWidth = Value.prefWidth;\r