Class Button
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
- 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
AnchorThe button's anchor
size
Vector2The 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
AnchorThe button's anchor
size
Vector2The button's size
textCallback
Paragraph.TextCallbackThe text that should be displayed on the button
tooltipTextCallback
Paragraph.TextCallbackThe 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
AnchorThe button's anchor
size
Vector2The button's size
text
stringThe text that should be displayed on the button
tooltipText
stringThe 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
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
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
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
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
Texture
The button's texture
public StyleProp<NinePatch> Texture
Field Value
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
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
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
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
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
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
GameTimeThe game's time
batch
SpriteBatchThe sprite batch to use for drawing
alpha
floatThe alpha to draw this element and its children with
context
SpriteBatchContextThe 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
UiStyleThe new style