libgdx API

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

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

public class CheckBox
extends Widget

A checkbox with a label.

Functionality

A CheckBox can be either checked or unchecked. The state of the CheckBox is displayed with images representing the checked and unchecked state as well as a label, displayed to the right of the image(s). Checking/unchecking a CheckBox works by clicking either the image or the label itself, the hit area of the CheckBox is the compositum of both elements.

To get notifications about a change in state of the CheckBox one can register a CheckBox.CheckedListener with the CheckBox.

Layout

A CheckBox's (preferred) width and height is determined by the size of the bigger of the two images representing the state plus the bounding box around the (single-line) label. Both the image and the label are centered vertically. Use Widget.setPrefSize(int, int) to programmatically change the size to your liking. Note that this will not have an affect on the actual rendering, but only manipulate the hit area of the CheckBox.

Style

A CheckBox is a Widget displaying one of two TextureRegion instances representing the checked and unchecked state, as well as a label via a BitmapFont and accompanying Color. The style is defined via an instance of CheckBox.CheckBoxStyle, which can either be done programmatically or via a Skin.

A CheckBox's style definition in a skin XML file should look like this:
  <checkbox name="styleName"
            checked="checkedRegion" 
            unchecked="uncheckedRegion"
            font="fontName" 
            fontColor="fontColor"/>
  
 

Author:
mzechner

Nested Class Summary
static class CheckBox.CheckBoxStyle
          Defines a check box style, see CheckBox
static interface CheckBox.CheckedListener
          Interface for listening to check events on this check box.
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
invalidated, prefHeight, 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
CheckBox(java.lang.String text, CheckBox.CheckBoxStyle style)
           
CheckBox(java.lang.String text, Skin skin)
           
CheckBox(java.lang.String name, java.lang.String text, CheckBox.CheckBoxStyle style)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
 Actor hit(float x, float y)
           
 boolean isChecked()
           
 void layout()
          Positions and sizes each child of this actor.
 void setChecked(boolean isChecked)
          Sets whether this check box is checked or not.
 CheckBox setCheckedListener(CheckBox.CheckedListener listener)
          Sets the CheckBox.CheckedListener
 void setStyle(CheckBox.CheckBoxStyle style)
          Sets the style of this widget.
 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.ui.Widget
getPrefHeight, getPrefWidth, invalidate, invalidateHierarchy, setPrefSize
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, action, clearActions, 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

CheckBox

public CheckBox(java.lang.String text,
                Skin skin)

CheckBox

public CheckBox(java.lang.String text,
                CheckBox.CheckBoxStyle style)

CheckBox

public CheckBox(java.lang.String name,
                java.lang.String text,
                CheckBox.CheckBoxStyle style)
Method Detail

setStyle

public void setStyle(CheckBox.CheckBoxStyle style)
Sets the style of this widget. Calls Widget.invalidateHierarchy() internally.

Parameters:
style -

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.


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.

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

touchDown

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

touchUp

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

touchDragged

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

hit

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

setChecked

public void setChecked(boolean isChecked)
Sets whether this check box is checked or not. Invalidates all parents.

Parameters:
isChecked - checked or not

isChecked

public boolean isChecked()
Returns:
whether this checkbox is checked or not

setCheckedListener

public CheckBox setCheckedListener(CheckBox.CheckedListener listener)
Sets the CheckBox.CheckedListener

Parameters:
listener - the listener or null
Returns:
this CheckBox for chaining

libgdx API

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