类 CellsManager<T,C extends Cell<T>>
- 类型参数:
T- the type of object to representC- the type of Cell to use
initCells(int) and then added to the container,
they are also updated to be sure they are showing the right content. On scroll updateCells(int)
is called, this method processes the needed updates to do, see (CellsManager<T,C extends Cell<T>>.io.github.palexdev.virtualizedfx.flow.simple.CellsManager.CellUpdate ), then updates the cells,
updates the layout by calling processLayout(List) and finally updates the indexes range of shown items.
The important part to understand is that rather than creating new cells everytime the flow scrolls
we update the already created cells, so the scroll is very smooth, and it's also efficient
in terms of memory usage. This allows the flow to handle huge amounts of items (depending on cells' complexity of course).-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected CcellForIndex(int index) Exchanges an index for a Cell.protected CcellForItem(T item) Exchanges an item for a Cell.protected voidclear()Resets the CellsManager by clearing the container's children, clearing the cellsPool, clearing the updates list and resetting the stored indexes range to [-1, -1].getCells()protected voidinitCells(int num) Populates the cellsPool, adds them to the container and then callsupdateCells(int)(indexes from 0 to num) to ensure the cells are displaying the right content (should not be needed though)voidCalled when the items list changes, if the list has been cleared callsclear()and then exits.protected voidprocessLayout(List<CellsManager<T, C>.io.github.palexdev.virtualizedfx.flow.simple.CellsManager.CellUpdate> updates) Responsible for laying out the cells from a list ofCellsManager<T,s.C extends Cell<T>>.io.github.palexdev.virtualizedfx.flow.simple.CellsManager.CellUpdate protected voidForcesprocessLayout(List)with the previously computed updates.protected voidreset()Drastic reset of the VirtualFlow, scroll position is set back to 0.0,clear()is called, cells are re-initializedinitCells(int).protected voidsupplyCells(int from, int targetSize) Creates new cells from the givenfromindex, keeps creating cells until the cell pool size has reachedtargetSize, new cells are also added to the container.protected voidupdateCells(int start) Responsible for updating the cells in the viewport.
-
构造器详细资料
-
CellsManager
-
-
方法详细资料
-
initCells
protected void initCells(int num) Populates the cellsPool, adds them to the container and then callsupdateCells(int)(indexes from 0 to num) to ensure the cells are displaying the right content (should not be needed though)- 参数:
num- the number of cells to create
-
updateCells
protected void updateCells(int start) Responsible for updating the cells in the viewport. If the items list is empty returns immediately. Computes the max number of cells to show by callingOrientationHelper.computeCellsNumber()then computes theendindex by adding thestartindex to it (clamped between 0 and number of items). If the list was cleared, sostartis invalid, callsinitCells(int)with the previous computed max, then exits as that method will then call this with a valid start index.If the new indexes range (start-end) is equal to the previous stored range it's not necessary to update the cells therefore exits. This check is ignored if the items list was changed (items replaced, added or removed), int this case it's needed to update.
The next step is a bit tricky. The cellsPool indexes go from 0 to size() - 1 of course, but the start and end parameters do not start from 0, let's say I have to show items from 10 to 20, so it's needed to use an "external" counter to get the cells from 0 to size() - 1, while the items are retrieved from the list fromstarttoend, in this loop we createCellsManager<T,beans to make the code cleaner, after the loopC extends Cell<T>>.io.github.palexdev.virtualizedfx.flow.simple.CellsManager.CellUpdate CellsManager.CellUpdate.update()is called for each bean, then the layout is updated withprocessLayout(List)and finally the range of shown items is updated.- 参数:
start- the start index from which retrieve the items from the items list
-
itemsChanged
public void itemsChanged()Called when the items list changes, if the list has been cleared callsclear()and then exits.If the last range is invalid (meaning that the container is empty) computes the max number of cells to show with
If none of the above conditions are met then we have to make several checks:OrientationHelper.computeCellsNumber(), then callsinitCells(int)with that number.It's needed to check if there are too many cells in the pool or too few, depending on the case, it's needed to remove/supply some cells.
Finally the listChanged flag is set to true to force the update andupdateCells(int)is called, the start index is the last start index. -
processLayout
protected void processLayout(List<CellsManager<T, C>.io.github.palexdev.virtualizedfx.flow.simple.CellsManager.CellUpdate> updates) Responsible for laying out the cells from a list ofCellsManager<T,s. The positioning is absolute, it always starts from [0, 0], this ensures that there is no white space above or below any cell.C extends Cell<T>>.io.github.palexdev.virtualizedfx.flow.simple.CellsManager.CellUpdate For each update (from 0 to updates.size()) cell's position is computed by
OrientationHelper.layout(Node, int, double, double). -
requestLayout
protected void requestLayout()ForcesprocessLayout(List)with the previously computed updates. -
reset
protected void reset()Drastic reset of the VirtualFlow, scroll position is set back to 0.0,clear()is called, cells are re-initializedinitCells(int).Typically happens when the layout bounds of the VirtualFlow changed.
-
clear
protected void clear()Resets the CellsManager by clearing the container's children, clearing the cellsPool, clearing the updates list and resetting the stored indexes range to [-1, -1]. -
supplyCells
protected void supplyCells(int from, int targetSize) Creates new cells from the givenfromindex, keeps creating cells until the cell pool size has reachedtargetSize, new cells are also added to the container. -
cellForIndex
Exchanges an index for a Cell.Gets the item at the given index in the items list then calls
cellForItem(Object). -
cellForItem
Exchanges an item for a Cell.Simply applies the VirtualFlow's cell factory to the given item.
-
getCells
- 返回:
- a map of the currently shown cells by the item's index
-