Table of Contents

Class Button

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

A button element for use inside of a UiSystem. A button element can be pressed, hovered over and that can be disabled.

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

Constructors

Button(Anchor, Vector2)

Creates a new button with the given settings and no text or tooltip.

public Button(Anchor anchor, Vector2 size)

Parameters

anchor Anchor

The button's anchor

size Vector2

The button's size

Button(Anchor, Vector2, TextCallback, TextCallback)

Creates a new button with the given settings

public Button(Anchor anchor, Vector2 size, Paragraph.TextCallback textCallback = null, Paragraph.TextCallback tooltipTextCallback = null)

Parameters

anchor Anchor

The button's anchor

size Vector2

The button's size

textCallback Paragraph.TextCallback

The text that should be displayed on the button

tooltipTextCallback Paragraph.TextCallback

The text that should be displayed in a Tooltip when hovering over this button

Button(Anchor, Vector2, string, string)

Creates a new button with the given settings

public Button(Anchor anchor, Vector2 size, string text = null, string tooltipText = null)

Parameters

anchor Anchor

The button's anchor

size Vector2

The button's size

text string

The text that should be displayed on the button

tooltipText string

The text that should be displayed in a Tooltip when hovering over this button

Fields

AutoDisableCondition

An optional function that can be used to modify the result of IsDisabled automatically based on a user-defined condition. This removes the need to disable a button based on a condition in OnUpdated or manually. Note that, if IsDisabled's underlying value is set to true using IsDisabled, this function's result will be ignored.

public Func<Button, bool> AutoDisableCondition

Field Value

Func<Button, bool>

CanSelectDisabled

Whether this button 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

DisabledColor

The color that the button uses for drawing when it IsDisabled

public StyleProp<Color> DisabledColor

Field Value

StyleProp<Color>

DisabledTexture

The texture that the button 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 the button uses for drawing while being moused over

public StyleProp<Color> HoveredColor

Field Value

StyleProp<Color>

HoveredTexture

The texture that the button uses while being moused over. If this is null, it uses its default Texture.

public StyleProp<NinePatch> HoveredTexture

Field Value

StyleProp<NinePatch>

NormalColor

The color that the button draws its texture with

public StyleProp<Color> NormalColor

Field Value

StyleProp<Color>

Text

The Paragraph of text that is displayed on the button. Note that this is only nonnull by default if the constructor was passed a nonnull text.

public Paragraph Text

Field Value

Paragraph

Texture

The button's texture

public StyleProp<NinePatch> Texture

Field Value

StyleProp<NinePatch>

Tooltip

The Tooltip that is displayed when hovering over the button. Note that this is only nonnull by default if the constructor was passed a nonnull tooltip text.

public Tooltip Tooltip

Field Value

Tooltip

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

IsDisabled

Set this property to true to mark the button as disabled. A disabled button cannot be moused over, selected or pressed. If this value changes often, consider using AutoDisableCondition.

public virtual bool IsDisabled { get; set; }

Property Value

bool

TruncateTextIfLong

Whether this button's Text should be truncated if it exceeds this button's width. Defaults to false.

public bool TruncateTextIfLong { get; set; }

Property Value

bool

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