Class SliderControl
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
A slider control that allows users to select a value from a range by dragging a thumb along a track. Supports both horizontal and vertical orientations, keyboard and mouse interaction, and optional value and min/max labels.
public class SliderControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable
- Inheritance
-
SliderControl
- Implements
- Inherited Members
- Extension Methods
Constructors
SliderControl()
Initializes a new instance of the SliderControl class.
public SliderControl()
Properties
BackgroundColor
Gets or sets the background color.
public Color? BackgroundColor { get; set; }
Property Value
CanFocusWithMouse
Whether this control can receive focus via mouse clicks
public bool CanFocusWithMouse { get; }
Property Value
CanReceiveFocus
Whether this control can receive focus
public bool CanReceiveFocus { get; }
Property Value
Container
Gets or sets the parent container that hosts this control.
public override IContainer? Container { get; set; }
Property Value
ContentWidth
Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.
public override int? ContentWidth { get; }
Property Value
- int?
FilledTrackColor
Gets or sets the color of the filled track portion.
public Color? FilledTrackColor { get; set; }
Property Value
FocusedThumbColor
Gets or sets the color of the thumb indicator when focused.
public Color? FocusedThumbColor { get; set; }
Property Value
HasFocus
public bool HasFocus { get; }
Property Value
IsDragging
Gets whether the slider is currently being dragged.
public bool IsDragging { get; }
Property Value
IsEnabled
Gets or sets whether the slider is enabled and can be interacted with.
public bool IsEnabled { get; set; }
Property Value
LargeStep
Gets or sets the large step increment used for Page Up/Down and Shift+Arrow.
public double LargeStep { get; set; }
Property Value
MaxValue
Gets or sets the maximum value of the slider range.
public double MaxValue { get; set; }
Property Value
MinValue
Gets or sets the minimum value of the slider range.
public double MinValue { get; set; }
Property Value
Orientation
Gets or sets the slider orientation.
public SliderOrientation Orientation { get; set; }
Property Value
ShowMinMaxLabels
Gets or sets whether to show the min and max value labels at the track ends.
public bool ShowMinMaxLabels { get; set; }
Property Value
ShowValueLabel
Gets or sets whether to show the current value label next to the slider.
public bool ShowValueLabel { get; set; }
Property Value
Step
Gets or sets the step increment. Must be at least SliderMinStep.
public double Step { get; set; }
Property Value
ThumbColor
Gets or sets the color of the thumb indicator.
public Color? ThumbColor { get; set; }
Property Value
TrackColor
Gets or sets the color of the unfilled track portion.
public Color? TrackColor { get; set; }
Property Value
Value
Gets or sets the current slider value. Clamped to [MinValue, MaxValue] and snapped to Step.
public double Value { get; set; }
Property Value
ValueLabelFormat
Gets or sets the format string for the value label (default: "F0").
public string ValueLabelFormat { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; }
Property Value
Methods
GetLogicalContentSize()
Gets the logical size of the control's content without rendering.
public override Size GetLogicalContentSize()
Returns
- Size
The size representing the content's natural dimensions.
MeasureDOM(LayoutConstraints)
Measures the control's desired size given the available constraints.
public override LayoutSize MeasureDOM(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraintsThe layout constraints (min/max width/height).
Returns
- LayoutSize
The desired size of the control.
OnDisposing()
Called during Dispose() before Container is set to null.
Override to perform control-specific cleanup (null events, close portals, clear data, etc.).
protected override void OnDisposing()
PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)
Paints the control's content directly to a CharacterBuffer.
public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)
Parameters
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
ProcessKey(ConsoleKeyInfo)
Processes a keyboard input event.
public bool ProcessKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfoThe key information for the pressed key.
Returns
- bool
True if the key was handled by this control; otherwise, false.
ProcessMouseEvent(MouseEventArgs)
Processes a mouse event for this control
public bool ProcessMouseEvent(MouseEventArgs args)
Parameters
argsMouseEventArgsMouse event arguments with control-relative coordinates
Returns
- bool
True if the event was handled and should not propagate further
Events
MouseClick
Event fired when the control is clicked
public event EventHandler<MouseEventArgs>? MouseClick
Event Type
MouseDoubleClick
Event fired when the control is double-clicked
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Event fired when the mouse enters the control area
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Event fired when the mouse leaves the control area
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Event fired when the mouse moves over the control
public event EventHandler<MouseEventArgs>? MouseMove
Event Type
MouseRightClick
Event fired when the control is right-clicked (Button3)
public event EventHandler<MouseEventArgs>? MouseRightClick
Event Type
ValueChanged
Occurs when the slider value changes.
public event EventHandler<double>? ValueChanged