Table of Contents

Class Slider

Namespace
BSGameLib.UI.Controls
Assembly
BSGameLib.UI.dll

A horizontal slider picking a number between Minimum and Maximum - a volume, a scale.

public class Slider : InteractiveControl, IUpdateable, IEquatable<IUpdateable>, IDrawable, IIdentifiable<Guid>, IEquatable<IDrawable>, IDisposable
Inheritance
Slider
Implements
Inherited Members

Remarks

Drawn from shapes like ProgressBar, which it looks like with a handle added: a track, the filled part up to the value, and a thumb at the value. Click anywhere on it to jump there, drag to follow the pointer (past either end, which pins it), and with focus the arrow keys step it and Home/End go to either end.

Value binds two-way: it follows the view model, and every change the player makes writes straight back, while dragging, rather than on release - a volume slider should be heard changing.

Constructors

Slider(ILogger, View, string)

Creates a slider in view.

public Slider(ILogger logger, View view, string id = null)

Parameters

logger ILogger
view View
id string

Properties

FocusColor

The handle's outline while the slider has focus.

public Color? FocusColor { get; set; }

Property Value

Color?

Fraction

0 at Minimum, 1 at Maximum.

public float Fraction { get; }

Property Value

float

LiveUpdate

Whether a drag writes its value back to the view model as it goes (the default) or only when the button is released. Arrow keys always write each step. Turn this off for a setting that is expensive to apply, or one whose applying moves the slider itself - a UI scale, which rebuilds the screen the slider is on.

public bool LiveUpdate { get; set; }

Property Value

bool

Maximum

The value at the right end. (Default: 1)

public float Maximum { get; set; }

Property Value

float

Minimum

The value at the left end. (Default: 0)

public float Minimum { get; set; }

Property Value

float

RequiresRawKeyboard

True, so that the arrow keys reach the slider when it has focus.

public override bool RequiresRawKeyboard { get; }

Property Value

bool

Step

The increment values snap to, and how far one arrow key moves it. 0, the default, means no snapping, and the arrow keys move a twentieth of the range.

public float Step { get; set; }

Property Value

float

ThumbColor

The handle. Falls back to the fill color when unset.

public Color? ThumbColor { get; set; }

Property Value

Color?

ThumbWidth

How wide the handle is. It spans the control's full height. (Default: 10)

public int ThumbWidth { get; set; }

Property Value

int

TrackColor

The full-length track behind the fill.

public Color? TrackColor { get; set; }

Property Value

Color?

TrackHeight

How tall the track is, centred in the control's height. (Default: 6)

public int TrackHeight { get; set; }

Property Value

int

Value

The value, kept within Minimum and Maximum and snapped to Step. Setting it writes the new value back to a bound view-model property.

public float Value { get; set; }

Property Value

float

Methods

Draw(IGameTime)

Draws the track, the part of it filled up to the value, the thumb and the border.

public override void Draw(IGameTime gameTime)

Parameters

gameTime IGameTime

Events

ValueChanged

Raised when Value changes, with the new value.

public event EventHandler<float> ValueChanged

Event Type

EventHandler<float>