rex_gridCtrl

ConceptThis plugin is improved from rex_listCtrl plugin.Grid table is composed of some cells. Each cell is composed of data and instances like sprites and texts.The physical boundary of this grid table control plugin is a visible area of this table, cells which out of this area are invisible.User creates instances of each visible cell, and registers them to this plugin, then this plugin will set the position of these registered instances. And these registered instances will be destroyed while the cell is invisible by this plugin automatically.Properties of instances in a cell are saved into this grid table control plugin instead of saving in private variables in the instances. So the instances only are used in displaying.

On a cell is visible"Condition:On cell visible" will be triggered while the cell becomes visible. Create instances of this cell under this event. There are some expressions for this cell -

Expression:CellIndex - the index of this visible cell( Expression:CellTLX, Expression:CellTLY ) - the position of the cell's top-left point

Then use "Action:Pin instance" to pin instances at this cell.

On a cell is invisible"Condition:On cell invisible" will be triggered while a cell becomes invisible. Pinned instances will be destroyed automatically. The cell index could be got by "Expression:CellIndex".

Retrieve visible cellsRetrieve visible cells by "Condition:For each visible cell", get the cell index by "Expression:CellIndex" and the position of the cell's top-left point by ( Expression:CellTLX, Expression:CellTLY ) under this event.

Get cell indexCall "Expression:UID2CellIndex" to get the pinned instance is belong to which cell.

Pick pined instances"Condition:Pick instances", "Action:Pick instance", or "Condition:Pick all instances", "Action:Pick all instances" could be used to pick pined instances on a cell.

Data of each cellData of each cell is stored in other data structure, like official array, official dictionary, rex_csv, etc... which indexes by cell index.Properties of instances (for example, "is selected" state in a sprite) in each cell is stored/read in custom data of this plugin by "Action:Set value"/"Expression:At". It is better NOT to use private variable to save properties in these instances in a cell, because that instances in a cell will be destroyed when the line is invisible.

Retrieve filter cells"Condition:For each matched cells" could be used to retrieve cells which the value in custom data is matched the condition. Get the cell index by "Expression:CellIndex".

Scroll tableThe table is scrolled by an offset (x, y), which is the (top-left) position of line index 0. Call one of these actions to set the offset (x, y) -

Action:Set OX, Action:Set OY, Action:Set OXY

Action:Add to OX, Action:Add to OY, Action:Add to OXY

Action:Scroll to index

Action:Scroll by percentage

The visible cells will be changed after offset (x,y) had changed.

Clamp offset (x,y)Set "Clamp OXY" to "Yes" could clamp the visible cell between first to last line.Set to "No" if user wants to control the offset (x,y) without any default constraint.

Total cellsSet total cells count in "Total cells" in properties table, or set by "Action:Set total cells count".

Retrieve cells"Condition:For each cell" could retrieve each cell in this table, or use "Condition:For each cell in a range" to retrieve some cells.Get the cell index by "Expression:CellIndex".

Cell sizeThe cell size is set in "Cell height", "Cell width" in properties table, or set by "Action:Set cell height", "Action:Set cell width".

Remove cellsCall "Action:Remove cells" to remove cells from a start index. It will also destroy instances which belong these removed cells.The custom data of these removed cells will also be removed, and packed into a string which could be read by "Expression:LastRemovedCells". It could be used to insert to another table, see next section.

Insert cellsCall "Action:Insert new cells" or "Action:Push new cells" to insert some new cells with empty custom data. Or call "Action:Insert cells" or "Action:Push cells" to insert some new cells with packed custom data. Packed custom data might come from "Expression:CustomDataInCells" or "Expression:LastRemovedCells".

Move cells from one table to anotherHere is a solution to move cells from source table to target table:

Insert data to another data structure (official array object in this sample), and insert the custom data of these cells by "Expression:CustomDataInCells" to target table.

Remove data and cells from source table.

DestroyAll pined object in each cell would be destroyed while gridCtrl object had been destroyed by action:Destroy.