Class ScrollbarControl
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
A standalone scrollbar control, decoupled from any single scrollable view. One ScrollbarControl can drive several views at once — the case that motivated it (issue #85) is a side-by-side diff viewer where one bar must scroll two panes together.
public class ScrollbarControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IMouseAwareControl, IWindowControl, IDisposable
- Inheritance
-
ScrollbarControl
- Implements
- Inherited Members
- Extension Methods
Remarks
Built on the shared engine in SharpConsoleUI.Helpers.Scrollbar (ScrollbarMetrics, SharpConsoleUI.Helpers.Scrollbar.ScrollbarGeometry, SharpConsoleUI.Helpers.Scrollbar.ScrollbarInput, SharpConsoleUI.Helpers.Scrollbar.ScrollbarRenderer, ScrollbarPaletteResolver) that every built-in scrolling control now shares, so this bar behaves identically to the one embedded in, say, ScrollablePanelControl.
The two events are the point of the control: ValueChanged fires on every change, including a code-set Value (conventional, INPC-consistent); UserValueChanged fires only for a change the user made through the bar (arrow, track page, thumb drag, wheel). A composite wires UserValueChanged to push the new offset to its views, and the views' own scroll events back to Value — with no echo and no guard flag needed, because a code-set Value never re-raises UserValueChanged.
Constructors
ScrollbarControl()
Initializes a new instance of the ScrollbarControl class.
public ScrollbarControl()
Properties
CanFocusWithMouse
A scrollbar cannot be focused by a mouse click either — only dragged/clicked for its own scrolling behaviour.
public bool CanFocusWithMouse { get; }
Property Value
CanReceiveFocus
A scrollbar is a bar, not a tab stop: it never takes keyboard 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?
IsActive
Gets or sets whether the bar paints itself as focused, even though it is never itself a Tab
stop. A composite that drives several sibling views sets this to true while one of
those views actually holds focus, so the bar's colour still reflects "the group is active."
public bool IsActive { get; set; }
Property Value
IsEnabled
Gets or sets whether the bar is enabled. A disabled bar dims to its unfocused colours and ignores mouse input.
public bool IsEnabled { get; set; }
Property Value
LargeChange
Gets or sets the amount Value moves for a track (page) click. Defaults to ViewportLength when never set explicitly.
public int LargeChange { get; set; }
Property Value
Maximum
Gets or sets the total length of the content being scrolled. Shrinking this re-clamps Value to the new range.
public int Maximum { get; set; }
Property Value
Orientation
Gets or sets the bar's orientation. Defaults to Vertical.
public ScrollbarOrientation Orientation { get; set; }
Property Value
ScrollbarColor
Gets or sets the track colour. When null (the default), the track uses the shared
scrollbar engine's focus-aware theme colour.
public Color? ScrollbarColor { get; set; }
Property Value
ScrollbarThumbColor
Gets or sets the thumb colour. When null (the default), the thumb uses the shared
scrollbar engine's focus-aware theme colour.
public Color? ScrollbarThumbColor { get; set; }
Property Value
SmallChange
Gets or sets the amount Value moves for an arrow click or a mouse wheel notch. Defaults to DefaultScrollWheelLines.
public int SmallChange { get; set; }
Property Value
Value
Gets or sets the current scroll offset, clamped to [0, Maximum - ViewportLength]. Every
change — including this one, set by code — raises ValueChanged. Only a change
made through the bar (arrow, track, drag, wheel) additionally raises UserValueChanged.
public int Value { get; set; }
Property Value
ViewportLength
Gets or sets the visible length of the view the bar represents. Shrinking or growing this re-clamps Value to the new range, and — when LargeChange was never set explicitly — changes the default paging amount to match.
public int ViewportLength { 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 defaultForeground, Color defaultBackground)
Parameters
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultForegroundColorThe default foreground color from the container.
defaultBackgroundColorThe default background color from the container.
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
UserValueChanged
Occurs only when the user changes Value through the bar itself: an arrow click, a track page click, a thumb drag, or a mouse wheel notch. Never raised by a code-set Value. A composite subscribes to this (not ValueChanged) to push the new offset to the views it drives, then writes the same value back to Value without causing an echo, since that write raises only ValueChanged.
public event EventHandler<int>? UserValueChanged
Event Type
ValueChanged
Occurs whenever Value changes, however it changed — including a value set by code. Matches the conventional, INPC-consistent behaviour of ValueChanged.
public event EventHandler<int>? ValueChanged