Class VFXGridHelper.DefaultHelper<T,C extends VFXCell<T>>
- All Implemented Interfaces:
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).
-
Property Summary
PropertiesTypePropertyDescriptionjavafx.beans.property.ReadOnlyObjectProperty
<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of columns that should be present in the viewport.javafx.beans.property.ReadOnlyDoubleProperty
Specifies the maximum possible horizontal position.javafx.beans.property.ReadOnlyDoubleProperty
Specifies the maximum possible vertical position.javafx.beans.property.ReadOnlyObjectProperty
<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of rows that should be present in the viewport.javafx.beans.property.ReadOnlyObjectProperty
<io.github.palexdev.mfxcore.base.beans.Position> Cells are actually contained in a separate pane called 'viewport'.javafx.beans.property.ReadOnlyDoubleProperty
Specifies the total number of pixels on the x-axis.javafx.beans.property.ReadOnlyDoubleProperty
Specifies the total number of pixels on the y-axis. -
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.palexdev.virtualizedfx.grid.VFXGridHelper
VFXGridHelper.DefaultHelper<T,
C extends VFXCell<T>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty
protected final javafx.beans.property.ReadOnlyDoubleWrapper
protected final javafx.beans.property.ReadOnlyDoubleWrapper
protected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty
protected final io.github.palexdev.mfxcore.base.properties.SizeProperty
protected final io.github.palexdev.mfxcore.base.properties.PositionProperty
protected final javafx.beans.property.ReadOnlyDoubleWrapper
protected final javafx.beans.property.ReadOnlyDoubleWrapper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjavafx.beans.property.ReadOnlyObjectProperty
<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of columns that should be present in the viewport.int
int
firstRow()
getGrid()
io.github.palexdev.mfxcore.base.beans.Size
int
int
lastRow()
void
Lays out the given cell.int
javafx.beans.property.ReadOnlyDoubleProperty
Specifies the maximum possible horizontal position.int
maxRows()
javafx.beans.property.ReadOnlyDoubleProperty
Specifies the maximum possible vertical position.javafx.beans.property.ReadOnlyObjectProperty
<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> Specifies the range of rows that should be present in the viewport.int
int
javafx.beans.property.ReadOnlyObjectProperty
<io.github.palexdev.mfxcore.base.beans.Position> Cells are actually contained in a separate pane called 'viewport'.javafx.beans.property.ReadOnlyDoubleProperty
Specifies the total number of pixels on the x-axis.javafx.beans.property.ReadOnlyDoubleProperty
Specifies the total number of pixels on the y-axis.int
int
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.palexdev.virtualizedfx.grid.VFXGridHelper
columnsRange, dispose, getMaxHScroll, getMaxVScroll, getViewportPosition, getVirtualMaxX, getVirtualMaxY, indexToCell, indexToItem, invalidatePos, itemToCell, rowsRange, scrollToColumn, scrollToRow, totalCells, visibleCells
-
Property Details
-
columnsRange
public javafx.beans.property.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> columnsRangeProperty- Specified by:
columnsRangeProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
columnsRange
property - See Also:
-
rowsRange
public javafx.beans.property.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> rowsRangeProperty- Specified by:
rowsRangeProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
rowsRange
property - See Also:
-
virtualMaxX
public javafx.beans.property.ReadOnlyDoubleProperty virtualMaxXProperty- Specified by:
virtualMaxXProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
virtualMaxX
property - See Also:
-
virtualMaxY
public javafx.beans.property.ReadOnlyDoubleProperty virtualMaxYProperty- Specified by:
virtualMaxYProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
virtualMaxY
property - See Also:
-
maxVScroll
public javafx.beans.property.ReadOnlyDoubleProperty maxVScrollProperty- Specified by:
maxVScrollProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
maxVScroll
property - See Also:
-
maxHScroll
public javafx.beans.property.ReadOnlyDoubleProperty maxHScrollProperty- Specified by:
maxHScrollProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
maxHScroll
property - See Also:
-
viewportPosition
public javafx.beans.property.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.Position> viewportPositionProperty- Specified by:
viewportPositionProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
viewportPosition
property - See Also:
-
-
Field Details
-
grid
-
columnsRange
protected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty columnsRange -
rowsRange
protected final io.github.palexdev.mfxcore.base.properties.range.IntegerRangeProperty rowsRange -
virtualMaxX
protected final javafx.beans.property.ReadOnlyDoubleWrapper virtualMaxX -
virtualMaxY
protected final javafx.beans.property.ReadOnlyDoubleWrapper virtualMaxY -
maxHScroll
protected final javafx.beans.property.ReadOnlyDoubleWrapper maxHScroll -
maxVScroll
protected final javafx.beans.property.ReadOnlyDoubleWrapper maxVScroll -
viewportPosition
protected final io.github.palexdev.mfxcore.base.properties.PositionProperty viewportPosition -
totalCellSize
protected final io.github.palexdev.mfxcore.base.properties.SizeProperty totalCellSize
-
-
Constructor Details
-
DefaultHelper
-
-
Method Details
-
maxColumns
public int maxColumns()Given byMath.min(nItems, nColumns)
.- Specified by:
maxColumns
in 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:
firstColumn
in 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:
lastColumn
in 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:
visibleColumns
in 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:
totalColumns
in 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 javafx.beans.property.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> columnsRangeProperty()Description copied from interface:VFXGridHelper
Specifies the range of columns that should be present in the viewport. This also takes into account buffer columns, seeVFXGridHelper.visibleColumns()
andVFXGridHelper.totalColumns()
.- Specified by:
columnsRangeProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
columnsRange
property
-
maxRows
public int maxRows()Given byMath.ceil(itemsNum / maxColumns())
, seemaxColumns()
. -
firstRow
public int firstRow()Given byMath.floor(vPos / totalCellHeight)
, clamped between 0 andmaxRows()
- 1. -
lastRow
public int lastRow()Given by the max inmaxRows()
. -
visibleRows
public int visibleRows()Given byMath.ceil(gridHeight / totalCellHeight)
.- Specified by:
visibleRows
in 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 javafx.beans.property.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.range.NumberRange<Integer>> rowsRangeProperty()Description copied from interface:VFXGridHelper
Specifies the range of rows that should be present in the viewport. This also takes into account buffer rows, seeVFXGridHelper.visibleRows()
andVFXGridHelper.totalRows()
.- Specified by:
rowsRangeProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
rowsRange
property
-
virtualMaxXProperty
public javafx.beans.property.ReadOnlyDoubleProperty virtualMaxXProperty()Description copied from interface:VFXGridHelper
Specifies the total number of pixels on the x-axis.- Specified by:
virtualMaxXProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
virtualMaxX
property - See Also:
-
virtualMaxYProperty
public javafx.beans.property.ReadOnlyDoubleProperty virtualMaxYProperty()Description copied from interface:VFXGridHelper
Specifies the total number of pixels on the y-axis.- Specified by:
virtualMaxYProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
virtualMaxY
property - See Also:
-
maxVScrollProperty
public javafx.beans.property.ReadOnlyDoubleProperty maxVScrollProperty()Description copied from interface:VFXGridHelper
Specifies the maximum possible vertical position.- Specified by:
maxVScrollProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
maxVScroll
property - See Also:
-
maxHScrollProperty
public javafx.beans.property.ReadOnlyDoubleProperty maxHScrollProperty()Description copied from interface:VFXGridHelper
Specifies the maximum possible horizontal position.- Specified by:
maxHScrollProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
maxHScroll
property - See Also:
-
viewportPositionProperty
public javafx.beans.property.ReadOnlyObjectProperty<io.github.palexdev.mfxcore.base.beans.Position> viewportPositionProperty()Description copied from interface:VFXGridHelper
Cells 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:
viewportPositionProperty
in interfaceVFXGridHelper<T,
C extends VFXCell<T>> - Returns:
- the
viewportPosition
property - 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:
getTotalCellSize
in 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
-
getGrid
-