Table of Contents

Class FocusManager

Namespace
SharpConsoleUI.Core
Assembly
SharpConsoleUI.dll

Manages focus within a single Window. This is the single source of truth for which control has focus. Use SetFocus(IFocusableControl?, FocusReason) to move focus programmatically, MoveFocus(bool) to advance via Tab, and HandleClick(IWindowControl?) to focus via mouse.

public class FocusManager
Inheritance
FocusManager
Inherited Members
Extension Methods

Constructors

FocusManager(Window)

Initializes a new FocusManager for the given window.

public FocusManager(Window window)

Parameters

window Window

Properties

FocusPath

Gets the ancestor chain from the window root to FocusedControl.

public IReadOnlyList<IWindowControl> FocusPath { get; }

Property Value

IReadOnlyList<IWindowControl>

FocusedControl

Gets the currently focused control, or null if nothing has focus.

public IFocusableControl? FocusedControl { get; }

Property Value

IFocusableControl

Methods

HandleClick(IWindowControl?)

Routes a mouse click to the nearest focusable ancestor of hit, skipping controls that have CanFocusWithMouse set to false.

public void HandleClick(IWindowControl? hit)

Parameters

hit IWindowControl

IsFocused(IFocusableControl)

Returns true if control is the currently focused control.

public bool IsFocused(IFocusableControl control)

Parameters

control IFocusableControl

Returns

bool

IsInFocusPath(IWindowControl)

Returns true if control appears anywhere in FocusPath.

public bool IsInFocusPath(IWindowControl control)

Parameters

control IWindowControl

Returns

bool

MoveFocus(bool)

Moves focus to the next (or previous when backward is true) focusable control.

public void MoveFocus(bool backward)

Parameters

backward bool

SetFocus(IFocusableControl?, FocusReason)

Sets focus to control. If the control is an IFocusScope and reason is not Mouse, focus is delegated to its first focusable child. Pass null to clear focus.

public void SetFocus(IFocusableControl? control, FocusReason reason)

Parameters

control IFocusableControl
reason FocusReason

Events

FocusChanged

Fired whenever FocusedControl changes.

public event EventHandler<FocusChangedEventArgs>? FocusChanged

Event Type

EventHandler<FocusChangedEventArgs>