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:
Button, CheckBox, ComboBox, Image, ImageButton, ImageToggleButton, Label, List, Slider, TextField, ToggleButton

public abstract class Widget
extends Actor
implements Layout

Base class for all UI widgets. A widget implements the Layout interface which has a couple of features.

A widget has a preferred width and height which it will use if possible, e.g. if it is not in a Table (Pane, Window) or a SplitPane or a ScrollPane. In case it is contained in one of the aforementioned containers, the preferred width and height will be used to guide the layouting mechanism employed by those containers.

A widget can be invalidated, e.g. by a Container changing its available space in the layout, in which case it will layout itself at the next oportunity to do so.

Invalidation can also be triggered manually via a call to invalidate() or invalidateHierarchy(). The former will tell the Widget to only invalidate itself. The later will also invalidate all the widget's parents. The later mechanism is used in case the widget was modified and the container it is contained in must relayout itself due to this modification as well.

Author:
mzechner

Field Summary
protected  boolean invalidated
           
 float prefHeight
           
 float prefWidth
           
 
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
Widget()
          Creates a new widget without a name or preferred size.
Widget(java.lang.String name, float prefWidth, float prefHeight)
          Creates a new widget with the preferred width and height
 
Method Summary
 float getPrefHeight()
           
 float getPrefWidth()
           
 Actor hit(float x, float y)
           
 void invalidate()
          Invalidates this widget, causing it to relayout itself at the next oportunity.
 void invalidateHierarchy()
          Invalidates this widget and all its parents, causing all involved widgets to relayout themselves at the next oportunity.
 void setPrefSize(int prefWidth, int prefHeight)
          Sets the preferred width and height of this widget.
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, draw, isMarkedToRemove, keyDown, keyTyped, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchDown, touchDragged, touchMoved, touchUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.badlogic.gdx.scenes.scene2d.Layout
layout
 

Field Detail

prefWidth

public float prefWidth

prefHeight

public float prefHeight

invalidated

protected boolean invalidated
Constructor Detail

Widget

public Widget()
Creates a new widget without a name or preferred size.


Widget

public Widget(java.lang.String name,
              float prefWidth,
              float prefHeight)
Creates a new widget with the preferred width and height

Parameters:
name - the name
prefWidth - the preferred width
prefHeight - the preferred height
Method Detail

getPrefWidth

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

getPrefHeight

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

invalidate

public void invalidate()
Invalidates this widget, causing it to relayout itself at the next oportunity.

Specified by:
invalidate in interface Layout

invalidateHierarchy

public void invalidateHierarchy()
Invalidates this widget and all its parents, causing all involved widgets to relayout themselves at the next oportunity.


hit

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

setPrefSize

public void setPrefSize(int prefWidth,
                        int prefHeight)
Sets the preferred width and height of this widget. Invalidates all parents.

Parameters:
prefWidth - the preferred width
prefHeight - the preferred height

libgdx API

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