Class GuiScrolling

All Implemented Interfaces:
ContentElement<GuiElement<?>>, ElementEvents, GuiParent<GuiScrolling>, TooltipHandler<GuiScrolling>

public class GuiScrolling extends GuiElement<GuiScrolling> implements ContentElement<GuiElement<?>>
So the logic behind this element is as follows. This element contains a base "Content Element" that holds all the scrollable content. The content element's position is controlled by the GuiScrolling But its GeoParam.WIDTH and GeoParam.HEIGHT constraints can be set by the user, Or they can be set to dynamically adjust to the child elements added to it.

The bounds of the GuiScrolling represent the "view window" When scrolling up/down, left/right the Content Element is effectively just moving around behind the view window and everything outside the view window is scissored off. Any events that occur outside the view window are not propagated to scroll element. Calls to GuiElement.isMouseOver() from an area of an element that is outside the view window will return false.

Elements that are completely outside the view window will not be rendered at all for efficiency.

Created by brandon3055 on 01/09/2023

  • Field Details

    • enableScissor

      public boolean enableScissor
      This is made available primarily for debugging purposes where it can be useful to see what's going on behind the scenes.
  • Constructor Details

    • GuiScrolling

      public GuiScrolling(@NotNull @NotNull GuiParent<?> parent)
      Parameters:
      parent - parent GuiParent.
  • Method Details

    • getContentElement

      public GuiElement<?> getContentElement()
      Retrieves the content element that holds all the scrolling elements. You must add all of your scrolling content to this element. Scrolling content must also be constrained relative to this element.

      The GeoParam.TOP and GeoParam.LEFT constraints for this element are set by the GuiScrolling and must not be overridden. These are used to control the 'scrolling' of the element.

      By default, the GeoParam.WIDTH and GeoParam.HEIGHT (and therefor also BOTTOM, RIGHT) are dynamically constrained to match the outer bounds of the scrolling elements. So attempting to constrain the content to any of these dynamic parameters would result in a stack overflow. You can however override the WIDTH and HEIGHT constraints if you wish. This can be useful if you wish to create something like a fixed width scrolling list where the width of each scrolling element is bound to the width of the list.

      The most important thing to note, Especially when manually constraining the WIDTH and HEIGHT of the content element, All scrolling elements must be withing the bounds of the content element. Anything outside the content element's bounds will not be visible.

      Specified by:
      getContentElement in interface ContentElement<GuiElement<?>>
      Returns:
      The content element.
    • installContainerElement

      public void installContainerElement(GuiElement<?> element)
      This allows you to install a custom container element. The elements constraints will automatically be set by this method.

      After calling this method you may override the container element WIDTH and HEIGHT constraints as described in the documentation for getContentElement() But you must not touch the TOP or LEFT constraints.

      Important thing to note, By default the container element is preinstalled before any children can be added, meaning any children added to the GuiScrolling will render on top of the scrolling content. As this method allows you to set a new child as the container element, any children added before the new content element, will render under the content element.

      Parameters:
      element - The new container element.
    • scrollState

      public SliderState scrollState(Axis axis)
      Returns:
      a SliderState that can be used to get or control the scroll position of the specified axis.
    • totalSize

      public double totalSize(Axis axis)
      Returns:
      the total content size / length for the given axis
    • hiddenSize

      public double hiddenSize(Axis axis)
      Returns:
      the hidden content size / length for the given axis (How much of the content is outside the view area)
    • tick

      public void tick(double mouseX, double mouseY)
      Description copied from class: GuiElement
      Called every tick to update the element. Note this is called regardless of weather or not the element is actually enabled.
      Overrides:
      tick in class GuiElement<GuiScrolling>
      Parameters:
      mouseX - Current mouse X position
      mouseY - Current mouse Y position
    • blockMouseOver

      public boolean blockMouseOver(GuiElement<?> element, double mouseX, double mouseY)
      Description copied from interface: GuiParent
      Allows an element to override the GuiElement.isMouseOver() method of its children. This is primarily used for things like scroll elements where mouseover interactions need to be blocked outside the view area.
      Specified by:
      blockMouseOver in interface GuiParent<GuiScrolling>
      Overrides:
      blockMouseOver in class GuiElement<GuiScrolling>
      Parameters:
      element - The element on which isMouseOver is getting called.
      Returns:
      true if mouse-over interaction should be blocked for this child element.
    • renderChild

      protected boolean renderChild(GuiElement<?> child, GuiRender render, double mouseX, double mouseY, float partialTicks)
      Overrides:
      renderChild in class GuiElement<GuiScrolling>
    • simpleScrollWindow

      public static GuiScrolling.ScrollWindow simpleScrollWindow(@NotNull @NotNull GuiParent<?> parent, boolean verticalScrollBar, boolean horizontalScrollBar)