Class OrientationHelper.VerticalHelper

java.lang.Object
io.github.palexdev.virtualizedfx.flow.base.OrientationHelper.VerticalHelper
All Implemented Interfaces:
OrientationHelper
Enclosing interface:
OrientationHelper

public static class OrientationHelper.VerticalHelper extends Object implements OrientationHelper
Implementation of OrientationHelper for Orientation.VERTICAL.

This helper is also responsible for listening to changes to the VirtualFlow's height, because in such cases it's needed to recompute the number of cells needed (to add or remove), and changes to the VirtualFlow.verticalPositionProperty() to update the container's layoutY property and call SimpleVirtualFlowContainer.update(double) with the new position.

Note that these listeners are added late during VirtualFlow's initialization as adding them already in the constructor would lead to an infinite loop and RAM eating for some reason.
See Also:
OrientationHelper
  • Constructor Details

  • Method Details

    • initialize

      public void initialize()
      DO NOT CALL THIS METHOD, it's automatically handled by the VirtualFlow.
    • firstVisible

      public int firstVisible()
      Computes the first visible cell index in the viewport with this formula:

      (int) Math.floor(scrolled / cellHeight)

      The scrolled parameter is the amount of pixels scrolled from the top and cellHeight is the fixed cells' height.

      The result is clamped between 0 and the number of items -1.

      Specified by:
      firstVisible in interface OrientationHelper
      Returns:
      the index of the first visible cell in the viewport
    • lastVisible

      public int lastVisible()
      Computes the first visible cell index in the viewport with this formula:

      (int) Math.ceil((scrolled + virtualFlowHeight) / cellHeight - 1)

      The scrolled parameter is the amount of pixels scrolled from the top, the virtualFlowHeight well... is self-explanatory, and cellHeight is the fixed cells' height.

      The result is clamped between 0 and the number of items -1.

      Specified by:
      lastVisible in interface OrientationHelper
      Returns:
      the index of the last visible cell in the viewport
    • computeCellsNumber

      public int computeCellsNumber()
      Specified by:
      computeCellsNumber in interface OrientationHelper
      Returns:
      the number of cells to show based on the viewport's height and cells' height
    • computeEstimatedHeight

      public double computeEstimatedHeight(double cellHeight)
      Description copied from interface: OrientationHelper
      Computes the estimated height of the flow.
      Specified by:
      computeEstimatedHeight in interface OrientationHelper
      Returns:
      the given cellHeight multiplied by the number of items
    • computeEstimatedWidth

      public double computeEstimatedWidth(double cellWidth)
      Description copied from interface: OrientationHelper
      Computes the estimated width of the flow.
      Specified by:
      computeEstimatedWidth in interface OrientationHelper
      Returns:
      the VirtualFlow's width
    • getHeight

      public double getHeight(Node node)
      Specified by:
      getHeight in interface OrientationHelper
      Returns:
      the Node's pref height
    • getWidth

      public double getWidth(Node node)
      If the Node's maxWidth is set to Double.MAX_VALUE then returns the VirtualFlow's width, otherwise calls OrientationHelper.boundSize(double, double, double).
      Specified by:
      getWidth in interface OrientationHelper
      Returns:
      the width of the given node
    • resizeRelocate

      public void resizeRelocate(Node node, double pos, double w, double h)
      Resizes and relocated the given node with the given parameters, the x offset is always 0.
      Specified by:
      resizeRelocate in interface OrientationHelper
      Parameters:
      node - the Node to resize and relocate
      pos - the y position
      w - the width
      h - the height
    • layout

      public void layout(Node node, int index, double cellW, double cellH)
      Computes the Node's y position and then calls resizeRelocate(Node, double, double, double).
      Specified by:
      layout in interface OrientationHelper
    • scrollBy

      public void scrollBy(double pixels)
      Scrolls the flow by the given amount of pixels.

      Gets the current vertical position and adds the given amount of pixels to it. The result is clamped between 0 and the vBar's max property.
      Specified by:
      scrollBy in interface OrientationHelper
    • scrollTo

      public void scrollTo(int index)
      Scrolls the flow to the given cell index.

      Computes the pixel value by multiplying the given index for the fixed cells' height, then calls scrollToPixel(double) with the result.
      Specified by:
      scrollTo in interface OrientationHelper
    • scrollToFirst

      public void scrollToFirst()
      Calls scrollTo(int) with 0 as argument.
      Specified by:
      scrollToFirst in interface OrientationHelper
    • scrollToLast

      public void scrollToLast()
      Calls scrollTo(int) with items size - 1 as argument.
      Specified by:
      scrollToLast in interface OrientationHelper
    • scrollToPixel

      public void scrollToPixel(double pixel)
      Scrolls the flow to the given pixel value.

      The given pixel value is clamped between 0 and the vBar's max property before.
      Specified by:
      scrollToPixel in interface OrientationHelper
    • dispose

      public void dispose()
      Removes and clears any listener.

      This must be called every time the OrientationHelper of the VirtualFlow is changed (typically occurs when the orientation changes).

      Specified by:
      dispose in interface OrientationHelper