1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Thread-local programmatic focus-request channel.
//!
//! Widgets built in app code can't reach the [`App`](crate::widget::App)'s
//! private focus path to focus themselves when they appear — e.g. a search
//! field that should grab the keyboard the instant its overlay opens. This
//! channel mirrors [`crate::animation::request_draw`]:
//!
//! 1. The widget is built with a stable [`FocusId`] and returns it from
//! [`Widget::focus_id`](crate::widget::Widget::focus_id).
//! 2. App logic calls [`request_focus`] with that id (typically from the
//! same handler that makes the widget visible).
//! 3. The `App` consumes the pending request on its next `layout`, locates
//! the focusable widget whose `focus_id` matches, and moves focus to it
//! — dispatching `FocusGained` and (for text inputs) raising the
//! on-screen keyboard.
//!
//! Only one request is held at a time; a later [`request_focus`] before the
//! `App` services the previous one wins.
use Cell;
/// Opaque, app-chosen identifier for a focusable widget. Values only need to
/// be unique among the widgets that opt into focus-by-request.
pub type FocusId = u64;
thread_local!
/// Request that the widget whose [`Widget::focus_id`](crate::widget::Widget::focus_id)
/// equals `id` receive focus on the next frame. Also wakes the host loop
/// (via [`crate::animation::request_draw`]) so the request is serviced
/// promptly.
/// Read-and-clear the pending focus request. Called by the `App` once per
/// `layout`.
/// Discard any pending focus request without acting on it.