libgdx API

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

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.ui.Widget
All Implemented Interfaces:
Layout
Direct Known Subclasses:
Image, Label, List, SelectBox, Slider, TextField

public abstract class Widget
extends Actor
implements Layout

An Actor that participates in layout and provides a minimum, preferred, and maximum size.

The default preferred size of a widget is 0 and this is almost always overridden by a subclass. The default minimum size returns the preferred size, so a subclass may choose to return 0 if it wants to allow itself to be sized smaller. The default maximum size is 0, which means no maximum size.

See Layout for details on how a widget should participate in layout. A widget's mutator methods should call invalidate() or invalidateHierarchy() as needed.

Author:
mzechner, Nathan Sweet

Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, stage, touchable, visible, width, x, y
 
Constructor Summary
Widget()
          Creates a new widget without a name.
Widget(java.lang.String name)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.
 float getMaxHeight()
           
 float getMaxWidth()
           
 float getMinHeight()
           
 float getMinWidth()
           
 float getPrefHeight()
           
 float getPrefWidth()
           
 Actor hit(float x, float y)
           
 void invalidate()
          Invalidates this actor's layout, causing Layout.layout() to be called the next time Layout.validate() is called.
 void invalidateHierarchy()
          Invalidates this actor and all its parents, calling Layout.invalidate() on all involved actors.
 void layout()
          Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child and calls Layout.invalidate() and then Layout.validate() on each one.
 boolean needsLayout()
          Returns true if the widget's layout has been invalidated.
 void pack()
          Sizes this actor to its preferred width and height and, if its size was changed, causes the actor to be laid out by calling Layout.invalidate() and then Layout.validate().
 void setFillParent(boolean fillParent)
          If true, this actor will be sized to the parent in Layout.validate().
static void toScreenCoordinates(Actor actor, Vector2 point)
          This modifies the specified point in the actor's coordinates to be in the stage's coordinates.
 boolean touchDown(float x, float y, int pointer)
           
 void touchDragged(float x, float y, int pointer)
           
 void touchUp(float x, float y, int pointer)
           
 void validate()
          Ensures the actor has been laid out.
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, getStage, isMarkedToRemove, keyDown, keyTyped, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Widget

public Widget()
Creates a new widget without a name.


Widget

public Widget(java.lang.String name)
Method Detail

getMinWidth

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

getMinHeight

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

getPrefWidth

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

getPrefHeight

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

getMaxWidth

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

getMaxHeight

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

invalidate

public void invalidate()
Description copied from interface: Layout
Invalidates this actor's layout, causing Layout.layout() to be called the next time Layout.validate() is called. This should be done when state changes in the actor that requires a layout but does not change the minimum, preferred, maximum, or actual size of the actor (meaning it does not affect the parent actor's layout).

Specified by:
invalidate in interface Layout

validate

public void validate()
Description copied from interface: Layout
Ensures the actor has been laid out. Calls Layout.layout() if Layout.invalidate() has called since the last time Layout.validate() was called, or if the actor otherwise needs to be laid out. This method is usually called in Actor.draw(SpriteBatch, float) before drawing is performed.

Specified by:
validate in interface Layout

needsLayout

public boolean needsLayout()
Returns true if the widget's layout has been invalidated.


invalidateHierarchy

public void invalidateHierarchy()
Description copied from interface: Layout
Invalidates this actor and all its parents, calling Layout.invalidate() on all involved actors. This method should be called when state changes in the actor that affects the minimum, preferred, maximum, or actual size of the actor (meaning it potentially affects the parent actor's layout).

Specified by:
invalidateHierarchy in interface Layout

pack

public void pack()
Description copied from interface: Layout
Sizes this actor to its preferred width and height and, if its size was changed, causes the actor to be laid out by calling Layout.invalidate() and then Layout.validate().

Generally this method should not be called in a constructor because it calls Layout.layout(), which means a subclass would have layout() called before the subclass' constructor. Instead, in a constructor simply set the actors width and height to Layout.getPrefWidth() and Layout.getPrefHeight(). This allows the actor to have a size at construction time for more convenient use outside of a Table.

Specified by:
pack in interface Layout

setFillParent

public void setFillParent(boolean fillParent)
Description copied from interface: Layout
If true, this actor will be sized to the parent in Layout.validate(). If the parent is the stage, the actor will be sized to the stage.

Specified by:
setFillParent in interface Layout

draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

Specified by:
draw in class Actor
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

hit

public Actor hit(float x,
                 float y)
Specified by:
hit in class Actor

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 and calls Layout.invalidate() and then Layout.validate() on each one. Usually this should not be called directly, instead Layout.validate() should be used.

Specified by:
layout in interface Layout

touchDown

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

touchUp

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

touchDragged

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

toScreenCoordinates

public static void toScreenCoordinates(Actor actor,
                                       Vector2 point)
This modifies the specified point in the actor's coordinates to be in the stage's coordinates. Note this method will ONLY work properly for screen aligned, unrotated, unscaled actors!


libgdx API

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