Class VFXListHelper.HorizontalHelper<T, C extends VFXCell<T>>
- All Implemented Interfaces:
VFXContainerHelper<T, VFXList<T,,C>> VFXListHelper<T,C>
- Direct Known Subclasses:
VFXPaginatedListHelper.HorizontalHelper
- Enclosing interface:
VFXListHelper<T, C extends VFXCell<T>>
VFXListHelper.AbstractHelper for Orientation.HORIZONTAL. Here the range of items to
display and the viewport position are defined as follows:
- the range is given by the firstVisible() element minus the buffer size (VFXList.bufferSizeProperty()),
cannot be negative; and the sum between this start index and the total number of needed cells given by VFXListHelper.AbstractHelper.totalNum(), cannot
exceed the number of items - 1. It may happen the number of indexes given by the range end - start + 1 is lesser
than the total number of cells we need, in such cases, the range start is corrected to be end - needed + 1.
A typical situation for this is when the list position reaches the max scroll.
The range computation has the following dependencies: the list's width, the virtual max x, the buffer size and
the horizontal position.
- the viewport position. This computation is at the core of virtual scrolling. The viewport, which contains the cell,
is not supposed to scroll by insane numbers of pixels both for performance reasons and because it is not necessary.
The vertical position is just the current VFXList.vPosProperty() but negative. The horizontal
position is the one virtualized.
First we get the range of items to display and the total cell size given by VFXListHelper.getTotalCellSize(), yes, the
spacing also affects the position. Then we compute the range to the first visible cell, which is given by
IntegerRange.of(range.getMin(), firstVisible()), in other words we limit the 'complete' range to the
left buffer including the first cell after the buffer. The number of indexes in this newfound range, given by
IntegerRange.diff() is multiplied by the total cell size, this way we found the number of pixels to the
first visible cell, pixelsToFirst. We are missing only one last information, how much do we actually see
of the first visible cell? We call this amount visibleAmountFirst and it's given by vPos % totalCellSize.
Finally, the viewport's vertical position is given by -(pixelsToFirst + visibleAmountFist.
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 left
or right anymore.
The viewport's position computation has the following dependencies: the horizontal position, the vertical position,
the cell size and the spacing
-
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.list.VFXListHelper
VFXListHelper.AbstractHelper<T, C extends VFXCell<T>>, VFXListHelper.HorizontalHelper<T, C extends VFXCell<T>>, VFXListHelper.VerticalHelper<T, C extends VFXCell<T>> -
Property Summary
Properties inherited from class io.github.palexdev.virtualizedfx.list.VFXListHelper.AbstractHelper
rangeProperties inherited from class io.github.palexdev.virtualizedfx.base.VFXContainerHelper.VFXContainerHelperBase
maxHScroll, maxVScroll, viewportPosition, virtualMaxX, virtualMaxYProperties inherited from interface io.github.palexdev.virtualizedfx.base.VFXContainerHelper
maxHScroll, maxVScroll, viewportPosition, virtualMaxX, virtualMaxY -
Field Summary
Fields inherited from class io.github.palexdev.virtualizedfx.list.VFXListHelper.AbstractHelper
rangeFields 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 TypeMethodDescriptiondoublecomputeSize(Node node) Computes the width or height of the cell depending on the container's orientation.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.intintvoidLays out the given cell.voidscrollBy(double pixels) Scrolls in the viewport by the given number of pixels.voidscrollToIndex(int index) Scrolls in the viewport to the given item's index.voidscrollToPixel(double pixel) Scrolls in the viewport to the given pixel value.intMethods inherited from class io.github.palexdev.virtualizedfx.list.VFXListHelper.AbstractHelper
rangeProperty, totalNumMethods inherited from class io.github.palexdev.virtualizedfx.base.VFXContainerHelper.VFXContainerHelperBase
createMaxHScrollBinding, createMaxVScrollBinding, getContainer, invalidateVirtualSizes, maxHScrollProperty, maxVScrollProperty, viewportPositionProperty, virtualMaxXProperty, virtualMaxYPropertyMethods 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, invalidateVirtualSizes, maxHScrollProperty, maxVScrollProperty, viewportPositionProperty, virtualMaxXProperty, virtualMaxYPropertyMethods inherited from interface io.github.palexdev.virtualizedfx.list.VFXListHelper
getTotalCellSize, indexToCell, itemToCell, range
-
Constructor Details
-
HorizontalHelper
-
-
Method Details
-
createBindings
protected void createBindings()- Overrides:
createBindingsin classVFXContainerHelper.VFXContainerHelperBase<T, VFXList<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, VFXList<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, VFXList<T, C extends VFXCell<T>>>
-
firstVisible
public int firstVisible()Given byhPos / totalCellSize, clamped between 0 and itemsNum - 1.- Returns:
- the index of the first visible item
-
lastVisible
public int lastVisible()Given by(hPos + listWidth) / totalCellSize, clamped between 0 and itemsNum - 1.- Returns:
- the index of the last visible item
-
visibleNum
public int visibleNum()Given byMath.ceil(listWidth / totalCellSize).- Returns:
- the number of cells visible in the viewport. Not necessarily the same as
VFXListHelper.totalNum()
-
computeSize
Computes the width or height of the cell depending on the container's orientation.- VERTICAL -> width
- HORIZONTAL -> height
IfVFXList.fitToViewportProperty()is true, then the computation will always return the list's height, otherwise the node height is computed byLayoutUtils.boundHeight(Node). Also, in the latter case, if the found height is greater than the current max y, then the propertyVFXContainerHelper.VFXContainerHelperBase.virtualMaxYProperty()is updated with the new value. -
layout
Lays out the given cell. The index parameter is necessary to identify the position of a cell compared to the others (comes before or after). The y position is 0. The x position is the total cell size multiplied bu the given index. The height is computed bycomputeSize(Node), and the width is given by theVFXList.cellSizeProperty().- Parameters:
layoutIndex- the absolute index of the given node/cell, seeVFXListSkin.layout()
-
scrollBy
public void scrollBy(double pixels) Description copied from interface:VFXListHelperScrolls in the viewport by the given number of pixels. -
scrollToPixel
public void scrollToPixel(double pixel) Description copied from interface:VFXListHelperScrolls in the viewport to the given pixel value. -
scrollToIndex
public void scrollToIndex(int index) Description copied from interface:VFXListHelperScrolls in the viewport to the given item's index. -
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.
-