Slider
namespace Griff.Scenes;
public sealed class Slider : Component, IDrawableA bar the player drags (or moves with the arrow keys, D-pad or stick once picked) to choose a number between Min and Max. Options menus need no code: set Setting to a volume and the slider changes it, and the game remembers it next time. SaveAs keeps any other choice (a difficulty) in Game.SaveData.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Background
Section titled “Background”public Color Background { get; set; }The color of the track past the handle.
BackgroundImage
Section titled “BackgroundImage”public string? BackgroundImage { get; set; }A picture for the track behind the fill, shown whole, instead of a plain color; tinted by Background.
BackgroundSlice
Section titled “BackgroundSlice”public float BackgroundSlice { get; set; }For a track that stretches (nine-slice), like Slice: how much of the BackgroundImage, from 0 to 0.5 of its width and height, is border at each edge. Its corners then keep their shape however long the slider is. 0 stretches the whole picture.
BackgroundSliceSize
Section titled “BackgroundSliceSize”public float BackgroundSliceSize { get; set; }With BackgroundSlice: how big the border is drawn, in world units (never more than half the slider).
public Color Fill { get; set; }The color of the part up to the handle.
FillImage
Section titled “FillImage”public string? FillImage { get; set; }A picture for the part up to the handle instead of a plain color, e.g. “Sprites/slider_fill.png”: laid over the whole slider and shown only as far as it’s set, cut off there rather than squeezed, and tinted by Fill (white shows the picture as it is).
Fraction
Section titled “Fraction”public float Fraction { get; }How far along it is, from 0 at Min to 1 at Max.
IsDragging
Section titled “IsDragging”public bool IsDragging { get; }True while it’s being dragged with the mouse.
IsFocused
Section titled “IsFocused”public bool IsFocused { get; }True while the keyboard or a gamepad has picked it (see IsFocused); left and right change it.
IsHovered
Section titled “IsHovered”public bool IsHovered { get; }True while the mouse is over it.
public Color Knob { get; set; }The handle at the end of the filled part. Transparent for none.
KnobImage
Section titled “KnobImage”public string? KnobImage { get; set; }A picture for the handle instead of a plain rectangle, e.g. “Sprites/slider_knob.png”: drawn at the end of the filled part in the handle’s usual box (half as wide as the slider is high, one and a half times as tall), tinted by Knob. A transparent Knob still hides it.
public float Max { get; set; }The value at its right end.
public float Min { get; set; }The value at its left end.
Navigable
Section titled “Navigable”public bool Navigable { get; set; }Whether the arrow keys, D-pad and stick can move to it, like Navigable.
public int Order { get; set; }Higher draws on top, like Order.
SaveAs
Section titled “SaveAs”public string? SaveAs { get; set; }A name to keep the value under in Game.SaveData, e.g. “difficulty”: it’s saved whenever it changes and comes back next time. Read it from scripts with Game.SaveData.GetFloat("difficulty").
Setting
Section titled “Setting”public GameSetting Setting { get; set; }A setting of the game it changes, like the music volume. While set, the slider always shows that setting: a volume from 0 to 1 fills it from Min to Max, so a slider from 0 to 10 works too. An offset is in milliseconds, which is the slider’s value.
public Vector2 Size { get; set; }World units before the transform’s scale, centered on the entity. It’s dragged along its width.
public string? Sound { get; set; }A sound played as the value changes, e.g. “Sounds/blip.wav”: with the sound volume, you hear how loud it is.
public float Step { get; set; }How far one press of an arrow key moves it, and what dragging snaps to: 0.1 picks tenths. 0 doesn’t snap, and the keys move it a tenth of the way.
public float Value { get; set; }Where it’s set, from Min to Max: a text inside it can show it (“{0:0} ms”).
Methods
Section titled “Methods”public Color Shade(Color color)The color to draw a color part in while it’s under the mouse, picked or dragged.
public float Snap(float value)value kept between Min and Max and snapped to Step.
Events
Section titled “Events”Changed
Section titled “Changed”public event Action<Slider>? ChangedRaised when the player changes the value.