Class ToolbarControl
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
A horizontal toolbar control that contains buttons, separators, and other controls. Supports Tab navigation between focusable items and Enter key activation of buttons.
public class ToolbarControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IContainer, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, IContainerControl, ILogicalCursorProvider, ICursorShapeProvider, IFocusScope
- Inheritance
-
ToolbarControl
- Implements
- Inherited Members
- Extension Methods
Constructors
ToolbarControl()
Initializes a new instance of the ToolbarControl class.
public ToolbarControl()
Properties
AboveLineColor
Color of the above line. Null uses the foreground color.
public Color? AboveLineColor { get; set; }
Property Value
BackgroundColor
Gets or sets the background color of the toolbar. When null is set, inherits from the theme or container.
public Color BackgroundColor { get; set; }
Property Value
BelowLineColor
Color of the below line. Null uses the foreground color.
public Color? BelowLineColor { 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
ContentPadding
Inner padding between toolbar edge and items.
public Padding ContentPadding { 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?
ForegroundColor
Gets or sets the foreground color of the toolbar. When null is set, inherits from the theme or container.
public Color ForegroundColor { get; set; }
Property Value
GetConsoleWindowSystem
Gets the console window system instance, or null if not attached to a window system.
public ConsoleWindowSystem? GetConsoleWindowSystem { get; }
Property Value
HasFocus
public bool HasFocus { get; }
Property Value
Height
Gets or sets the height of the toolbar. When null (default), row height is auto-computed from the tallest item per row. When set explicitly, all rows use the fixed height and items may be clipped.
public override int? Height { get; set; }
Property Value
- int?
IsDirty
Gets or sets whether this container needs to be redrawn.
public bool IsDirty { get; set; }
Property Value
IsEnabled
Gets or sets whether this control is enabled and can receive input.
public bool IsEnabled { get; set; }
Property Value
ItemSpacing
Gets or sets the spacing between items. Defaults to 0.
public int ItemSpacing { get; set; }
Property Value
Items
Gets the items in the toolbar.
public IReadOnlyList<IWindowControl> Items { get; }
Property Value
PreferredCursorShape
Gets the preferred cursor shape for this control. Return null to use the default cursor shape.
public CursorShape? PreferredCursorShape { get; }
Property Value
SavedFocus
Saved focus position. FocusManager sets this before exiting the scope (if scope opts in). GetInitialFocus should return this when set, then clear it.
public IFocusableControl? SavedFocus { get; set; }
Property Value
ShowAboveLine
When true, renders a horizontal line above the toolbar content. Default false.
public bool ShowAboveLine { get; set; }
Property Value
ShowBelowLine
When true, renders a horizontal line below the toolbar content. Default false.
public bool ShowBelowLine { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; }
Property Value
Wrap
Gets or sets whether toolbar items wrap to the next row when they exceed the available width. When false (default), items are laid out in a single row and may be clipped. When true, items that don't fit on the current row flow to the next row.
public bool Wrap { get; set; }
Property Value
Methods
AddItem(IWindowControl)
Adds an item to the toolbar.
public void AddItem(IWindowControl item)
Parameters
itemIWindowControlThe item to add.
Clear()
Clears all items from the toolbar.
public void Clear()
Create()
Creates a new ToolbarBuilder for fluent toolbar construction.
public static ToolbarBuilder Create()
Returns
- ToolbarBuilder
A new toolbar builder.
GetChildren()
Gets the children of this container for Tab navigation traversal. Required by IContainerControl interface.
public IReadOnlyList<IWindowControl> GetChildren()
Returns
GetInitialFocus(bool)
Returns the first child to focus when Tab enters this scope. backward=true means Shift+Tab entered from the right — return last child.
public IFocusableControl? GetInitialFocus(bool backward)
Parameters
backwardbool
Returns
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.
GetLogicalCursorPosition()
Gets the logical cursor position within the control's content coordinate system. This should be the raw position without any visual adjustments for margins, scrolling, etc.
public Point? GetLogicalCursorPosition()
Returns
- Point?
Logical cursor position or null if no cursor.
GetNextFocus(IFocusableControl, bool)
Returns the next child to focus after Tab from 'current'. Returns null when Tab should exit this scope.
public IFocusableControl? GetNextFocus(IFocusableControl current, bool backward)
Parameters
currentIFocusableControlbackwardbool
Returns
Remarks
Always returns null — Tab always exits the toolbar immediately. Arrow key navigation within the toolbar is handled by ProcessKey(ConsoleKeyInfo).
GetVisibleHeightForControl(IWindowControl)
Gets the actual visible height for a control within the container viewport. Returns null if the control is not found or visibility cannot be determined.
public int? GetVisibleHeightForControl(IWindowControl control)
Parameters
controlIWindowControlThe control to check
Returns
- int?
The number of visible lines, or null if unknown
InsertItem(int, IWindowControl)
Inserts an item at the specified index.
public void InsertItem(int index, IWindowControl item)
Parameters
indexintThe index to insert at.
itemIWindowControlThe item to insert.
Invalidate()
Marks this control as needing to be re-rendered.
public void Invalidate()
Invalidate(bool, IWindowControl?)
Marks this container as needing to be redrawn.
public void Invalidate(bool redrawAll, IWindowControl? callerControl = null)
Parameters
redrawAllboolIf true, forces a complete redraw of all content.
callerControlIWindowControlThe control that triggered the invalidation, if any.
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
RemoveItem(IWindowControl)
Removes an item from the toolbar.
public void RemoveItem(IWindowControl item)
Parameters
itemIWindowControlThe item to remove.
SetLogicalCursorPosition(Point)
Sets the logical cursor position within the control's content coordinate system.
public void SetLogicalCursorPosition(Point position)
Parameters
positionPoint
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
Occurs when the control is right-clicked with the mouse.
public event EventHandler<MouseEventArgs>? MouseRightClick