Class VFXGridHelper.DefaultHelper<T,C extends VFXCell<T>>

java.lang.Object
io.github.palexdev.virtualizedfx.grid.VFXGridHelper.DefaultHelper<T,C>
All Implemented Interfaces:
VFXGridHelper<T,C>
Enclosing interface:
VFXGridHelper<T,C extends VFXCell<T>>

public static class VFXGridHelper.DefaultHelper<T,C extends VFXCell<T>> extends Object implements VFXGridHelper<T,C>
Concrete implementation of 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 Details

  • Field Details

    • grid

      protected final VFXGrid<T,C extends VFXCell<T>> 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

      public DefaultHelper(VFXGrid<T,C> grid)
  • Method Details