Table of Contents

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

Color?

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

Color

BelowLineColor

Color of the below line. Null uses the foreground color.

public Color? BelowLineColor { get; set; }

Property Value

Color?

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

Container

Gets or sets the parent container that hosts this control.

public override IContainer? Container { get; set; }

Property Value

IContainer

ContentPadding

Inner padding between toolbar edge and items.

public Padding ContentPadding { get; set; }

Property Value

Padding

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

Color

GetConsoleWindowSystem

Gets the console window system instance, or null if not attached to a window system.

public ConsoleWindowSystem? GetConsoleWindowSystem { get; }

Property Value

ConsoleWindowSystem

HasFocus

public bool HasFocus { get; }

Property Value

bool

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

bool

IsEnabled

Gets or sets whether this control is enabled and can receive input.

public bool IsEnabled { get; set; }

Property Value

bool

ItemSpacing

Gets or sets the spacing between items. Defaults to 0.

public int ItemSpacing { get; set; }

Property Value

int

Items

Gets the items in the toolbar.

public IReadOnlyList<IWindowControl> Items { get; }

Property Value

IReadOnlyList<IWindowControl>

PreferredCursorShape

Gets the preferred cursor shape for this control. Return null to use the default cursor shape.

public CursorShape? PreferredCursorShape { get; }

Property Value

CursorShape?

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

IFocusableControl

ShowAboveLine

When true, renders a horizontal line above the toolbar content. Default false.

public bool ShowAboveLine { get; set; }

Property Value

bool

ShowBelowLine

When true, renders a horizontal line below the toolbar content. Default false.

public bool ShowBelowLine { get; set; }

Property Value

bool

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

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

bool

Methods

AddItem(IWindowControl)

Adds an item to the toolbar.

public void AddItem(IWindowControl item)

Parameters

item IWindowControl

The 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

IReadOnlyList<IWindowControl>

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

backward bool

Returns

IFocusableControl

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

current IFocusableControl
backward bool

Returns

IFocusableControl

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

control IWindowControl

The 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

index int

The index to insert at.

item IWindowControl

The 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

redrawAll bool

If true, forces a complete redraw of all content.

callerControl IWindowControl

The 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

constraints LayoutConstraints

The 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

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultFg Color
defaultBg Color

ProcessKey(ConsoleKeyInfo)

Processes a keyboard input event.

public bool ProcessKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

The 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

args MouseEventArgs

Mouse 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

item IWindowControl

The item to remove.

SetLogicalCursorPosition(Point)

Sets the logical cursor position within the control's content coordinate system.

public void SetLogicalCursorPosition(Point position)

Parameters

position Point

Events

MouseClick

Event fired when the control is clicked

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Event fired when the control is double-clicked

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Event fired when the mouse enters the control area

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Event fired when the mouse leaves the control area

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Event fired when the mouse moves over the control

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Occurs when the control is right-clicked with the mouse.

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>