Expand description
§Focus State Management
This module provides focus state management for the Tessera UI framework.
§Overview
Focus is a common requirement in UI frameworks. As a functional UI framework,
tessera
lacks a stable method for locating specific components by reference.
Treating focus as an independent, shared state aligns better with tessera
’s
design philosophy and provides greater flexibility.
§Design Philosophy
The focus system is designed around the following principles:
- Decentralized: Each component can create its own
Focus
instance - Thread-safe: Focus state is managed using atomic operations and locks
- Automatic cleanup: Focus is automatically cleared when a
Focus
instance is dropped - Unique identification: Each focus instance has a unique UUID to prevent conflicts
§Usage
use tessera_ui::Focus;
// Create a new focus instance
let focus = Focus::new();
// Check if this focus is currently active
if focus.is_focused() {
// Handle focused state
}
// Request focus for this component
focus.request_focus();
// Clear focus when no longer needed
focus.unfocus();
§Thread Safety
The focus state is managed through a global static variable protected by read-write locks, making it safe to use across multiple threads. This is essential for Tessera’s parallelized design.
Structs§
- Focus
- A focus handle that represents a focusable component.