Documentation
¶
Index ¶
- Constants
- func DrawFocusRing(canvas widget.Canvas, bounds geometry.Rect, color widget.Color, radius float32)
- type Manager
- func (m *Manager) Blur()
- func (m *Manager) Focus(w widget.Focusable)
- func (m *Manager) Focused() widget.Focusable
- func (m *Manager) HandleKeyEvent(e *event.KeyEvent) bool
- func (m *Manager) Next()
- func (m *Manager) Previous()
- func (m *Manager) RegisterShortcut(s Shortcut, handler func())
- func (m *Manager) SetRoot(root widget.Widget)
- func (m *Manager) UnregisterShortcut(s Shortcut)
- type Shortcut
Constants ¶
const DefaultFocusRingOffset float32 = 2.0
DefaultFocusRingOffset is the distance between the widget bounds and the focus ring, in logical pixels.
const DefaultFocusRingStrokeWidth float32 = 2.0
DefaultFocusRingStrokeWidth is the line width of the focus ring stroke, in logical pixels.
Variables ¶
This section is empty.
Functions ¶
func DrawFocusRing ¶
DrawFocusRing draws a focus indicator around the given bounds.
The ring is drawn as a rounded rectangle outline, offset slightly outside the bounds. The radius controls corner rounding; use 0 for square corners.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager tracks keyboard focus within a widget tree.
It maintains a reference to the widget tree root and the currently focused widget. Tab and Shift+Tab key events are handled automatically to cycle focus through focusable widgets in depth-first order.
The Manager also supports global keyboard shortcuts that take precedence over tab navigation.
func New ¶
New creates a new focus Manager for the given widget tree root.
The root widget is the top-level widget whose subtree will be traversed for focus management. It may be nil, in which case the manager operates as a no-op until SetRoot is called.
func (*Manager) Blur ¶
func (m *Manager) Blur()
Blur removes focus from the currently focused widget.
After calling Blur, Manager.Focused returns nil.
func (*Manager) Focus ¶
Focus sets keyboard focus to the given widget.
If another widget currently has focus, it is blurred first. If w is nil, focus is cleared (equivalent to Manager.Blur). If w is not focusable (IsFocusable returns false), this is a no-op.
func (*Manager) Focused ¶
Focused returns the currently focused widget, or nil if no widget has focus.
func (*Manager) HandleKeyEvent ¶
HandleKeyEvent processes a key event for focus management.
The event is checked in the following order:
- Registered keyboard shortcuts
- Tab key (moves focus to next widget)
- Shift+Tab (moves focus to previous widget)
Returns true if the event was consumed (shortcut matched or tab navigation occurred), false otherwise.
func (*Manager) Next ¶
func (m *Manager) Next()
Next moves focus to the next focusable widget in tab order.
Tab order is determined by depth-first traversal of the widget tree. If no widget currently has focus, focus moves to the first focusable widget. If the last focusable widget has focus, focus wraps to the first. If no focusable widgets exist, this is a no-op.
func (*Manager) Previous ¶
func (m *Manager) Previous()
Previous moves focus to the previous focusable widget in tab order.
If no widget currently has focus, focus moves to the last focusable widget. If the first focusable widget has focus, focus wraps to the last. If no focusable widgets exist, this is a no-op.
func (*Manager) RegisterShortcut ¶
RegisterShortcut registers a global keyboard shortcut.
When the shortcut's key combination is pressed, the handler function is called. Shortcuts take precedence over tab navigation.
func (*Manager) SetRoot ¶
SetRoot replaces the widget tree root.
If the currently focused widget is no longer in the new tree, focus is cleared.
func (*Manager) UnregisterShortcut ¶
UnregisterShortcut removes all handlers for the given shortcut.
type Shortcut ¶
type Shortcut struct {
// Key is the key code that triggers this shortcut.
Key event.Key
// Ctrl indicates whether the Control modifier must be held.
Ctrl bool
// Shift indicates whether the Shift modifier must be held.
Shift bool
// Alt indicates whether the Alt modifier must be held.
Alt bool
}
Shortcut defines a keyboard shortcut as a combination of a key and modifier flags.
Shortcuts are matched against key press events. A shortcut matches when the key matches and all specified modifiers are held.