Skip to content

Class Slider

Definition

Namespace: StardewUI.Widgets
Assembly: StardewUI.dll

A horizontal track with draggable thumb (button) for choosing a numeric value in a range.

[StardewUI.GenerateDescriptor]
public class Slider : StardewUI.Widgets.ComponentView

Inheritance
ObjectDecoratorView<T>ComponentView<T>ComponentView ⇦ Slider

Members

Constructors

Name Description
Slider()

Properties

Name Description
ActualBounds The bounds of this view relative to the origin (0, 0).
(Inherited from DecoratorView<T>)
BackgroundSprite Background or track sprite, if not using the default.
ClipOrigin Origin position for the ClipSize.
(Inherited from DecoratorView<T>)
ClipSize Size of the clipping rectangle, outside which content will not be displayed.
(Inherited from DecoratorView<T>)
ContentBounds The true bounds of this view's content; i.e. ActualBounds excluding margins.
(Inherited from DecoratorView<T>)
FloatingBounds Contains the bounds of all floating elements in this view tree, including the current view and all descendants.
(Inherited from DecoratorView<T>)
Interval The interval of which Value should be a multiple. Affects which values will be hit while dragging.
IsFocusable Whether or not the view can receive controller focus, i.e. the stick/d-pad controlled cursor can move to this view. Not generally applicable for mouse controls.
(Inherited from DecoratorView<T>)
Layout The current layout parameters, which determine how Measure(Vector2) will behave.
(Inherited from DecoratorView<T>)
Max The maximum value allowed for Value.
Min The minimum value allowed for Value.
Name Simple name for this view, used in log/debug output; does not affect behavior.
(Inherited from DecoratorView<T>)
Opacity Opacity (alpha level) of the view.
(Inherited from DecoratorView<T>)
OuterSize The true computed layout size resulting from a single Measure(Vector2) pass.
(Inherited from DecoratorView<T>)
PointerEventsEnabled Whether this view should receive pointer events like Click or Drag.
(Inherited from DecoratorView<T>)
PointerStyle Pointer style to use when this view is hovered.
(Inherited from DecoratorView<T>)
ScrollWithChildren If set to an axis, specifies that when any child of the view is scrolled into view (using ScrollIntoView(IEnumerable<ViewChild>, Vector2)), then this entire view should be scrolled along with it.
(Inherited from DecoratorView<T>)
Tags The user-defined tags for this view.
(Inherited from DecoratorView<T>)
ThumbSize Override for the thumb/button size, recommended when using a custom ThumbSprite.
ThumbSprite Sprite for the thumb/button, if not using the default.
Tooltip Tooltip data to display on hover, if any.
(Inherited from DecoratorView<T>)
TrackWidth Width of the track bar.
Transform Local transformation to apply to this view, including any children and floating elements.
(Inherited from DecoratorView<T>)
TransformOrigin Relative origin position for any Transform on this view.
(Inherited from DecoratorView<T>)
Value The current value.
ValueColor Color of the value text to render, if overriding the default text color.
ValueFormat Specifies how to format the Value in the label text.
View (Inherited from ComponentView<T>)
Visibility Drawing visibility for this view.
(Inherited from DecoratorView<T>)
ZIndex Z order for this view within its direct parent. Higher indices draw later (on top).
(Inherited from DecoratorView<T>)

Methods

Name Description
ContainsPoint(Vector2) Checks if a given point, relative to the view's origin, is within its bounds.
(Inherited from DecoratorView<T>)
CreateView() Creates and returns the root view.
(Overrides ComponentView<T>.CreateView())
Dispose() (Inherited from DecoratorView<T>)
Draw(ISpriteBatch) Draws the content for this view.
(Inherited from DecoratorView<T>)
FocusSearch(Vector2, Direction) Finds the next focusable component in a given direction that does not overlap with a current position.
(Overrides DecoratorView<T>.FocusSearch(Vector2, Direction))
GetChildAt(Vector2, Boolean, Boolean) Finds the child at a given position.
(Inherited from DecoratorView<T>)
GetChildPosition(IView) Computes or retrieves the position of a given direct child.
(Inherited from DecoratorView<T>)
GetChildren(Boolean) Gets the current children of this view.
(Inherited from DecoratorView<T>)
GetChildrenAt(Vector2) Finds all children at a given position.
(Inherited from DecoratorView<T>)
GetDefaultFocusChild() Gets the direct child that should contain cursor focus when a menu or overlay containing this view is first opened.
(Inherited from DecoratorView<T>)
HasOutOfBoundsContent() Checks if the view has content or elements that are all or partially outside the ActualBounds.
(Inherited from DecoratorView<T>)
IsDirty() Checks whether or not the view is dirty - i.e. requires a new layout with a full Measure(Vector2).
(Inherited from DecoratorView<T>)
IsVisible(Vector2?) Checks if the view is effectively visible, i.e. if it has anything to draw.
(Inherited from DecoratorView<T>)
Measure(Vector2) Performs layout on this view, updating its OuterSize, ActualBounds and ContentBounds, and arranging any children in their respective positions.
(Inherited from DecoratorView<T>)
OnButtonPress(ButtonEventArgs) Called when a button press is received while this view is in the focus path.
(Inherited from DecoratorView<T>)
OnButtonRepeat(ButtonEventArgs) Called when a button press is first received, and at recurring intervals thereafter, for as long as the button is held and this view remains in the focus path.
(Inherited from DecoratorView<T>)
OnClick(ClickEventArgs) Called when a click is received within this view's bounds.
(Inherited from DecoratorView<T>)
OnDrag(PointerEventArgs) Called when the view is being dragged (mouse moved while left button held).
(Inherited from DecoratorView<T>)
OnDrop(PointerEventArgs) Called when the mouse button is released after at least one OnDrag(PointerEventArgs).
(Inherited from DecoratorView<T>)
OnLayout() Runs whenever layout occurs as a result of the UI elements changing.
(Overrides DecoratorView<T>.OnLayout())
OnPointerMove(PointerMoveEventArgs) Called when a pointer movement related to this view occurs.
(Inherited from DecoratorView<T>)
OnPropertyChanged(PropertyChangedEventArgs) Raises the PropertyChanged event.
(Inherited from DecoratorView<T>)
OnPropertyChanged(string) Raises the PropertyChanged event.
(Inherited from DecoratorView<T>)
OnUpdate(TimeSpan) Runs on every update tick.
(Inherited from DecoratorView<T>)
OnWheel(WheelEventArgs) Called when a wheel event is received within this view's bounds.
(Inherited from DecoratorView<T>)
RegisterDecoratedProperty<TValue>(DecoratedProperty<T, TValue>) Registers a DecoratedProperty<T, TValue>.
(Inherited from DecoratorView<T>)
ScrollIntoView(IEnumerable<ViewChild>, Vector2) Attempts to scroll the specified target into view, including all of its ancestors, if not fully in view.
(Inherited from DecoratorView<T>)

Events

Name Description
ButtonPress Event raised when any button on any input device is pressed.
(Inherited from DecoratorView<T>)
ButtonRepeat Event raised when a button is being held while the view is in focus, and has been held long enough since the initial ButtonPress or the previous ButtonRepeat to trigger a repeated press.
(Inherited from DecoratorView<T>)
Click Event raised when the view receives a click initiated from any button.
(Inherited from DecoratorView<T>)
Drag Event raised when the view is being dragged using the mouse.
(Inherited from DecoratorView<T>)
DragEnd Event raised when mouse dragging is stopped, i.e. when the button is released. Always raised after the last Drag, and only once per drag operation.
(Inherited from DecoratorView<T>)
DragStart Event raised when mouse dragging is first activated. Always raised before the first Drag, and only once per drag operation.
(Inherited from DecoratorView<T>)
LeftClick Event raised when the view receives a click initiated from the left mouse button, or the controller's action button (A).
(Inherited from DecoratorView<T>)
PointerEnter Event raised when the pointer enters the view.
(Inherited from DecoratorView<T>)
PointerLeave Event raised when the pointer exits the view.
(Inherited from DecoratorView<T>)
PointerMove Event raised when the pointer moves within the view.
(Inherited from DecoratorView<T>)
PropertyChanged (Inherited from DecoratorView<T>)
RightClick Event raised when the view receives a click initiated from the right mouse button, or the controller's tool-use button (X).
(Inherited from DecoratorView<T>)
ValueChange Event raised when the Value changes.
Wheel Event raised when the scroll wheel moves.
(Inherited from DecoratorView<T>)

Details

Constructors

Slider()

public Slider();

Properties

BackgroundSprite

Background or track sprite, if not using the default.

public StardewUI.Graphics.Sprite BackgroundSprite { get; set; }
Property Value

Sprite


Interval

The interval of which Value should be a multiple. Affects which values will be hit while dragging.

public float Interval { get; set; }
Property Value

Single


Max

The maximum value allowed for Value.

public float Max { get; set; }
Property Value

Single


Min

The minimum value allowed for Value.

public float Min { get; set; }
Property Value

Single


ThumbSize

Override for the thumb/button size, recommended when using a custom ThumbSprite.

public Microsoft.Xna.Framework.Vector2? ThumbSize { get; set; }
Property Value

Nullable<Vector2>


ThumbSprite

Sprite for the thumb/button, if not using the default.

public StardewUI.Graphics.Sprite ThumbSprite { get; set; }
Property Value

Sprite


TrackWidth

Width of the track bar.

public float TrackWidth { get; set; }
Property Value

Single


Value

The current value.

public float Value { get; set; }
Property Value

Single


ValueColor

Color of the value text to render, if overriding the default text color.

public Microsoft.Xna.Framework.Color? ValueColor { get; set; }
Property Value

Nullable<Color>


ValueFormat

Specifies how to format the Value in the label text.

public Func<System.Single, string> ValueFormat { get; set; }
Property Value

Func<Single, string>


Methods

CreateView()

Creates and returns the root view.

protected override StardewUI.IView CreateView();
Returns

IView


FocusSearch(Vector2, Direction)

Finds the next focusable component in a given direction that does not overlap with a current position.

public override StardewUI.Input.FocusSearchResult FocusSearch(Microsoft.Xna.Framework.Vector2 position, StardewUI.Direction direction);
Parameters

position   Vector2
The current cursor position, relative to this view. May have dimensions that are negative or outside the view bounds, indicating that the cursor is not currently within the view.

direction   Direction
The direction of cursor movement.

Returns

FocusSearchResult

The next focusable view reached by moving in the specified direction, or null if there are no focusable descendants that are possible to reach in that direction.

Remarks

If position is out of bounds, it does not necessarily mean that the view should return null; the expected result depends on the direction also. The base case is when the focus position is already in bounds, and in this case a view should return whichever view can be reached by moving from the edge of that view along a straight line in the specified direction. However, focus search is recursive and the result should reflect the "best" candidate for focus if the cursor were to move into this view's bounds. For example, in a 1D horizontal layout the rules might be:

  • If the direction is East, and the position's X value is negative, then the result should the leftmost focusable child, regardless of Y value.
  • If the direction is South, and the X position is within the view's horizontal bounds, and the Y value is negative or greater than the view's height, then result should be whichever child intersects with that X position.
  • If the direction is West and the X position is negative, or the direction is East and the X position is greater than the view's width, then the result should be null as there is literally nothing the view knows about in that direction.

There are no strict rules for how a view performs focus search, but in general it is assumed that a view implementation understands its own layout and can accommodate accordingly; for example, a grid would follow essentially the same rules as our "list" example above, with additional considerations for navigating rows. "Ragged" 2D layouts might have complex rules requiring explicit neighbors, and therefore are typically easier to implement as nested lanes.


OnLayout()

Runs whenever layout occurs as a result of the UI elements changing.

protected override void OnLayout();

Events

ValueChange

Event raised when the Value changes.

public event EventHandler<System.EventArgs>? ValueChange;
Event Type

EventHandler<EventArgs>