Class VFXGridHelper.DefaultHelper<T, C extends VFXCell<T>>
- All Implemented Interfaces:
VFXContainerHelper<T, VFXGrid<T,,C>> VFXGridHelper<T,C>
- Enclosing interface:
VFXGridHelper<T, C extends VFXCell<T>>
VFXGridHelper, here the range of rows and columns to display, as well as the
viewport position, the virtual max x and y properties are defined as follows:
- the columns range is given by the firstColumn() element minus the buffer size VFXGrid.bufferSizeProperty(),
(cannot be negative) and the sum between this start index and the total number of needed columns given by totalColumns()
(cannot exceed the maximum number of columns maxColumns()). It may happen that the number of indexes given
by the range end - start + 1 is lesser than the total number of columns we need. In such cases, the range
start is corrected to be end - needed + 1. A typical situation for this is when the grid's horizontal position
reaches the max scroll.
The range computation has the following dependencies: the number of columns, the grid's width, horizontal position,
the buffer size, the number of items, the cell size and the horizontal spacing.
- the rows range is given by the firstRow() element minus the buffer size VFXGrid.bufferSizeProperty(),
(cannot be negative) and the sum between this start index and the total number of needed rows given by totalRows()
(cannot exceed the maximum number of rows maxRows()). It may happen that the number of indexes given
by the range end - start + 1 is lesser than the total number of rows we need. In such cases, the range
start is corrected to be end - needed + 1. A typical situation for this is when the grid's vertical position
reaches the max scroll.
The range computation has the following dependencies: the number of columns, the grid's height, vertical position,
the buffer size, the number of items, the cell size and the vertical spacing.
- the viewport position, a computation that is at the core of virtual scrolling. The viewport, which contains the cells,
is not supposed to scroll by insane numbers of pixels both for performance reasons and because it is not necessary.
For both the horizontal and vertical positions, we use the same technique, just using the appropriate values according
to the axis we are working on.
First we get the range of rows/columns to display, then the total cell size given by getTotalCellSize(),
yes, the spacing also affects the position. Then we compute the ranges to the first visible row/column, which
are given by IntegerRange.of(range.getMin(), first()), in other words we limit the 'complete' ranges to the
start buffer including the first row/column after the buffer. The number of indexes in the newfound ranges
(given by IntegerRange.diff()) is multiplied by the total cell size, this way we are finding the number of pixels to the
first visible cell, pixelsToFirst. We are missing only one last piece of information: how much of the first row/column
do we actually see? We call this amount visibleAmountFirst and it's given by pos % totalCellSize.
Finally, the viewport's position is given by this formula -(pixelsToFirst + visibleAmountFirst)
(for both hPos and vPos of course).
While it's true that the calculations are more complex and 'needy', it's important to note that this approach
allows avoiding 'hacks' to correctly lay out the cells in the viewport. No need for special offsets at the top
or bottom anymore.
The viewport's position computation has the following dependencies: the horizontal position, the vertical position,
the cell size and both the vertical and horizontal spacing.
- the virtual max x and y properties, which give the total number of pixels on the x-axis and y-axis. Virtual means that it's not the actual size of the container, rather the size it would have if it was not virtualized. The two values are given by the max number of rows/columns multiplied by the total cell size, minus the spacing (otherwise we would have the spacing applied between the last row/column and the grid's border too). The computations have the following dependencies: the number of items, the number of columns, the cell size and the horizontal/vertical spacing (respectively).
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.palexdev.virtualizedfx.base.VFXContainerHelper
VFXContainerHelper.VFXContainerHelperBase<T, C extends Region & VFXContainer<T>>Nested classes/interfaces inherited from interface io.github.palexdev.virtualizedfx.grid.VFXGridHelper
VFXGridHelper.DefaultHelper<T, C extends VFXCell<T>> -
Property Summary
PropertiesTypePropertyDescriptionReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of columns that should be present in the viewport.Specifies the maximum possible horizontal position.Specifies the maximum possible vertical position.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of rows that should be present in the viewport.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.Position> Cells are actually contained in a separate pane called 'viewport'.Specifies the total number of pixels on the x-axis.Specifies the total number of pixels on the y-axis. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangePropertyprotected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangePropertyprotected final io.github.palexdev.mfxcore.base.properties.SizePropertyFields inherited from class io.github.palexdev.virtualizedfx.base.VFXContainerHelper.VFXContainerHelperBase
container, maxHScroll, maxVScroll, viewportPosition, virtualMaxX, virtualMaxY, vmxBinding, vmyBinding -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of columns that should be present in the viewport.protected voidprotected DoubleBindingImplementations should use this build and return theDoubleBindingwith the appropriate dependencies responsible for theVFXContainerHelper.VFXContainerHelperBase.virtualMaxXProperty()'s value.protected DoubleBindingImplementations should use this build and return theDoubleBindingwith the appropriate dependencies responsible for theVFXContainerHelper.VFXContainerHelperBase.virtualMaxXProperty()'s value.voiddispose()If the helper uses listeners/bindings that may lead to memory leaks, this is the right place to remove them.intintfirstRow()io.github.palexdev.mfxcore.base.beans.SizeintintlastRow()voidLays out the given cell.intSpecifies the maximum possible horizontal position.intmaxRows()Specifies the maximum possible vertical position.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of rows that should be present in the viewport.intintReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.Position> Cells are actually contained in a separate pane called 'viewport'.Specifies the total number of pixels on the x-axis.Specifies the total number of pixels on the y-axis.intintMethods inherited from class io.github.palexdev.virtualizedfx.base.VFXContainerHelper.VFXContainerHelperBase
createMaxHScrollBinding, createMaxVScrollBinding, getContainer, invalidateVirtualSizesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.github.palexdev.virtualizedfx.base.VFXContainerHelper
getContainer, getMaxHScroll, getMaxVScroll, getViewportPosition, getVirtualMaxX, getVirtualMaxY, indexToItem, invalidatePos, invalidateVirtualSizesMethods inherited from interface io.github.palexdev.virtualizedfx.grid.VFXGridHelper
columnsRange, indexToCell, itemToCell, rowsRange, scrollToColumn, scrollToRow, totalCells, visibleCells
-
Property Details
-
columnsRange
public ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> columnsRangeProperty- Specified by:
columnsRangePropertyin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the
columnsRangeproperty - See Also:
-
rowsRange
public ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> rowsRangeProperty- Specified by:
rowsRangePropertyin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the
rowsRangeproperty - See Also:
-
virtualMaxX
- Specified by:
virtualMaxXPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
virtualMaxXPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
virtualMaxXproperty - See Also:
-
virtualMaxY
- Specified by:
virtualMaxYPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
virtualMaxYPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
virtualMaxYproperty - See Also:
-
maxVScroll
- Specified by:
maxVScrollPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
maxVScrollPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
maxVScrollproperty - See Also:
-
maxHScroll
- Specified by:
maxHScrollPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
maxHScrollPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
maxHScrollproperty - See Also:
-
viewportPosition
public ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.Position> viewportPositionProperty- Specified by:
viewportPositionPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
viewportPositionPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
viewportPositionproperty - See Also:
-
-
Field Details
-
columnsRange
protected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty columnsRange -
rowsRange
protected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty rowsRange -
totalCellSize
protected final io.github.palexdev.mfxcore.base.properties.SizeProperty totalCellSize
-
-
Constructor Details
-
DefaultHelper
-
-
Method Details
-
createBindings
protected void createBindings()- Overrides:
createBindingsin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>
-
createVirtualMaxXBinding
Description copied from class:VFXContainerHelper.VFXContainerHelperBaseImplementations should use this build and return theDoubleBindingwith the appropriate dependencies responsible for theVFXContainerHelper.VFXContainerHelperBase.virtualMaxXProperty()'s value.- Specified by:
createVirtualMaxXBindingin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>
-
createVirtualMaxYBinding
Description copied from class:VFXContainerHelper.VFXContainerHelperBaseImplementations should use this build and return theDoubleBindingwith the appropriate dependencies responsible for theVFXContainerHelper.VFXContainerHelperBase.virtualMaxXProperty()'s value.- Specified by:
createVirtualMaxYBindingin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>
-
maxColumns
public int maxColumns()Given byMath.min(nItems, nColumns).- Specified by:
maxColumnsin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the maximum number of columns the grid can have. This value is essentially the same as
VFXGrid.columnsNumProperty()but it's also taken into account the number of items (you can't have more columns than the number of items)
-
firstColumn
public int firstColumn()Given byMath.floor(hPos / totalCellWidth), clamped between 0 andmaxColumns()- 1.- Specified by:
firstColumnin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the index of the first visible column
-
lastColumn
public int lastColumn()Given by the max inVFXGridHelper.columnsRange().- Specified by:
lastColumnin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the index of the last visible column
-
visibleColumns
public int visibleColumns()Given byMath.ceil(gridWidth / totalCellWidth). 0 if the total cells' width is also 0.- Specified by:
visibleColumnsin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the number of columns visible in the viewport. Not necessarily the same as
VFXGridHelper.totalColumns()
-
totalColumns
public int totalColumns()Given byvisibleColumns()plus double the value ofVFXGrid.bufferSizeProperty()restricted to the maximum number of columns allowed,maxColumns().- Specified by:
totalColumnsin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the total number of columns in the viewport which doesn't include only the number of visible columns but also the number of buffer columns
-
columnsRangeProperty
public ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> columnsRangeProperty()Description copied from interface:VFXGridHelperSpecifies the range of columns that should be present in the viewport. This also takes into account buffer columns, seeVFXGridHelper.visibleColumns()andVFXGridHelper.totalColumns().- Specified by:
columnsRangePropertyin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the
columnsRangeproperty
-
maxRows
public int maxRows()Given byMath.ceil(itemsNum / maxColumns()), seemaxColumns(). -
firstRow
-
lastRow
-
visibleRows
public int visibleRows()Given byMath.ceil(gridHeight / totalCellHeight).- Specified by:
visibleRowsin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the number of rows visible in the viewport. Not necessarily the same as
VFXGridHelper.totalRows()
-
totalRows
public int totalRows()Given byvisibleRows()plus double the value ofVFXGrid.bufferSizeProperty()restricted to the maximum number of rows allowed,maxRows(). -
rowsRangeProperty
public ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> rowsRangeProperty()Description copied from interface:VFXGridHelperSpecifies the range of rows that should be present in the viewport. This also takes into account buffer rows, seeVFXGridHelper.visibleRows()andVFXGridHelper.totalRows().- Specified by:
rowsRangePropertyin interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the
rowsRangeproperty
-
virtualMaxXProperty
Description copied from interface:VFXContainerHelperSpecifies the total number of pixels on the x-axis.- Specified by:
virtualMaxXPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
virtualMaxXPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
virtualMaxXproperty - See Also:
-
virtualMaxYProperty
Description copied from interface:VFXContainerHelperSpecifies the total number of pixels on the y-axis.- Specified by:
virtualMaxYPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
virtualMaxYPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
virtualMaxYproperty - See Also:
-
maxVScrollProperty
Description copied from interface:VFXContainerHelperSpecifies the maximum possible vertical position.- Specified by:
maxVScrollPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
maxVScrollPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
maxVScrollproperty - See Also:
-
maxHScrollProperty
Description copied from interface:VFXContainerHelperSpecifies the maximum possible horizontal position.- Specified by:
maxHScrollPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
maxHScrollPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
maxHScrollproperty - See Also:
-
viewportPositionProperty
public ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.Position> viewportPositionProperty()Description copied from interface:VFXContainerHelperCells are actually contained in a separate pane called 'viewport'. The scroll is applied on this pane.This property specifies the translation of the viewport, the value depends on the implementation.
- Specified by:
viewportPositionPropertyin interfaceVFXContainerHelper<T, C extends VFXCell<T>>- Overrides:
viewportPositionPropertyin classVFXContainerHelper.VFXContainerHelperBase<T, VFXGrid<T, C extends VFXCell<T>>>- Returns:
- the
viewportPositionproperty - See Also:
-
layout
Lays out the given cell. The row and column layout indexes are necessary to identify the position of a cell among the others (comes before/after, above/below). The x position is given bytotalCellWidth * columnIndex, the y position is given bytotalCellHeight * rowIndex, the width and height are given by theVFXGrid.cellSizeProperty(). -
getTotalCellSize
public io.github.palexdev.mfxcore.base.beans.Size getTotalCellSize()- Specified by:
getTotalCellSizein interfaceVFXGridHelper<T, C extends VFXCell<T>>- Returns:
- the total size of each cell, given by the
VFXGrid.cellSizeProperty()summed to the horizontal and vertical spacing values
-
dispose
public void dispose()Description copied from interface:VFXContainerHelperIf the helper uses listeners/bindings that may lead to memory leaks, this is the right place to remove them.
-