Class Button
A push button with a text label. Its look comes from its normal, hover, clicked and focused states.
public class Button : InteractiveControl, IUpdateable, IEquatable<IUpdateable>, IDrawable, IIdentifiable<Guid>, IEquatable<IDrawable>, IDisposable
- Inheritance
-
Button
- Implements
- Inherited Members
Constructors
Button(ILogger, View, string)
Creates a button in view.
public Button(ILogger logger, View view, string id = null)
Parameters
Properties
Color
The tint applied to the button's texture. White, the default, leaves it as it is.
public Color Color { get; set; }
Property Value
Command
The command run when the button is clicked, or activated with Enter or Space while it has focus.
public ICommand Command { get; set; }
Property Value
DisabledOpacity
How much of its normal opacity a disabled button keeps.
public float DisabledOpacity { get; set; }
Property Value
Remarks
A single fade rather than a whole Disabled BSGameLib.UI.Controls.ControlState alongside Normal/Hover/Clicked/Focused: a state would have to be defined by every theme and every style before it showed anything, so an unthemed button -- and every existing theme -- would go on looking live while being dead. Fading works out of the box and a theme can still override the number.
Font
The font the text is drawn in. Set by LoadContent().
public IFont Font { get; }
Property Value
FontColor
The colour of the text in the normal state.
public Color FontColor { get; set; }
Property Value
FontFile
The font to draw the text in: a font file, or the name of a built-in font. Null for the built-in default.
public string FontFile { get; set; }
Property Value
FontSize
The size of the text, in pixels. Zero draws the font at its own size.
public float FontSize { get; set; }
Property Value
LetterSpacing
Extra space between letters, in pixels.
public float LetterSpacing { get; set; }
Property Value
RequiresRawKeyboard
Whether the button takes keys directly, so that Enter and Space reach it when it has focus.
public override bool RequiresRawKeyboard { get; }
Property Value
SuppressesDefaultButton
Whether a focused button keeps Enter for itself, so the view's default button does not also run.
public override bool SuppressesDefaultButton { get; }
Property Value
Text
The text shown on the button.
public string Text { get; set; }
Property Value
Texture
The texture drawn for the button's current state. Set by LoadContent() and when the state changes.
public ITexture Texture { get; }
Property Value
Methods
Draw(IGameTime)
Draws the button in its current state, faded while it is Disabled.
public override void Draw(IGameTime gameTime)
Parameters
gameTimeIGameTime
~Button()
Unsubscribes the button's own event handlers.
protected ~Button()
GainFocus()
Shows the focused state when the button gets focus.
public override void GainFocus()
LoadContent()
Loads the font, and the built-in textures for each state that sets neither a texture nor a fill or border.
public override void LoadContent()
LoseFocus()
Shows the hover state if the pointer is still over the button, or the normal state otherwise.
public override void LoseFocus()
Update(IGameTime)
Does nothing by default. Override it to advance the component's state each frame.
public override void Update(IGameTime gameTime)
Parameters
gameTimeIGameTime