Package arc.scene.ui

Class ScrollPane

All Implemented Interfaces:
Cullable

public class ScrollPane extends WidgetGroup
A group that scrolls a child widget using scrollbars and/or mouse or touch dragging.

The widget is sized to its preferred size. If the widget's preferred width or height is less than the size of this scroll pane, it is set to the size of this scroll pane. Scrollbars appear when the widget is larger than the scroll pane.

The scroll pane's preferred size is that of the child widget. At this size, the child widget will not need to scroll, so the scroll pane is typically sized by ignoring the preferred size in one or both directions.

  • Field Details

    • disableX

      protected boolean disableX
    • disableY

      protected boolean disableY
  • Constructor Details

  • Method Details

    • cancelTouchFocus

      public void cancelTouchFocus()
      Cancels the stage's touch focus for all listeners except this scroll pane's flick scroll listener. This causes any widgets inside the scrollpane that have received touchDown to receive touchUp.
      See Also:
    • cancel

      public void cancel()
      If currently scrolling by tracking a touch down, stop scrolling.
    • getStyle

      public ScrollPane.ScrollPaneStyle getStyle()
      Returns the scroll pane's style. Modifying the returned style may not have an effect until setStyle(ScrollPaneStyle) is called.
    • setStyle

      public void setStyle(ScrollPane.ScrollPaneStyle style)
    • act

      public void act(float delta)
      Description copied from class: Element
      Updates the actor based on time. Typically this is called each frame by Scene.act(float).

      The default implementation calls Action.act(float) on each action and removes actions that are complete.

      Overrides:
      act in class Group
      Parameters:
      delta - Time in seconds since the last frame.
    • setClip

      public void setClip(boolean clip)
    • layout

      public void layout()
      Description copied from class: Element
      Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Element.invalidate() on any each child whose width or height has changed, and calls Element.validate() on each child. This method should almost never be called directly, instead Element.validate() should be used.
      Overrides:
      layout in class WidgetGroup
    • draw

      public void draw()
      Description copied from class: WidgetGroup
      If this method is overridden, the super method or WidgetGroup.validate() should be called to ensure the widget group is laid out.
      Overrides:
      draw in class WidgetGroup
    • fling

      public void fling(float flingTime, float velocityX, float velocityY)
      Generate fling gesture.
      Parameters:
      flingTime - Time in seconds for which you want to fling last.
      velocityX - Velocity for horizontal direction.
      velocityY - Velocity for vertical direction.
    • getPrefWidth

      public float getPrefWidth()
      Overrides:
      getPrefWidth in class WidgetGroup
    • getPrefHeight

      public float getPrefHeight()
      Overrides:
      getPrefHeight in class WidgetGroup
    • getMinWidth

      public float getMinWidth()
      Overrides:
      getMinWidth in class WidgetGroup
    • getMinHeight

      public float getMinHeight()
      Overrides:
      getMinHeight in class WidgetGroup
    • getWidget

      public Element getWidget()
      Returns the actor embedded in this scroll pane, or null.
    • setWidget

      public void setWidget(Element widget)
      Sets the Element embedded in this scroll pane.
      Parameters:
      widget - May be null to remove any current actor.
    • removeChild

      public boolean removeChild(Element actor)
      Description copied from class: Group
      Removes an actor from this group and unfocuses it. Calls Group.removeChild(Element, boolean) with true.
      Overrides:
      removeChild in class Group
    • removeChild

      public boolean removeChild(Element actor, boolean unfocus)
      Description copied from class: Group
      Removes an actor from this group. If the actor will not be used again and has actions, they should be cleared so the actions will be returned to their pool, if any. This is not done automatically.
      Overrides:
      removeChild in class Group
      unfocus - If true, Scene.unfocus(Element) is called.
      Returns:
      true if the actor was removed from this group.
    • hit

      public Element hit(float x, float y, boolean touchable)
      Description copied from class: Element
      Returns the deepest actor that contains the specified point and is touchable and visible, or null if no actor was hit. The point is specified in the actor's local coordinate system (0,0 is the bottom left of the actor and width,height is the upper right).

      This method is used to delegate touchDown, mouse, and enter/exit events. If this method returns null, those events will not occur on this Actor.

      The default implementation returns this actor if the point is within this actor's bounds.

      Overrides:
      hit in class Group
      touchable - If true, the hit detection will respect the touchability.
      See Also:
    • scrollX

      protected void scrollX(float pixelsX)
      Called whenever the x scroll amount is changed.
    • scrollY

      protected void scrollY(float pixelsY)
      Called whenever the y scroll amount is changed.
    • visualScrollX

      protected void visualScrollX(float pixelsX)
      Called whenever the visual x scroll amount is changed.
    • visualScrollY

      protected void visualScrollY(float pixelsY)
      Called whenever the visual y scroll amount is changed.
    • getMouseWheelX

      protected float getMouseWheelX()
      Returns the amount to scroll horizontally when the mouse wheel is scrolled.
    • getMouseWheelY

      protected float getMouseWheelY()
      Returns the amount to scroll vertically when the mouse wheel is scrolled.
    • setScrollXForce

      public void setScrollXForce(float pixels)
    • getScrollX

      public float getScrollX()
      Returns the x scroll position in pixels, where 0 is the left of the scroll pane.
    • setScrollYForce

      public void setScrollYForce(float pixels)
    • getScrollY

      public float getScrollY()
      Returns the y scroll position in pixels, where 0 is the top of the scroll pane.
    • updateVisualScroll

      public void updateVisualScroll()
      Sets the visual scroll amount equal to the scroll amount. This can be used when setting the scroll amount without animating.
    • getVisualScrollX

      public float getVisualScrollX()
    • getVisualScrollY

      public float getVisualScrollY()
    • getVisualScrollPercentX

      public float getVisualScrollPercentX()
    • getVisualScrollPercentY

      public float getVisualScrollPercentY()
    • getScrollPercentX

      public float getScrollPercentX()
    • setScrollPercentX

      public void setScrollPercentX(float percentX)
    • getScrollPercentY

      public float getScrollPercentY()
    • setScrollPercentY

      public void setScrollPercentY(float percentY)
    • setFlickScroll

      public void setFlickScroll(boolean flickScroll)
    • setFlickScrollTapSquareSize

      public void setFlickScrollTapSquareSize(float halfTapSquareSize)
    • scrollTo

      public void scrollTo(float x, float y, float width, float height)
      Sets the scroll offset so the specified rectangle is fully in view, if possible. Coordinates are in the scroll pane widget's coordinate system.
    • scrollTo

      public void scrollTo(float x, float y, float width, float height, boolean centerHorizontal, boolean centerVertical)
      Sets the scroll offset so the specified rectangle is fully in view, and optionally centered vertically and/or horizontally, if possible. Coordinates are in the scroll pane widget's coordinate system.
    • getMaxX

      public float getMaxX()
      Returns the maximum scroll value in the x direction.
    • getMaxY

      public float getMaxY()
      Returns the maximum scroll value in the y direction.
    • getScrollBarHeight

      public float getScrollBarHeight()
    • getScrollBarWidth

      public float getScrollBarWidth()
    • getScrollWidth

      public float getScrollWidth()
      Returns the width of the scrolled viewport.
    • getScrollHeight

      public float getScrollHeight()
      Returns the height of the scrolled viewport.
    • isScrollX

      public boolean isScrollX()
      Returns true if the widget is larger than the scroll pane horizontally.
    • setScrollX

      public void setScrollX(float pixels)
    • isScrollY

      public boolean isScrollY()
      Returns true if the widget is larger than the scroll pane vertically.
    • setScrollY

      public void setScrollY(float pixels)
    • setScrollingDisabled

      public void setScrollingDisabled(boolean x, boolean y)
      Disables scrolling in a direction. The widget will be sized to the FlickScrollPane in the disabled direction.
    • setScrollingDisabledX

      public void setScrollingDisabledX(boolean x)
    • setScrollingDisabledY

      public void setScrollingDisabledY(boolean y)
    • isScrollingDisabledX

      public boolean isScrollingDisabledX()
    • isScrollingDisabledY

      public boolean isScrollingDisabledY()
    • isLeftEdge

      public boolean isLeftEdge()
    • isRightEdge

      public boolean isRightEdge()
    • isTopEdge

      public boolean isTopEdge()
    • isBottomEdge

      public boolean isBottomEdge()
    • isDragging

      public boolean isDragging()
    • isPanning

      public boolean isPanning()
    • isFlinging

      public boolean isFlinging()
    • getVelocityX

      public float getVelocityX()
      Gets the flick scroll x velocity.
    • setVelocityX

      public void setVelocityX(float velocityX)
    • getVelocityY

      public float getVelocityY()
      Gets the flick scroll y velocity.
    • setVelocityY

      public void setVelocityY(float velocityY)
    • setOverscroll

      public void setOverscroll(boolean overscrollX, boolean overscrollY)
      For flick scroll, if true the widget can be scrolled slightly past its bounds and will animate back to its bounds when scrolling is stopped. Default is true.
    • setupOverscroll

      public void setupOverscroll(float distance, float speedMin, float speedMax)
      For flick scroll, sets the overscroll distance in pixels and the speed it returns to the widget's bounds in seconds. Default is 50, 30, 200.
    • setForceScroll

      public void setForceScroll(boolean x, boolean y)
      Forces enabling scrollbars (for non-flick scroll) and overscrolling (for flick scroll) in a direction, even if the contents do not exceed the bounds in that direction.
    • isForceScrollX

      public boolean isForceScrollX()
    • isForceScrollY

      public boolean isForceScrollY()
    • setFlingTime

      public void setFlingTime(float flingTime)
      For flick scroll, sets the amount of time in seconds that a fling will continue to scroll. Default is 1.
    • setClamp

      public void setClamp(boolean clamp)
      For flick scroll, prevents scrolling out of the widget's bounds. Default is true.
    • setScrollBarPositions

      public void setScrollBarPositions(boolean bottom, boolean right)
      Set the position of the vertical and horizontal scroll bars.
    • setFadeScrollBars

      public void setFadeScrollBars(boolean fadeScrollBars)
      When true the scrollbars don't reduce the scrollable size and fade out after some time of not being used.
    • setupFadeScrollBars

      public void setupFadeScrollBars(float fadeAlphaSeconds, float fadeDelaySeconds)
    • setSmoothScrolling

      public void setSmoothScrolling(boolean smoothScrolling)
    • setScrollbarsOnTop

      public void setScrollbarsOnTop(boolean scrollbarsOnTop)
      When false (the default), the widget is clipped so it is not drawn under the scrollbars. When true, the widget is clipped to the entire scroll pane bounds and the scrollbars are drawn on top of the widget. If setFadeScrollBars(boolean) is true, the scroll bars are always drawn on top.
    • getVariableSizeKnobs

      public boolean getVariableSizeKnobs()
    • setVariableSizeKnobs

      public void setVariableSizeKnobs(boolean variableSizeKnobs)
      If true, the scroll knobs are sized based on getMaxX() or getMaxY(). If false, the scroll knobs are sized based on Drawable.getMinWidth() or Drawable.getMinHeight(). Default is true.
    • setCancelTouchFocus

      public void setCancelTouchFocus(boolean cancelTouchFocus)
      When true (default) and flick scrolling begins, cancelTouchFocus() is called. This causes any widgets inside the scrollpane that have received touchDown to receive touchUp when flick scrolling begins.