Class ScrollPane

All Implemented Interfaces:
Cullable, Layout
Direct Known Subclasses:
SelectBox.SelectBoxScrollPane

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

The actor is sized to its preferred size. If the actor'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 actor is larger than the scroll pane.

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

Author:
mzechner, Nathan Sweet
  • Constructor Details

  • Method Details

    • setScrollbarsVisible

      public void setScrollbarsVisible(boolean visible)
      Shows or hides the scrollbars for when using setFadeScrollBars(boolean).
    • cancelTouchFocus

      public void cancelTouchFocus()
      Cancels the stage's touch focus for all listeners except this scroll pane's flick scroll listener. This causes any actors 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.
    • setStyle

      public void setStyle(ScrollPane.ScrollPaneStyle style)
    • 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.
    • act

      public void act(float delta)
      Description copied from class: Actor
      Updates the actor based on time. Typically this is called each frame by Stage.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.
    • layout

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

      public void draw(Batch batch, float parentAlpha)
      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
      parentAlpha - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
    • 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()
      Specified by:
      getPrefWidth in interface Layout
      Overrides:
      getPrefWidth in class WidgetGroup
    • getPrefHeight

      public float getPrefHeight()
      Specified by:
      getPrefHeight in interface Layout
      Overrides:
      getPrefHeight in class WidgetGroup
    • getMinWidth

      public float getMinWidth()
      Specified by:
      getMinWidth in interface Layout
      Overrides:
      getMinWidth in class WidgetGroup
    • getMinHeight

      public float getMinHeight()
      Specified by:
      getMinHeight in interface Layout
      Overrides:
      getMinHeight in class WidgetGroup
    • setActor

      public void setActor(@Null Actor actor)
      Sets the Actor embedded in this scroll pane.
      Parameters:
      actor - May be null to remove any current actor.
    • getActor

      @Null public Actor getActor()
      Returns the actor embedded in this scroll pane, or null.
    • setWidget

      @Deprecated public void setWidget(@Null Actor actor)
      Deprecated.
    • getWidget

      @Deprecated @Null public Actor getWidget()
      Deprecated.
    • addActor

      @Deprecated public void addActor(Actor actor)
      Deprecated.
      ScrollPane may have only a single child.
      Description copied from class: Group
      Adds an actor as a child of this group, removing it from its previous parent. If the actor is already a child of this group, no changes are made.
      Overrides:
      addActor in class Group
      See Also:
    • addActorAt

      @Deprecated public void addActorAt(int index, Actor actor)
      Deprecated.
      ScrollPane may have only a single child.
      Description copied from class: Group
      Adds an actor as a child of this group at a specific index, removing it from its previous parent. If the actor is already a child of this group, no changes are made.
      Overrides:
      addActorAt in class Group
      Parameters:
      index - May be greater than the number of children.
      See Also:
    • addActorBefore

      @Deprecated public void addActorBefore(Actor actorBefore, Actor actor)
      Deprecated.
      ScrollPane may have only a single child.
      Description copied from class: Group
      Adds an actor as a child of this group immediately before another child actor, removing it from its previous parent. If the actor is already a child of this group, no changes are made.
      Overrides:
      addActorBefore in class Group
      See Also:
    • addActorAfter

      @Deprecated public void addActorAfter(Actor actorAfter, Actor actor)
      Deprecated.
      ScrollPane may have only a single child.
      Description copied from class: Group
      Adds an actor as a child of this group immediately after another child actor, removing it from its previous parent. If the actor is already a child of this group, no changes are made. If actorAfter is not in this group, the actor is added as the last child.
      Overrides:
      addActorAfter in class Group
      See Also:
    • removeActor

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

      public boolean removeActor(Actor actor, boolean unfocus)
      Description copied from class: Group
      Removes an actor from this group. Calls Group.removeActorAt(int, boolean) with the actor's child index.
      Overrides:
      removeActor in class Group
    • removeActorAt

      public Actor removeActorAt(int index, 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:
      removeActorAt in class Group
      unfocus - If true, Stage.unfocus(Actor) is called.
      Returns:
      the actor removed from this group.
    • hit

      @Null public Actor hit(float x, float y, boolean touchable)
      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:
      hit in class WidgetGroup
      touchable - If true, hit detection will respect the touchability.
      See Also:
    • setScrollX

      public void setScrollX(float pixels)
    • getScrollX

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

      public void setScrollY(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 actor'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 actor'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 actor is larger than the scroll pane horizontally.
    • isScrollY

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

      public void setScrollingDisabled(boolean x, boolean y)
      Disables scrolling in a direction. The actor will be sized to the FlickScrollPane in the disabled direction.
    • 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()
    • setVelocityX

      public void setVelocityX(float velocityX)
    • getVelocityX

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

      public void setVelocityY(float velocityY)
    • getVelocityY

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

      public void setOverscroll(boolean overscrollX, boolean overscrollY)
      For flick scroll, if true the actor 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 actor's bounds in seconds. Default is 50, 30, 200.
    • getOverscrollDistance

      public float getOverscrollDistance()
    • 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 actor'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)
    • getFadeScrollBars

      public boolean getFadeScrollBars()
    • setScrollBarTouch

      public void setScrollBarTouch(boolean scrollBarTouch)
      When false, the scroll bars don't respond to touch or mouse events. Default is true.
    • setSmoothScrolling

      public void setSmoothScrolling(boolean smoothScrolling)
    • setScrollbarsOnTop

      public void setScrollbarsOnTop(boolean scrollbarsOnTop)
      When false (the default), the actor is clipped so it is not drawn under the scrollbars. When true, the actor is clipped to the entire scroll pane bounds and the scrollbars are drawn on top of the actor. 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 actors inside the scrollpane that have received touchDown to receive touchUp when flick scrolling begins.
    • drawDebug

      public void drawDebug(ShapeRenderer shapes)
      Description copied from class: Group
      Draws this actor's debug lines if Actor.getDebug() is true and, regardless of Actor.getDebug(), calls Actor.drawDebug(ShapeRenderer) on each child.
      Overrides:
      drawDebug in class Group