Table of Contents

Class Checkbox

Namespace
MLEM.Ui.Elements
Assembly
MLEM.Ui.dll

A checkbox element to use inside of a UiSystem. A checkbox can be checked by pressing it and will stay checked until it is pressed again. For a checkbox that causes neighboring checkboxes to be deselected automatically, use RadioButton.

public class Checkbox : Element, IGenericDataHolder, IDisposable
Inheritance
Checkbox
Implements
Derived
Inherited Members
Extension Methods

Constructors

Checkbox(Anchor, Vector2, string, bool)

Creates a new checkbox with the given settings

public Checkbox(Anchor anchor, Vector2 size, string label, bool defaultChecked = false)

Parameters

anchor Anchor

The checkbox's anchor

size Vector2

The checkbox's size

label string

The checkbox's label text

defaultChecked bool

The default value of Checked

Fields

CanSelectDisabled

Whether this checkbox should be able to be selected even if it IsDisabled. If this is true, CanBeSelected will be able to return true even if IsDisabled is true.

public bool CanSelectDisabled

Field Value

bool

Checkmark

The texture that is rendered on top of this checkbox when it is Checked.

public StyleProp<TextureRegion> Checkmark

Field Value

StyleProp<TextureRegion>

DisabledColor

The color that the checkbox uses for drawing when it IsDisabled.

public StyleProp<Color> DisabledColor

Field Value

StyleProp<Color>

DisabledTexture

The texture that the checkbox uses when it IsDisabled. If this is null, it uses its default Texture.

public StyleProp<NinePatch> DisabledTexture

Field Value

StyleProp<NinePatch>

HoveredColor

The color that this checkbox uses for drawing when it is hovered.

public StyleProp<Color> HoveredColor

Field Value

StyleProp<Color>

HoveredTexture

The texture that this checkbox uses when it is hovered. If this is null, the default Texture is used.

public StyleProp<NinePatch> HoveredTexture

Field Value

StyleProp<NinePatch>

Label

The label Paragraph that displays next to this checkbox

public Paragraph Label

Field Value

Paragraph

OnCheckStateChange

An event that is invoked when this checkbox's Checked property changes

public Checkbox.CheckStateChange OnCheckStateChange

Field Value

Checkbox.CheckStateChange

Texture

The texture that this checkbox uses for drawing.

public StyleProp<NinePatch> Texture

Field Value

StyleProp<NinePatch>

Properties

CanBePressed

Set this field to false to disallow this element's OnPressed and OnSecondaryPressed events to be called.

public override bool CanBePressed { get; }

Property Value

bool

CanBeSelected

Set this field to false to disallow the element from being selected. An unselectable element is skipped by automatic navigation and its OnSelected callback will never be called.

public override bool CanBeSelected { get; }

Property Value

bool

Checked

Whether or not this checkbox is currently checked.

public bool Checked { get; set; }

Property Value

bool

IsDisabled

Set this property to true to mark the checkbox as disabled. A disabled checkbox cannot be moused over, selected or toggled.

public virtual bool IsDisabled { get; set; }

Property Value

bool

TextOffsetX

The width of the space between this checkbox and its Label

public StyleProp<float> TextOffsetX { get; set; }

Property Value

StyleProp<float>

Methods

Draw(GameTime, SpriteBatch, float, SpriteBatchContext)

Draws this element and all of its children. Override this method to draw the content of custom elements. Note that, when this is called, SpriteBatch.Begin has already been called with custom Transform etc. applied.

public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context)

Parameters

time GameTime

The game's time

batch SpriteBatch

The sprite batch to use for drawing

alpha float

The alpha to draw this element and its children with

context SpriteBatchContext

The sprite batch context to use for drawing

InitStyle(UiStyle)

Initializes this element's StyleProp<T> instances using the ui system's UiStyle.

protected override void InitStyle(UiStyle style)

Parameters

style UiStyle

The new style

SetAreaAndUpdateChildren(RectangleF)

Sets this element's Area to the given RectangleF and invokes the OnElementAreaUpdated event. This method also updates all of this element's Children's areas. Note that this method does not take into account any auto-sizing, anchoring or positioning, and so it should be used sparingly, if at all.

public override void SetAreaAndUpdateChildren(RectangleF area)

Parameters

area RectangleF
See Also