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
windowWindow
Properties
FocusPath
Gets the ancestor chain from the window root to FocusedControl.
public IReadOnlyList<IWindowControl> FocusPath { get; }
Property Value
FocusedControl
Gets the currently focused control, or null if nothing has focus.
public IFocusableControl? FocusedControl { get; }
Property Value
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
hitIWindowControl
IsFocused(IFocusableControl)
Returns true if control is the currently focused control.
public bool IsFocused(IFocusableControl control)
Parameters
controlIFocusableControl
Returns
IsInFocusPath(IWindowControl)
Returns true if control appears anywhere in FocusPath.
public bool IsInFocusPath(IWindowControl control)
Parameters
controlIWindowControl
Returns
MoveFocus(bool)
Moves focus to the next (or previous when backward is true) focusable control.
public void MoveFocus(bool backward)
Parameters
backwardbool
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
controlIFocusableControlreasonFocusReason
Events
FocusChanged
Fired whenever FocusedControl changes.
public event EventHandler<FocusChangedEventArgs>? FocusChanged