libgdx API

com.badlogic.gdx.scenes.scene2d.ui
Class ScrollPane

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.Group
          extended by com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
All Implemented Interfaces:
Layout

public class ScrollPane
extends Group
implements Layout

A special container that allows scrolling over its children.

Functionality

A ScrollPane can embed any Actor (and Widget or Table for that matter) and provide scrolling functionality in case the embedded Actor is bigger than the scroll pane itself. The scroll pane will automatically decide whether it needs a vertical and/or horizontal scroll handle based on the contained Actor's size with respect to the scroll pane's own size.

Note: do not use any of the Group.addActor(Actor) or Group.removeActor(Actor) methods with this class! The embedded widget is specified at construction time or via setWidget(Actor). *

Layout

The (preferred) width and height of a scroll pane is determined by the size passed to its constructor. The contained Actor will be positioned in such a way that it's top left corner will coincide with the scroll pane's corner when the vertical and horizontal scroll handles are at their minimum position.

Style

A ScrollPane is a Group (note the comment in the functionality section!) that conditionally displays horizontal and vertical scroll bars and handles as well as the embedded Actor, clipped to the available area inside of the scroll pane. The scroll bars are NinePatch instances, the scroll handles are NinePatch instances as well. In addition a background NinePatch is displayed behind the embedded Actor. The style is defined via a ScrollPane.ScrollPaneStyle instance, which can be either done programmatically or via a Skin.

The height of the horizontal scroll bar and handle is constant and takes on the maximum NinePatch.getTotalHeight() value of the involed NinePatch instances. The width is determined automatically based on the size of the scroll pane.

The width of the vertical scroll bar and handle is constant and takes on the maximum NinePatch.getTotalWidth() value of the involed NinePatch instances. The height is determined automatically based on the size of the scroll pane.

A ScrollPane's style definition in a skin XML file should look like this:
 <scrollpane name="default" 
             background="backgroundPatch" 
             hScroll="horizontalScrollBarPatch" 
             hScrollKnob="horizontalScrollHandlePatch" 
             vScroll="verticalScrollBarPatch" 
             vScrollKnob="verticalScrollBarHandle"/>
 
 

Author:
mzechner

Nested Class Summary
static class ScrollPane.ScrollPaneStyle
          Defines a scroll pane's style, see ScrollPane.
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Group
batchTransform, children, debug, debugTexture, focusedActor, groups, immutableChildren, immutableGroups, keyboardFocusedActor, lastTouchedChild, localTransform, namesToActors, oldBatchTransform, point, scrollFocusedActor, transform, worldTransform
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, touchable, visible, width, x, y
 
Constructor Summary
ScrollPane(Actor widget, Stage stage, ScrollPane.ScrollPaneStyle style)
           
ScrollPane(Actor widget, Stage stage, ScrollPane.ScrollPaneStyle style, java.lang.String name)
           
ScrollPane(Actor widget, Stage stage, Skin skin)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
 float getMaxHeight()
           
 float getMaxWidth()
           
 float getMinHeight()
           
 float getMinWidth()
           
 float getPrefHeight()
           
 float getPrefWidth()
           
 Actor hit(float x, float y)
           
 void invalidate()
          Invalidates the layout, forcing the next call to Layout.layout() to relayout.
 void layout()
          Positions and sizes each child of this actor.
 void setHScrollAmount(float hScrollAmount)
           
 void setVScrollAmount(float vScrollAmount)
           
 void setWidget(Actor widget)
          Sets the Actor embedded in this scroll pane.
 boolean touchDown(float x, float y, int pointer)
           
 void touchDragged(float x, float y, int pointer)
           
 void touchUp(float x, float y, int pointer)
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group
act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, clear, disableDebugging, drawChild, drawChildren, enableDebugging, findActor, focus, getActors, getGroups, keyboardFocus, keyDown, keyTyped, keyUp, removeActor, removeActorRecursive, resetTransform, scrolled, scrollFocus, sortChildren, swapActor, swapActor, toChildCoordinates, touchMoved, unfocusAll, unfocusAll, updateTransform
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
action, clearActions, isMarkedToRemove, markToRemove, remove, toLocalCoordinates, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScrollPane

public ScrollPane(Actor widget,
                  Stage stage,
                  Skin skin)

ScrollPane

public ScrollPane(Actor widget,
                  Stage stage,
                  ScrollPane.ScrollPaneStyle style)

ScrollPane

public ScrollPane(Actor widget,
                  Stage stage,
                  ScrollPane.ScrollPaneStyle style,
                  java.lang.String name)
Method Detail

draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Actor
Draws the Actor. The spriteBatch is configured so that the Actor can draw in its parents coordinate system. The parent's alpha is passed to the method in order for the Actor to multiply it with its own alpha. This will allow FadeIn and other Actions to have an effect even if they are only set on the parent of the Actor.

Overrides:
draw in class Group
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

layout

public void layout()
Description copied from interface: Layout
Positions and sizes each child of this actor. Subsequent calls will not have any affect unless Layout.invalidate() is called.

Specified by:
layout in interface Layout

invalidate

public void invalidate()
Description copied from interface: Layout
Invalidates the layout, forcing the next call to Layout.layout() to relayout. If an actor is resized or otherwise changed in a way that affects its layout, Layout.invalidate() should be called.

Specified by:
invalidate in interface Layout

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout

getMinWidth

public float getMinWidth()
Specified by:
getMinWidth in interface Layout

getMinHeight

public float getMinHeight()
Specified by:
getMinHeight in interface Layout

getMaxWidth

public float getMaxWidth()
Specified by:
getMaxWidth in interface Layout

getMaxHeight

public float getMaxHeight()
Specified by:
getMaxHeight in interface Layout

touchDown

public boolean touchDown(float x,
                         float y,
                         int pointer)
Overrides:
touchDown in class Group

touchUp

public void touchUp(float x,
                    float y,
                    int pointer)
Overrides:
touchUp in class Group

touchDragged

public void touchDragged(float x,
                         float y,
                         int pointer)
Overrides:
touchDragged in class Group

hit

public Actor hit(float x,
                 float y)
Overrides:
hit in class Group

setVScrollAmount

public void setVScrollAmount(float vScrollAmount)

setHScrollAmount

public void setHScrollAmount(float hScrollAmount)

setWidget

public void setWidget(Actor widget)
Sets the Actor embedded in this scroll pane.

Parameters:
widget - the Actor

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)