mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-28 17:30:12 +01:00
Every focusable egui widget the app draws is a stop of the window's one Tab order
The focus service takes egui's focus candidates of the pass (Memory::focus_candidates) at every order-dependent registration and at the end hook: each widget no component made becomes a stop of the app's own, where it was drawn among the framework's stops, a text stop for a TextEdit. Recorded views and lazy children replay them with their transcripts. A bare Tab is the framework's move unless an egui popup is open or the app's focused widget keeps Tab by its egui key filter. Removed: focus::host_stop and the separate egui-Tab path for windows without framework stops. The scrim absorber no longer takes key focus.
This commit is contained in:
1 parent
1f14633b74
commit
c933a90624
11 files changed
+327
-120
No files matched your search
@@ -380,7 +380,9 @@ pub(crate) fn show_cover_layer(ctx: &Context, cover: CoverLayer) {
|
||||
sizing = ui.is_sizing_pass();
|
||||
for rect in covered {
|
||||
ui.painter().rect_filled(rect, 0.0, scrim);
|
||||
let absorber = ui.allocate_rect(rect, Sense::click_and_drag());
|
||||
// It absorbs presses and never takes key focus: a focusable egui widget no component made is a Tab stop
|
||||
// of the app's own (`focus::take_app_widgets`).
|
||||
let absorber = ui.allocate_rect(rect, Sense::CLICK | Sense::DRAG);
|
||||
crate::runtime::egui::widgets::note_widget(ui.ctx(), absorber.id);
|
||||
crate::runtime::egui::access::hide(ui.ctx(), absorber.id);
|
||||
}
|
||||
|
||||
@@ -500,6 +500,13 @@ pub(crate) fn host_field(ui: &mut Ui, id: egui::Id, text: &mut String) -> Rect {
|
||||
ui.add(egui::TextEdit::singleline(text).id(id)).rect
|
||||
}
|
||||
|
||||
/// A host's own multi-line egui text field of `id` over `text` that locks focus, as a code editor of the app's own:
|
||||
/// its egui key filter keeps Tab, which it types.
|
||||
#[cfg(feature = "suite")]
|
||||
pub(crate) fn host_code_field(ui: &mut Ui, id: egui::Id, text: &mut String) -> Rect {
|
||||
ui.add(egui::TextEdit::multiline(text).id(id).lock_focus(true)).rect
|
||||
}
|
||||
|
||||
/// A host's own text editor of `id` at `rect`, as a canvas text tool draws it: it reads the IME events from egui's
|
||||
/// input into `text` (a commit appends, a deletion before the caret removes characters from its end) and writes the
|
||||
/// pass's IME output, context generation 1.
|
||||
|
||||
@@ -27,6 +27,17 @@ pub(crate) fn focused(ctx: &Context) -> Option<Id> {
|
||||
ctx.memory(|memory| memory.focused())
|
||||
}
|
||||
|
||||
/// egui's focus candidates of the running pass from the `seen`th on (`Memory::focus_candidates`): the widgets
|
||||
/// interested in key focus, in the order they registered.
|
||||
pub(crate) fn candidates_since(ctx: &Context, seen: usize) -> Vec<egui::FocusCandidate> {
|
||||
ctx.memory(|memory| memory.focus_candidates().get(seen..).map(<[_]>::to_vec).unwrap_or_default())
|
||||
}
|
||||
|
||||
/// Whether the widget egui holds key focus on keeps Tab by its event filter (`Memory::focus_lock_filter`).
|
||||
pub(crate) fn focused_keeps_tab(ctx: &Context) -> bool {
|
||||
ctx.memory(|memory| memory.focus_lock_filter()).is_some_and(|filter| filter.tab)
|
||||
}
|
||||
|
||||
/// Whether egui holds a label text selection, which egui copies on a copy or cut event.
|
||||
pub(crate) fn label_selection(ctx: &Context) -> bool {
|
||||
ctx.with_plugin::<egui::text_selection::LabelSelectionState, _>(|state| state.has_selection()).unwrap_or(false)
|
||||
@@ -57,9 +68,9 @@ pub(crate) fn surrender(ctx: &Context, id: Id) {
|
||||
}
|
||||
|
||||
/// H7: egui's begin pass set a focus direction from an unmodified arrow or the Tab it kept. The focus service clears
|
||||
/// it before any component runs unless egui focus is on an app's own widget (`FocusedRecord::host_focus`), or the
|
||||
/// key stage left a Tab to egui in a window with no focus stop, and the service moves no focus in the pass: egui would
|
||||
/// otherwise move focus off a framework stop that the same arrow reaches as an intent.
|
||||
/// it before any component runs unless egui focus is on an app's own widget (`FocusedRecord::host_focus`) and the
|
||||
/// service moves no focus in the pass: egui would otherwise move focus off a framework stop that the same arrow
|
||||
/// reaches as an intent.
|
||||
pub(crate) fn clear_directional_focus(ctx: &Context) {
|
||||
ctx.memory_mut(|memory| memory.move_focus(FocusDirection::None));
|
||||
}
|
||||
|
||||
@@ -76,7 +76,8 @@ pub(crate) struct FocusedRecord {
|
||||
pub(crate) claims: Vec<craft_keymap::Chord>,
|
||||
/// The component of the focused stop: only its state-dependent claims hold.
|
||||
pub(crate) focused: Option<Id>,
|
||||
/// The focused stop is the app's own egui widget (`Stop::host`): it reads the presses it claims from egui.
|
||||
/// The focused stop is the app's own egui widget (`Stop::host`: one of the app's focusable egui widgets, or its
|
||||
/// canvas): it reads the presses it claims from egui.
|
||||
pub(crate) host: bool,
|
||||
/// The arena root of the focused stop when the stop is a non-text member of an arena (a part of a canvas's frame
|
||||
/// overlay): the root's state-dependent claims hold too, so a canvas tool's keys work with a part focused.
|
||||
@@ -96,12 +97,18 @@ pub(crate) struct FocusedRecord {
|
||||
/// focused.
|
||||
pub(crate) canvas: Option<Id>,
|
||||
/// egui focus is on a widget no framework component made, or an egui popup is open, and no framework press or
|
||||
/// drag is captured: an app's own focused widget or popup keeps the keys a focused component keeps (Tab, Escape,
|
||||
/// the plain Enter, the clipboard events), and no window intent comes of them. Written by the end hook after its
|
||||
/// focus moves.
|
||||
/// drag is captured: an app's own focused widget or popup keeps the keys a focused component keeps (Escape, the
|
||||
/// plain Enter, the clipboard events), and no window intent comes of them. Written by the end hook after its focus
|
||||
/// moves.
|
||||
pub(crate) foreign: bool,
|
||||
/// egui focus is on a widget no framework component made, and no framework press or drag is captured: egui
|
||||
/// moves focus among the app's own widgets with the arrows and the Tab it keeps. Written by the end hook.
|
||||
/// A bare Tab is egui's: an egui popup is open (`foreign`), or egui focus is on the app's own widget and its egui
|
||||
/// key filter keeps Tab (a multi-line text edit that locks focus, a code editor). Any other bare Tab is the
|
||||
/// framework's move over its one order, which holds the app's widgets (`take_app_widgets`). Written by the end
|
||||
/// hook.
|
||||
pub(crate) tab_in_egui: bool,
|
||||
/// egui focus is on a widget no framework component made (`State::app_widget`: its stop of the app's own does not
|
||||
/// count, the app's canvas does), and no framework press or drag is captured: egui moves focus among the app's own
|
||||
/// widgets with the arrows. Written by the end hook.
|
||||
pub(crate) host_focus: bool,
|
||||
/// `host_focus`, on a text edit the app drew itself. Written by the end hook.
|
||||
pub(crate) host_text: bool,
|
||||
@@ -182,8 +189,9 @@ pub(crate) struct State {
|
||||
/// The stop focus last moved onto, the frame whose passes see the move, and what moved it there. It stays until focus
|
||||
/// moves again: while the stop keeps the focus, it is how the stop got it (`origin`).
|
||||
pub(super) arrived: Option<(u64, StopKey, FocusOrigin)>,
|
||||
/// The running pass's begin hook left a Tab to egui (`NavKeys::tab_to_egui`); its end hook takes it.
|
||||
pub(super) tab_to_egui: bool,
|
||||
/// How many of egui's focus candidates of the running pass (`Memory::focus_candidates`) `take_app_widgets` has
|
||||
/// read.
|
||||
pub(super) candidates_seen: usize,
|
||||
}
|
||||
|
||||
fn viewport(ctx: &Context) -> ViewportId {
|
||||
@@ -219,26 +227,78 @@ pub(crate) fn apply(ctx: &Context, acts: Vec<Act>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers a stop of the running pass in the innermost open scope, in registration order.
|
||||
/// Registers a stop of the running pass in the innermost open scope, in registration order: after the app's own
|
||||
/// widgets drawn before it (`take_app_widgets`). The app's own widget `stop` names (`host_canvas`) takes the place of
|
||||
/// its stop as one of those widgets, if the pass took it already.
|
||||
pub(crate) fn register_stop(ctx: &Context, stop: Stop) {
|
||||
take_app_widgets(ctx, Some(stop.root));
|
||||
let acts = with(ctx, |state| {
|
||||
let scope = state.open.last().map(|(id, _)| *id);
|
||||
state.stop_ids.insert(stop.id);
|
||||
if stop.host
|
||||
&& let Some(rec) = state.stops.iter_mut().find(|rec| rec.stop.host && rec.stop.id == stop.id)
|
||||
{
|
||||
rec.stop = stop;
|
||||
return Vec::new();
|
||||
}
|
||||
state.push_stop(stop)
|
||||
});
|
||||
apply(ctx, acts);
|
||||
}
|
||||
|
||||
impl State {
|
||||
/// Appends `stop` to the running pass's stops in the innermost open scope; it takes the focus a request of the pass
|
||||
/// awaits for it.
|
||||
fn push_stop(&mut self, stop: Stop) -> Vec<Act> {
|
||||
let scope = self.open.last().map(|(id, _)| *id);
|
||||
self.stop_ids.insert(stop.id);
|
||||
let rec = StopRec { stop, scope, group_position: false };
|
||||
let acts = if state.awaited == Some(rec.stop.key()) {
|
||||
state.awaited = None;
|
||||
state.focus_stop(rec.clone())
|
||||
let acts = if self.awaited == Some(rec.stop.key()) {
|
||||
self.awaited = None;
|
||||
self.focus_stop(rec.clone())
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
state.stops.push(rec);
|
||||
self.stops.push(rec);
|
||||
acts
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers the app's own egui widgets that egui listed as focus candidates since the last take of the running pass
|
||||
/// (`Memory::focus_candidates`, in the order they registered with egui), each as a stop of the app's own
|
||||
/// (`Stop::host`) with the keys of a pointer control, a text stop for a text edit: every focusable egui widget the app
|
||||
/// draws is a Tab and F6 stop among the framework's, where it was drawn. A widget a component made is none: its
|
||||
/// component registers its stops (`pointer::made_by_component`, or the root of a stop of the pass), and so is
|
||||
/// `except`, the root of the stop being registered. Every registration that depends on order takes them first, and
|
||||
/// the end hook takes the last ones, so a stop range (`mark`, `stop_count`) holds the app's widgets drawn in it.
|
||||
fn take_app_widgets(ctx: &Context, except: Option<Id>) {
|
||||
let seen = with(ctx, |state| state.candidates_seen);
|
||||
let fresh = egui_focus::candidates_since(ctx, seen);
|
||||
if fresh.is_empty() {
|
||||
return;
|
||||
}
|
||||
let viewport = viewport(ctx);
|
||||
let app: Vec<egui::FocusCandidate> = fresh
|
||||
.iter()
|
||||
.filter(|candidate| Some(candidate.id) != except && !crate::runtime::pointer::made_by_component(ctx, viewport, candidate.id))
|
||||
.copied()
|
||||
.collect();
|
||||
let acts = with(ctx, |state| {
|
||||
state.candidates_seen = seen + fresh.len();
|
||||
let mut acts = Vec::new();
|
||||
for candidate in app {
|
||||
if state.stops.iter().any(|rec| rec.stop.root == candidate.id) {
|
||||
continue;
|
||||
}
|
||||
let stop = Stop::new(candidate.id, KeyUse::of(craft_behavior::Input::Pointer)).host();
|
||||
acts.extend(state.push_stop(if candidate.text { stop.text() } else { stop }));
|
||||
}
|
||||
acts
|
||||
});
|
||||
apply(ctx, acts);
|
||||
}
|
||||
|
||||
/// Registers the app's own egui widget `id`, drawn in the running pass, as its window's document canvas: a focus stop
|
||||
/// with `keys`, marked as the canvas (`KeyUse::chrome_key`). The window then shows a document, so with
|
||||
/// Registers the app's own egui widget `id`, drawn in the running pass, as its window's document canvas: its focus stop
|
||||
/// takes `keys` and is marked as the canvas (`KeyUse::chrome_key`), in place of the stop it has as one of the app's
|
||||
/// focusable egui widgets, at the same place in Tab order. The window then shows a document, so with
|
||||
/// `RootEnv::tab_toggles_chrome` a bare Tab with nothing focused toggles its panels, as with a framework canvas. Focus
|
||||
/// reaches the canvas by Tab, F6, `request` or the app's own egui focus request; while it has focus, Tab and the arrows
|
||||
/// route as `keys` says (the arrows as nudges, Tab moving focus on or toggling the panels unless it keeps Tab). `keys`
|
||||
@@ -255,16 +315,6 @@ pub fn host_canvas(ctx: &Context, id: Id, keys: KeyUse) {
|
||||
register_stop(ctx, Stop::new(id, keys.with_chrome_key(true)).host());
|
||||
}
|
||||
|
||||
/// Registers the app's own egui widget `id`, drawn in the running pass, as a focus stop with `keys`, in the window's one
|
||||
/// Tab order: Tab and F6 reach it among the framework's stops in the order the pass registers them, so call it where
|
||||
/// the widget is drawn, each pass it shows. The widget must take egui focus under `id`. While it has the focus it reads
|
||||
/// its keys from egui as any focused widget of the app's own does (Escape, Enter, the keys `keys` keeps, and its
|
||||
/// claims), and Tab moves on from it as `keys` says. It never marks the window as showing a document: the document
|
||||
/// canvas registers with [`host_canvas`].
|
||||
pub fn host_stop(ctx: &Context, id: Id, keys: KeyUse) {
|
||||
register_stop(ctx, Stop::new(id, keys.with_chrome_key(false)).host());
|
||||
}
|
||||
|
||||
/// The stop of the document canvas `viewport` registered in its last pass (`KeyUse::chrome_key`), framework or the
|
||||
/// app's own (`Stop::host`). Read before the begin hook rotates the registrations, by the input hook and the begin
|
||||
/// hook's Tab moves.
|
||||
@@ -290,19 +340,9 @@ pub(crate) fn is_canvas_member(ctx: &Context, rec: &StopRec) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether a bare Tab in `viewport` is egui's own focus move: the window registered no framework stop in its last pass,
|
||||
/// only stops of the app's own egui widgets (`Stop::host`: `host_canvas`, `host_stop`) if any, which egui's Tab order
|
||||
/// holds with the app's other widgets; and egui held no focus at the end of that pass, or held it on one of those
|
||||
/// stops. A framework move would reach the host stops alone. With a framework stop in the window, Tab is the
|
||||
/// framework's move over its one order, which holds the host stops beside the framework's. Read by the input hook, before the begin hook rotates the registrations.
|
||||
pub(crate) fn tab_is_egui_s(ctx: &Context, viewport: ViewportId) -> bool {
|
||||
with_viewport(ctx, viewport, |state| {
|
||||
state.stops.iter().all(|rec| rec.stop.host) && state.focus_now.is_none_or(|id| state.stops.iter().any(|rec| rec.stop.root == id))
|
||||
})
|
||||
}
|
||||
|
||||
/// How many stops the running pass has registered so far.
|
||||
pub(crate) fn stop_count(ctx: &Context) -> usize {
|
||||
take_app_widgets(ctx, None);
|
||||
with(ctx, |state| state.stops.len())
|
||||
}
|
||||
|
||||
@@ -388,6 +428,7 @@ impl Eq for Transcript {}
|
||||
|
||||
/// Where the running pass's registrations stand.
|
||||
pub(crate) fn mark(ctx: &Context) -> Mark {
|
||||
take_app_widgets(ctx, None);
|
||||
with(ctx, |state| Mark {
|
||||
stops: state.stops.len(),
|
||||
scopes: state.scope_order.len(),
|
||||
@@ -398,6 +439,7 @@ pub(crate) fn mark(ctx: &Context) -> Mark {
|
||||
|
||||
/// What the running pass registered since `mark`, which a run that closed every scope it opened left.
|
||||
pub(crate) fn transcript(ctx: &Context, mark: Mark) -> Transcript {
|
||||
take_app_widgets(ctx, None);
|
||||
with(ctx, |state| {
|
||||
let stops = state.stops.get(mark.stops..).unwrap_or_default().to_vec();
|
||||
let scopes = state.scope_order.get(mark.scopes..).unwrap_or_default();
|
||||
@@ -416,6 +458,7 @@ pub(crate) fn transcript(ctx: &Context, mark: Mark) -> Transcript {
|
||||
/// Registers `transcript` again in the running pass, in place of the run that left it: in the innermost open scope,
|
||||
/// as the run would have. A replayed scope is no new scope: it moves no focus when it shows again.
|
||||
pub(crate) fn replay(ctx: &Context, transcript: &Transcript) {
|
||||
take_app_widgets(ctx, None);
|
||||
let frame = crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx));
|
||||
let focused = egui_focus::focused(ctx);
|
||||
with(ctx, |state| {
|
||||
@@ -456,6 +499,7 @@ pub(crate) fn has_reachable_stop(ctx: &Context, id: Id) -> bool {
|
||||
/// Where a request for the component `id` goes when it has no stop of its own: the first stop registered since
|
||||
/// `from` (a `stop_count`), which a component inside it holds.
|
||||
pub(crate) fn first_stop_inside(ctx: &Context, id: Id, from: usize) -> Option<FocusTarget> {
|
||||
take_app_widgets(ctx, None);
|
||||
with(ctx, |state| {
|
||||
if state.stop_ids.contains(&id) {
|
||||
return None;
|
||||
@@ -489,6 +533,7 @@ pub(crate) fn focus_in(ctx: &Context, range: std::ops::Range<usize>) -> bool {
|
||||
/// order, then the footer's, then the header's, and initial focus goes to the first of them, not to the title
|
||||
/// row's close action. The first mark of a pass stands.
|
||||
pub(crate) fn begin_body(ctx: &Context) {
|
||||
take_app_widgets(ctx, None);
|
||||
with(ctx, |state| {
|
||||
if let Some((scope, _)) = state.open.last().copied() {
|
||||
let at = state.stops.len();
|
||||
@@ -552,6 +597,7 @@ pub(crate) fn push_scope_from(
|
||||
closing: bool,
|
||||
entering: Option<bool>,
|
||||
) {
|
||||
take_app_widgets(ctx, None);
|
||||
let focused = egui_focus::focused(ctx);
|
||||
with(ctx, |state| {
|
||||
let parent = state.open.last().map(|(parent, _)| *parent);
|
||||
@@ -583,6 +629,7 @@ pub fn open_scope(ctx: &Context) -> Option<Id> {
|
||||
/// Closes the innermost open scope. A scope pushed for the first time (or again after a gap of a frame)
|
||||
/// moves focus to its initial stop, in this pass.
|
||||
pub(crate) fn pop_scope(ctx: &Context) {
|
||||
take_app_widgets(ctx, None);
|
||||
let frame = crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx));
|
||||
let acts = with(ctx, |state| {
|
||||
nav::order_regions(state);
|
||||
@@ -1014,17 +1061,15 @@ pub(crate) fn begin(ctx: &Context, tab_all_controls: bool, dialog_tab: TabReach)
|
||||
dialog_tab,
|
||||
frame: crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx)),
|
||||
};
|
||||
let tab_to_egui = input.nav.tab_to_egui;
|
||||
let (acts, announcements, host_focus) = with(ctx, |state| {
|
||||
state.awaited = None;
|
||||
let host_focus = state.record.host_focus;
|
||||
state.tab_to_egui = tab_to_egui;
|
||||
let (acts, announcements) = nav::begin(state, input);
|
||||
(acts, announcements, host_focus)
|
||||
});
|
||||
// egui's direction moves focus from the widget it holds, an app's own, or with a Tab the key stage left to egui
|
||||
// (from nothing or a host stop); never in a pass whose focus the framework moves.
|
||||
if !(host_focus || tab_to_egui) || !acts.is_empty() {
|
||||
// egui's direction (its arrows, a Tab the key stage left to egui) moves focus from the widget it holds when that is
|
||||
// an app's own; never in a pass whose focus the framework moves.
|
||||
if !host_focus || !acts.is_empty() {
|
||||
egui_focus::clear_directional_focus(ctx);
|
||||
}
|
||||
apply(ctx, acts);
|
||||
@@ -1037,13 +1082,7 @@ pub(crate) fn begin(ctx: &Context, tab_all_controls: bool, dialog_tab: TabReach)
|
||||
/// moves it off a stop that was not registered, and records what the next input hook reads.
|
||||
pub(crate) fn end(ctx: &Context) {
|
||||
let viewport = viewport(ctx);
|
||||
// A Tab left to egui moves egui focus into the app's own widgets only: a component's egui widget takes focus
|
||||
// through its stop, and a component that registered none (a disabled one) takes none.
|
||||
if with(ctx, |state| std::mem::take(&mut state.tab_to_egui))
|
||||
&& let Some(id) = egui_focus::focused(ctx).filter(|id| crate::runtime::pointer::made_by_component(ctx, viewport, *id))
|
||||
{
|
||||
egui_focus::surrender(ctx, id);
|
||||
}
|
||||
take_app_widgets(ctx, None);
|
||||
let app_widget = |id: Id| {
|
||||
let made = crate::runtime::pointer::made_by_component(ctx, viewport, id);
|
||||
with(ctx, |state| state.app_widget(id, made))
|
||||
@@ -1056,7 +1095,9 @@ pub(crate) fn end(ctx: &Context) {
|
||||
// Escape over a captured framework press or drag cancels it (`frame::begin_pass`), whatever egui has focused.
|
||||
let captured = crate::runtime::pointer::press_captured(ctx) || crate::runtime::drag::running(ctx);
|
||||
let host_focus = !captured && with(ctx, |state| state.focus_now).is_some_and(app_widget);
|
||||
let foreign = host_focus || (!captured && crate::runtime::egui::areas::popup_open(ctx));
|
||||
let popup = !captured && crate::runtime::egui::areas::popup_open(ctx);
|
||||
let foreign = host_focus || popup;
|
||||
let tab_in_egui = popup || (host_focus && egui_focus::focused_keeps_tab(ctx));
|
||||
let label_selection = egui_focus::label_selection(ctx);
|
||||
let host_text = host_focus && ctx.text_edit_focused();
|
||||
// A modal layer keeps the canvas's claims from it, as it keeps the arrows (`overlay::end_pass` ran before).
|
||||
@@ -1064,6 +1105,7 @@ pub(crate) fn end(ctx: &Context) {
|
||||
with(ctx, |state| {
|
||||
state.record.canvas = state.record.canvas.filter(|_| !modal);
|
||||
state.record.foreign = foreign;
|
||||
state.record.tab_in_egui = tab_in_egui;
|
||||
state.record.host_focus = host_focus;
|
||||
state.record.host_text = host_text;
|
||||
state.record.label_selection = label_selection;
|
||||
|
||||
@@ -193,6 +193,7 @@ impl State {
|
||||
self.body_from.clear();
|
||||
self.entered = false;
|
||||
self.asked = false;
|
||||
self.candidates_seen = 0;
|
||||
}
|
||||
|
||||
/// The registrations of last pass, which Tab and the arrows move over.
|
||||
@@ -228,10 +229,13 @@ impl State {
|
||||
.or_else(|| self.stops.iter().chain(&self.last_stops).find(|rec| rec.stop.root == root).cloned())
|
||||
}
|
||||
|
||||
/// Whether `id`, holding egui focus, is an app's own widget: no stop's root and, as `made` says, no widget a
|
||||
/// component made (`pointer::made_by_component`).
|
||||
/// Whether `id`, holding egui focus, is an app's own widget: as `made` says, no widget a component made
|
||||
/// (`pointer::made_by_component`), and the root of no stop but the one every focusable egui widget of the app has
|
||||
/// (`Stop::host` with default keys). The app's canvas (`host_canvas`, `KeyUse::chrome_key`) is none: its declared
|
||||
/// keys route as a framework stop's do, so egui's arrows and Tab never move focus off it.
|
||||
pub(super) fn app_widget(&self, id: Id, made: bool) -> bool {
|
||||
!made && self.find_stop((id, None)).is_none() && !self.stops.iter().chain(&self.last_stops).any(|rec| rec.stop.root == id)
|
||||
let automatic = |rec: &StopRec| rec.stop.host && !rec.stop.keys.chrome_key;
|
||||
!made && !self.stops.iter().chain(&self.last_stops).any(|rec| !automatic(rec) && (rec.stop.root == id || rec.stop.key() == (id, None)))
|
||||
}
|
||||
|
||||
/// Moves focus to `rec` and asks the enclosing scroll owner to reveal it: the egui widget is its root, and the stop
|
||||
@@ -873,6 +877,7 @@ pub(super) fn end(state: &mut State, focused: Option<Id>, on_app_widget: bool, f
|
||||
menu_bar_by_claim: std::mem::take(&mut state.menu_bar_by_claim),
|
||||
canvas: if stop.is_none() { state.stops.iter().find(|rec| rec.stop.keys.chrome_key).map(|rec| rec.stop.id) } else { None },
|
||||
foreign: false,
|
||||
tab_in_egui: false,
|
||||
host_focus: false,
|
||||
host_text: false,
|
||||
label_selection: false,
|
||||
|
||||
@@ -66,9 +66,6 @@ pub enum MenuKey {
|
||||
pub(crate) struct NavKeys {
|
||||
pub(crate) tabs: Vec<bool>,
|
||||
pub(crate) panes: Vec<bool>,
|
||||
/// The input hook left a bare Tab in egui's input: nothing has the focus and the window registered no focus stop,
|
||||
/// so the framework has nothing to move to and egui moves its own focus.
|
||||
pub(crate) tab_to_egui: bool,
|
||||
}
|
||||
|
||||
struct Press {
|
||||
|
||||
@@ -42,9 +42,12 @@ struct Strip<'a> {
|
||||
holds_drafts: bool,
|
||||
/// A dialog keeps a canvas open and Space belongs to it: the press is the canvas's momentary command chord.
|
||||
canvas_space: bool,
|
||||
/// An app's own egui widget or popup has the focus (`FocusedRecord::foreign`): Tab, Escape, the plain Enter and the
|
||||
/// An app's own egui widget or popup has the focus (`FocusedRecord::foreign`): Escape, the plain Enter and the
|
||||
/// clipboard events are its own, and no window intent comes of them.
|
||||
foreign: bool,
|
||||
/// A bare Tab is egui's (`FocusedRecord::tab_in_egui`): an app's own popup is open, or the app's own focused widget
|
||||
/// keeps Tab by its egui key filter.
|
||||
tab_in_egui: bool,
|
||||
/// The focused stop is the app's own egui widget (`Stop::host`, `FocusedRecord::host`), which reads its keys from
|
||||
/// egui: its Escape stays there, as an app's own focused widget's does. Tab and the arrows follow its `KeyUse`, as
|
||||
/// the framework's navigation reads it.
|
||||
@@ -52,12 +55,6 @@ struct Strip<'a> {
|
||||
/// The edit set whose clipboard events and edit chords stay in egui's input: the focused stop's when it is the
|
||||
/// app's own widget (`host`), else the window canvas's with nothing focused (`target_canvas`).
|
||||
egui_edits: EditSet,
|
||||
/// A bare Tab that the focus does not keep is egui's own move (`focus::tab_is_egui_s`): the window registered no
|
||||
/// framework stop in its last pass, only the app's own widgets' (`Stop::host`) if any, and nothing has the focus or
|
||||
/// one of those stops has it. egui's Tab order holds those stops and the app's other widgets; a framework move
|
||||
/// would reach the stops alone. Focus on a component's widget without a stop is focus: egui would take a Tab from
|
||||
/// it as a move to the next widget it shows, in a later pass. A Tab that toggles the chrome stays the framework's.
|
||||
egui_tab: bool,
|
||||
/// egui holds a label text selection, which a copy or cut event copies.
|
||||
label_selection: bool,
|
||||
/// A tool host claimed the lone Alt tap: it goes to the claimer on every OS, not to the menu bar.
|
||||
@@ -375,10 +372,12 @@ impl Strip<'_> {
|
||||
PressUse::Edit(*command)
|
||||
} else if key == Key::Space && self.canvas_space {
|
||||
PressUse::CanvasSpace
|
||||
} else if (self.foreign && (bare_tab || escape || plain_enter)) || (self.host && escape && !self.press_captured) || egui_edit {
|
||||
} else if (self.foreign && (escape || plain_enter))
|
||||
|| (bare_tab && self.tab_in_egui)
|
||||
|| (self.host && escape && !self.press_captured)
|
||||
|| egui_edit
|
||||
{
|
||||
PressUse::Egui
|
||||
} else if bare_tab && self.egui_tab && !self.keeps_tab {
|
||||
PressUse::TabToEgui
|
||||
} else if bare_tab && !self.keeps_tab {
|
||||
PressUse::Tab
|
||||
} else if ctrl_tab {
|
||||
@@ -439,12 +438,6 @@ impl Strip<'_> {
|
||||
// the key from egui; the runtime routes nothing for it, so no shortcut toggles the chrome or fires an edit
|
||||
// command with it either.
|
||||
PressUse::Egui => true,
|
||||
PressUse::TabToEgui => {
|
||||
// egui moves its own focus with it, from nothing focused or a host stop through the app's own widgets
|
||||
// (`focus::begin`).
|
||||
batch.nav.tab_to_egui = true;
|
||||
true
|
||||
}
|
||||
PressUse::Tab => {
|
||||
batch.tabs.push(TabPress { input: *input, repeat, at, place: batch.place });
|
||||
false
|
||||
@@ -534,8 +527,6 @@ enum PressUse {
|
||||
CanvasSpace,
|
||||
/// The app's own widget or popup, or the canvas with nothing focused, reads the key from egui.
|
||||
Egui,
|
||||
/// A bare Tab egui moves its own focus with, through the app's own widgets.
|
||||
TabToEgui,
|
||||
/// A bare Tab: a focus move or a chrome toggle, which `take_nav` decides.
|
||||
Tab,
|
||||
/// The page switch of the focused stop.
|
||||
@@ -666,10 +657,6 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec<Arriv
|
||||
let lists_edits = |keys: &KeyUse| EditCommands::ALL.iter().any(|command| command.edit().is_some_and(|edit| keys.edits.contains(edit)));
|
||||
let edit_chords = if keys.as_ref().or(canvas.as_ref()).is_some_and(lists_edits) { commands::edit_chords(ctx) } else { Arc::default() };
|
||||
let window_shortcuts = commands::window_shortcuts(ctx);
|
||||
// A window with a document canvas whose root env has Tab toggle the chrome: the begin hook decides that Tab
|
||||
// (`take_nav`), so it is never egui's.
|
||||
let chrome_tab = focus::canvas_stop(ctx, viewport).is_some() && Env::root_for(ctx, viewport).is_some_and(|env| env.tab_toggles_chrome);
|
||||
let egui_tab = (keys.is_none() || record.host) && !record.foreign && !chrome_tab && focus::tab_is_egui_s(ctx, viewport);
|
||||
let latin = &input.latin_layout_chars;
|
||||
let requested_paste = commands::board::has_pending_paste(ctx, viewport);
|
||||
let mut requested_content = None::<commands::ClipContent>;
|
||||
@@ -699,9 +686,9 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec<Arriv
|
||||
holds_drafts: keys.is_some_and(|keys| keys.holds_drafts),
|
||||
canvas_space: hole.as_ref().is_some_and(|hole| hole.space || hole.space_pressed),
|
||||
foreign: record.foreign,
|
||||
tab_in_egui: record.tab_in_egui,
|
||||
host: record.host,
|
||||
egui_edits: keys.filter(|_| record.host).or(canvas).map_or(EditSet::NONE, |keys| keys.edits),
|
||||
egui_tab,
|
||||
label_selection: record.label_selection,
|
||||
alt_claimed: !stage.alt_claims.is_empty(),
|
||||
in_menu: record.menu.is_some(),
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::runtime::commands::{
|
||||
use crate::runtime::drag::{self, DragPreview};
|
||||
use crate::runtime::egui::{areas, fixture};
|
||||
use crate::runtime::env::{Env, RootEnv};
|
||||
use crate::runtime::focus::{EditSet, FocusPolicy, FocusTarget, KeepKeys, KeyUse, host_canvas, host_stop, request};
|
||||
use crate::runtime::focus::{EditSet, FocusPolicy, FocusTarget, KeepKeys, KeyUse, host_canvas, request};
|
||||
use crate::runtime::frame::{ChromeToggle, take_output};
|
||||
use crate::runtime::keys::with_window_intents;
|
||||
use crate::style::{ComponentStyle, StyleCx};
|
||||
@@ -298,7 +298,7 @@ fn an_app_editor_s_later_reset_ends_the_fence() {
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_focused_egui_field_keeps_tab_escape_and_the_clipboard() {
|
||||
fn a_focused_egui_field_keeps_escape_and_the_clipboard_and_tabs_on_through_the_one_order() {
|
||||
let (host, mut show) = host_window();
|
||||
let mut frames = Frames::new();
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
@@ -309,9 +309,9 @@ fn a_focused_egui_field_keeps_tab_escape_and_the_clipboard() {
|
||||
frames.frame(vec![Event::Paste("x".to_owned())], &mut show);
|
||||
assert_eq!(host.borrow().text, "x", "the paste reaches the focused field");
|
||||
press_key(&mut frames, &mut show, Key::Tab);
|
||||
assert_eq!(seen(&host), (vec![Key::Tab], 0), "the field's Tab is egui's");
|
||||
assert_eq!(seen(&host), (Vec::new(), 0), "a single-line field's Tab is the framework's move, never egui's");
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "egui's Tab moves focus on to the next widget");
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "the field is the last stop: Tab wraps to the framework's button");
|
||||
fixture::host_focus(&frames.ctx, field());
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
press_key(&mut frames, &mut show, Key::Escape);
|
||||
@@ -393,8 +393,10 @@ fn escape_cancels_a_framework_drag_while_an_egui_field_has_focus() {
|
||||
frames.frame(vec![release(inside)], &mut show);
|
||||
}
|
||||
|
||||
/// The app's own buttons drawn after the window's framework button and host field: egui's arrows move focus among
|
||||
/// them, and Tab and Shift+Tab move it through the window's one order, which holds them.
|
||||
#[trial]
|
||||
fn arrows_and_tab_move_egui_focus_among_host_buttons() {
|
||||
fn arrows_move_egui_focus_among_host_buttons_and_tab_moves_through_the_one_order() {
|
||||
let (left, right) = (named_id("host left"), named_id("host right"));
|
||||
let (_host, mut base) = host_window();
|
||||
let mut show = move |ui: &mut Ui| {
|
||||
@@ -411,7 +413,7 @@ fn arrows_and_tab_move_egui_focus_among_host_buttons() {
|
||||
press_key(&mut frames, &mut show, Key::ArrowLeft);
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(left), "ArrowLeft moves it back");
|
||||
press_key(&mut frames, &mut show, Key::Tab);
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(right), "Tab moves egui focus on");
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(right), "Tab moves focus on to the next stop");
|
||||
frames.frame(vec![key_press(Key::Tab, Modifiers::SHIFT)], &mut show);
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(left), "Shift+Tab moves it back");
|
||||
@@ -424,15 +426,14 @@ fn arrows_and_tab_move_egui_focus_among_host_buttons() {
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "egui's arrows leave a framework stop's focus alone");
|
||||
}
|
||||
|
||||
/// Arrows from an entry of the app's own popup list stay in the list: the app's button under the list, a host stop as
|
||||
/// an app's tool slot is, is no arrow target while the list covers it, though it lies nearer below the first entry
|
||||
/// than the second entry does.
|
||||
/// Arrows from an entry of the app's own popup list stay in the list: the app's button under the list, a Tab stop as
|
||||
/// every focusable widget of the app is, is no arrow target while the list covers it, though it lies nearer below the
|
||||
/// first entry than the second entry does.
|
||||
#[trial]
|
||||
fn arrows_in_an_app_popup_list_skip_the_widget_it_covers() {
|
||||
let (button, popup, first, second) = (named_id("host tool"), named_id("host popup"), named_id("host entry 1"), named_id("host entry 2"));
|
||||
let mut show = move |ui: &mut Ui| {
|
||||
fixture::host_button(ui, button, Rect::from_min_max(Pos2::new(228.0, 31.0), Pos2::new(254.0, 57.0)));
|
||||
host_stop(ui.ctx(), button, KeyUse::of(Input::Pointer));
|
||||
areas::host_popup_list(ui.ctx(), popup, Pos2::new(201.0, 18.0), &[first, second]);
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
@@ -498,23 +499,23 @@ fn tab_from_nothing(before: Before, shift: bool) -> (Option<Id>, bool) {
|
||||
(egui_focused(&frames.ctx), reached)
|
||||
}
|
||||
|
||||
/// Tab is the framework's move whatever the window holds: from nothing focused it reaches the app's own widgets as its
|
||||
/// stops, and never egui's input. A component's widget that registered no stop is no stop of the app's own.
|
||||
#[trial]
|
||||
fn tab_from_nothing_focused_in_a_window_without_stops_moves_egui_focus() {
|
||||
fn tab_from_nothing_reaches_the_app_s_widgets_as_the_framework_s_move() {
|
||||
let (first, last) = (Some(named_id("host first")), Some(named_id("host last")));
|
||||
assert_eq!(tab_from_nothing(Before::Nothing, false), (first, true), "Tab gives egui focus to the first host button");
|
||||
assert_eq!(tab_from_nothing(Before::Nothing, true), (last, true), "Shift+Tab to the last");
|
||||
assert_eq!(tab_from_nothing(Before::Stop, false), (Some(named_id("button")), false), "with a framework stop, Tab is the framework's move");
|
||||
assert_eq!(tab_from_nothing(Before::Unstopped, false), (None, true), "egui's Tab gives no focus to a component's widget without a stop");
|
||||
let (focused, reached) = tab_from_nothing(Before::FocusedUnstopped, false);
|
||||
assert!(focused.is_some() && focused != first && !reached, "egui focus on that widget is focus: the Tab is not egui's and moves nothing");
|
||||
assert_eq!(tab_from_nothing(Before::Nothing, false), (first, false), "Tab focuses the first host button");
|
||||
assert_eq!(tab_from_nothing(Before::Nothing, true), (last, false), "Shift+Tab the last");
|
||||
assert_eq!(tab_from_nothing(Before::Stop, false), (Some(named_id("button")), false), "the framework stop drawn first comes first");
|
||||
assert_eq!(tab_from_nothing(Before::Unstopped, false), (first, false), "a component's widget without a stop gets no focus");
|
||||
assert_eq!(tab_from_nothing(Before::FocusedUnstopped, false), (first, false), "from that widget holding focus, Tab goes to the first stop");
|
||||
}
|
||||
|
||||
/// A window with a framework stop, two of the app's own buttons registered as host stops and the app's canvas, which
|
||||
/// keeps Tab, unfocused: Tab from nothing is the framework's move over its one order, which holds the app's buttons
|
||||
/// beside the framework's stop. The unfocused canvas does not keep the Tab; it is the last entry, and once Tab focuses
|
||||
/// it, it keeps Tab.
|
||||
/// A window with a framework stop, two of the app's own buttons and the app's canvas, which keeps Tab, unfocused: Tab
|
||||
/// from nothing is the framework's move over its one order, which holds the app's buttons beside the framework's
|
||||
/// stop. The unfocused canvas does not keep the Tab; it is the last entry, and once Tab focuses it, it keeps Tab.
|
||||
#[trial]
|
||||
fn tab_from_nothing_goes_through_the_framework_order_with_the_app_s_host_stops() {
|
||||
fn tab_from_nothing_goes_through_the_framework_order_with_the_app_s_widgets() {
|
||||
let (stop, first, second, canvas) = (named_id("button"), named_id("host first"), named_id("host second"), named_id("host canvas"));
|
||||
let reached = Rc::new(Cell::new(false));
|
||||
let seen_tab = Rc::clone(&reached);
|
||||
@@ -524,7 +525,6 @@ fn tab_from_nothing_goes_through_the_framework_order_with_the_app_s_host_stops()
|
||||
register_stop(ui.ctx(), Stop::new(stop, KeyUse::of(Input::Pointer)));
|
||||
for (id, x) in [(first, 300.0), (second, 420.0)] {
|
||||
fixture::host_button(ui, id, Rect::from_min_size(Pos2::new(x, 300.0), egui::vec2(80.0, 30.0)));
|
||||
host_stop(ui.ctx(), id, KeyUse::of(Input::Pointer));
|
||||
}
|
||||
widget(ui, canvas);
|
||||
host_canvas(ui.ctx(), canvas, KeyUse::CANVAS.with_keep(KeepKeys::Tab));
|
||||
@@ -544,10 +544,11 @@ fn tab_from_nothing_goes_through_the_framework_order_with_the_app_s_host_stops()
|
||||
assert_eq!(tab(&mut frames), (Some(canvas), true), "the focused canvas keeps Tab and reads it from egui");
|
||||
}
|
||||
|
||||
/// A window whose only stop is the app's own canvas, between two of the app's own buttons: a bare Tab moves egui
|
||||
/// focus through egui's order, from nothing focused and from the canvas alike, and a canvas that keeps Tab keeps it.
|
||||
/// A window of the app's own canvas between two of the app's own buttons, with no framework stop: a bare Tab moves
|
||||
/// focus through them in the order the pass drew them, from nothing focused and from the canvas alike, and never
|
||||
/// reaches egui; a canvas that keeps Tab keeps it.
|
||||
#[trial]
|
||||
fn tab_moves_egui_focus_through_the_app_s_widgets_while_every_stop_is_a_host_stop() {
|
||||
fn tab_moves_through_the_app_s_widgets_and_canvas_in_a_window_without_framework_stops() {
|
||||
let (first, canvas, last) = (named_id("host first"), named_id("host canvas"), named_id("host last"));
|
||||
let keeps = Rc::new(Cell::new(false));
|
||||
let reached = Rc::new(Cell::new(false));
|
||||
@@ -567,9 +568,9 @@ fn tab_moves_egui_focus_through_the_app_s_widgets_while_every_stop_is_a_host_sto
|
||||
frames.frame(Vec::new(), &mut *show);
|
||||
(egui_focused(&frames.ctx), reached.get())
|
||||
};
|
||||
assert_eq!(tab(&mut frames, &mut show), (Some(first), true), "Tab from nothing gives egui focus to the first widget in egui's order");
|
||||
assert_eq!(tab(&mut frames, &mut show), (Some(canvas), true), "the next Tab reaches the canvas");
|
||||
assert_eq!(tab(&mut frames, &mut show), (Some(last), true), "Tab from the canvas moves on through egui's order");
|
||||
assert_eq!(tab(&mut frames, &mut show), (Some(first), false), "Tab from nothing focuses the first widget drawn");
|
||||
assert_eq!(tab(&mut frames, &mut show), (Some(canvas), false), "the next Tab reaches the canvas");
|
||||
assert_eq!(tab(&mut frames, &mut show), (Some(last), false), "Tab from the canvas moves on");
|
||||
keeps.set(true);
|
||||
request(&frames.ctx, FocusTarget::Id(canvas));
|
||||
frames.idle(2, &mut show);
|
||||
@@ -577,6 +578,135 @@ fn tab_moves_egui_focus_through_the_app_s_widgets_while_every_stop_is_a_host_sto
|
||||
assert_eq!(tab(&mut frames, &mut show), (Some(canvas), true), "a canvas that keeps Tab gets it from egui and keeps the focus");
|
||||
}
|
||||
|
||||
/// The window the one-order trials show: the app's own button, a framework stop, the app's own single-line text field
|
||||
/// inside a framework scope, a framework stop and the app's own button, in that order.
|
||||
const MIXED: [&str; 5] = ["app first", "framework one", "app field", "framework two", "app last"];
|
||||
|
||||
fn mixed_window() -> impl FnMut(&mut Ui) {
|
||||
let mut text = String::new();
|
||||
move |ui: &mut Ui| {
|
||||
let [first, one, field, two, last] = MIXED.map(named_id);
|
||||
fixture::host_button(ui, first, Rect::from_min_size(Pos2::new(20.0, 300.0), egui::vec2(80.0, 30.0)));
|
||||
widget(ui, one);
|
||||
register_stop(ui.ctx(), Stop::new(one, KeyUse::of(Input::Pointer)));
|
||||
push_scope(ui.ctx(), named_id("group"), FocusPolicy::NONE, None);
|
||||
fixture::host_field(ui, field, &mut text);
|
||||
pop_scope(ui.ctx());
|
||||
widget(ui, two);
|
||||
register_stop(ui.ctx(), Stop::new(two, KeyUse::of(Input::Pointer)));
|
||||
fixture::host_button(ui, last, Rect::from_min_size(Pos2::new(420.0, 300.0), egui::vec2(80.0, 30.0)));
|
||||
}
|
||||
}
|
||||
|
||||
/// A Tab press with `mods`, released in the same frame, and the frame after it: where egui focus is then.
|
||||
fn tab_with(frames: &mut Frames, show: &mut impl FnMut(&mut Ui), mods: Modifiers) -> Option<Id> {
|
||||
frames.frame(vec![key_press(Key::Tab, mods), key_release(Key::Tab, mods)], &mut *show);
|
||||
frames.frame(Vec::new(), &mut *show);
|
||||
egui_focused(&frames.ctx)
|
||||
}
|
||||
|
||||
/// Every focusable egui widget the app draws is a Tab stop of the window's one order, where the pass drew it among the
|
||||
/// framework's stops, with no registration of its own: Tab from nothing visits the five in order and wraps, and
|
||||
/// Shift+Tab walks back.
|
||||
#[trial]
|
||||
fn tab_reaches_the_app_s_egui_widgets_beside_the_framework_stops_in_registration_order() {
|
||||
let mut show = mixed_window();
|
||||
let mut frames = Frames::new();
|
||||
frames.idle(2, &mut show);
|
||||
let order = MIXED.map(|name| Some(named_id(name)));
|
||||
let forward: Vec<Option<Id>> = (0..6).map(|_| tab_with(&mut frames, &mut show, Modifiers::NONE)).collect();
|
||||
assert_eq!(forward, [&order[..], &order[..1]].concat(), "Tab visits the five in the order the pass drew them, then wraps");
|
||||
let back: Vec<Option<Id>> = (0..5).map(|_| tab_with(&mut frames, &mut show, Modifiers::SHIFT)).collect();
|
||||
let reversed: Vec<Option<Id>> = order.iter().rev().copied().collect();
|
||||
assert_eq!(back, reversed, "Shift+Tab walks back from the first, wrapping to the last");
|
||||
}
|
||||
|
||||
/// F6 lands on the app's own widget in a pane whose only content it is.
|
||||
#[trial]
|
||||
fn f6_lands_on_an_app_widget_in_a_pane() {
|
||||
let button = named_id("app pane button");
|
||||
let mut show = move |ui: &mut Ui| {
|
||||
show_panes(ui);
|
||||
push_scope(ui.ctx(), named_id("app pane"), FocusPolicy::PANE, Some(Arc::from("App")));
|
||||
fixture::host_button(ui, button, Rect::from_min_size(Pos2::new(420.0, 300.0), egui::vec2(80.0, 30.0)));
|
||||
pop_scope(ui.ctx());
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
frames.idle(2, &mut show);
|
||||
focus_stop(&mut frames, &mut show, named_id("right"));
|
||||
let (focused, said) = pane_key(&mut frames, &mut show, Modifiers::NONE);
|
||||
assert_eq!(focused, Some(button), "F6 from the right pane goes to the app's pane and its button");
|
||||
assert!(said.contains(&"App".to_owned()), "and announces the pane: {said:?}");
|
||||
}
|
||||
|
||||
/// A focused multi-line text field of the app's own whose egui key filter keeps Tab (it locks focus) gets the Tab in
|
||||
/// egui and types it; a single-line field of the app's own moves on to the next stop.
|
||||
#[trial]
|
||||
fn an_app_field_that_keeps_tab_types_it_and_a_single_line_field_tabs_on() {
|
||||
let (code, line, after) = (named_id("app code"), named_id("app line"), named_id("framework after"));
|
||||
let texts = Rc::new(RefCell::new((String::new(), String::new())));
|
||||
let shared = Rc::clone(&texts);
|
||||
let mut show = move |ui: &mut Ui| {
|
||||
let mut texts = shared.borrow_mut();
|
||||
let (code_text, line_text) = &mut *texts;
|
||||
fixture::host_code_field(ui, code, code_text);
|
||||
fixture::host_field(ui, line, line_text);
|
||||
widget(ui, after);
|
||||
register_stop(ui.ctx(), Stop::new(after, KeyUse::of(Input::Pointer)));
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
frames.idle(2, &mut show);
|
||||
fixture::host_focus(&frames.ctx, code);
|
||||
frames.idle(2, &mut show);
|
||||
assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), Some(code), "the field that keeps Tab keeps the focus");
|
||||
assert!(texts.borrow().0.contains('\t'), "and types the Tab: {:?}", texts.borrow().0);
|
||||
fixture::host_focus(&frames.ctx, line);
|
||||
frames.idle(2, &mut show);
|
||||
assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), Some(after), "the single-line field's Tab moves on");
|
||||
assert_eq!(texts.borrow().1, "", "and types nothing");
|
||||
}
|
||||
|
||||
/// Where Tab reaches only text fields (the Mac's default), it reaches the app's own text field and skips the app's
|
||||
/// own buttons, as it skips the framework's.
|
||||
#[trial]
|
||||
fn tab_that_reaches_only_text_fields_reaches_the_app_s_field_and_skips_its_buttons() {
|
||||
let mut show = mixed_window();
|
||||
let mut frames = Frames::new();
|
||||
crate::runtime::windows::set_os(&frames.ctx, craft_host::target::Os::Mac);
|
||||
frames.root({
|
||||
let mut root = RootEnv::default();
|
||||
root.tab_all_controls = false;
|
||||
root
|
||||
});
|
||||
frames.idle(2, &mut show);
|
||||
let field = Some(named_id("app field"));
|
||||
assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), field, "Tab from nothing goes to the app's field");
|
||||
assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), field, "the field is the one entry: the next Tab stays on it");
|
||||
}
|
||||
|
||||
/// While an app's own egui popup is open, Tab is egui's, as Escape is: the framework moves no focus with it.
|
||||
#[trial]
|
||||
fn an_open_app_popup_keeps_tab() {
|
||||
let popup = named_id("host popup");
|
||||
let (host, mut base) = host_window();
|
||||
let mut show = move |ui: &mut Ui| {
|
||||
base(ui);
|
||||
areas::host_popup(ui, popup, Pos2::ZERO);
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
request(&frames.ctx, FocusTarget::Id(named_id("button")));
|
||||
frames.idle(2, &mut show);
|
||||
areas::open_host_popup(&frames.ctx, popup);
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
assert!(areas::host_popup_open(&frames.ctx, popup));
|
||||
seen(&host);
|
||||
press_key(&mut frames, &mut show, Key::Tab);
|
||||
assert_eq!(seen(&host).0, vec![Key::Tab], "the popup's Tab is egui's");
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "the framework moved no focus");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn escape_ends_an_egui_drag_on_a_host_widget() {
|
||||
let area = named_id("host drag area");
|
||||
|
||||
@@ -125,6 +125,34 @@ fn replayed_focus_stops_keep_their_own_target() {
|
||||
});
|
||||
}
|
||||
|
||||
// The app's own egui widgets drawn inside a recorded view are stops of its transcript, and none drawn before it; the
|
||||
// replay registers each once, where the view shows, after the widgets drawn before it.
|
||||
#[trial]
|
||||
fn a_recorded_view_holds_the_app_s_widgets_drawn_in_it_and_its_replay_registers_them_once() {
|
||||
let mut frames = Frames::new();
|
||||
let [before, inside] = [fixture::named_id("app before"), fixture::named_id("app inside")];
|
||||
let rect = |x: f32| Rect::from_min_size(Pos2::new(x, 100.0), Vec2::new(80.0, 30.0));
|
||||
let mut recorded = None;
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
let ctx = ui.ctx().clone();
|
||||
fixture::host_button(ui, before, rect(20.0));
|
||||
replay::open(&ctx);
|
||||
fixture::host_button(ui, inside, rect(120.0));
|
||||
recorded = Some(replay::close(&ctx, fixture::layer_of(ui)));
|
||||
});
|
||||
let recorded = recorded.expect("the frame ran");
|
||||
assert_eq!(recorded.focus.stop_ids().collect::<Vec<_>>(), [inside], "the transcript holds the widget drawn in the view alone");
|
||||
let mut order = Vec::new();
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
let ctx = ui.ctx();
|
||||
fixture::host_button(ui, before, rect(20.0));
|
||||
focus::replay(ctx, &recorded.focus);
|
||||
focus::stop_count(ctx);
|
||||
order = focus::tab_order(ctx, |_| true).into_iter().map(|(id, _)| id).collect();
|
||||
});
|
||||
assert_eq!(order, [before, inside], "the replay registers the view's widget once, after the one drawn before it");
|
||||
}
|
||||
|
||||
/// Records `stops` run inside a record, with `entering` the first-pass flag of the layer scope it pushes, inside the
|
||||
/// scope `outer` when one is given.
|
||||
fn layer_scope_record(frames: &mut Frames, outer: Option<egui::Id>, entering: bool) -> replay::Record {
|
||||
|
||||
@@ -3974,8 +3974,7 @@ The focus service: stops, scopes and roving groups registered per pass, the focu
|
||||
- `craft_ui::runtime::focus::FocusMove`: `pub enum FocusMove { Keys, Other }`. What moved the key focus.
|
||||
- `craft_ui::runtime::focus::FocusShape`: `pub enum FocusShape { Rect, Circle, Polygon(Vec<egui::Pos2>) }`. The shape the focus ring takes around a part.
|
||||
- `craft_ui::runtime::focus::has`: `pub fn has(ctx: &Context, id: Id) -> bool`. Whether focus is on the component `id` or on one of its parts (a canvas's editor part), from the focus record of
|
||||
- `craft_ui::runtime::focus::host_canvas`: `pub fn host_canvas(ctx: &Context, id: Id, keys: KeyUse)`. Registers the app's own egui widget `id`, drawn in the running pass, as its window's document canvas: a focus stop
|
||||
- `craft_ui::runtime::focus::host_stop`: `pub fn host_stop(ctx: &Context, id: Id, keys: KeyUse)`. Registers the app's own egui widget `id`, drawn in the running pass, as a focus stop with `keys`, in the window's one
|
||||
- `craft_ui::runtime::focus::host_canvas`: `pub fn host_canvas(ctx: &Context, id: Id, keys: KeyUse)`. Registers the app's own egui widget `id`, drawn in the running pass, as its window's document canvas: its focus stop
|
||||
- `craft_ui::runtime::focus::request`: `pub fn request(ctx: &Context, target: FocusTarget) -> bool`. Moves focus to `target`, leaves modality unchanged and asks the enclosing scroll owner to reveal it. Called
|
||||
- `craft_ui::runtime::focus::takes_letters`: `pub fn takes_letters(keys: &KeyUse) -> bool`. Whether a stop with these keys takes typed letters: a text field or a shortcut recorder. The letters a keytip or a
|
||||
- `craft_ui::runtime::focus::ActivateKeys`: `pub enum ActivateKeys { Neither, Enter, Space, Both }`. The keys that activate a component.
|
||||
|
||||
@@ -144,22 +144,21 @@ An app with its own eframe `App` calls the hooks in `craft::ui::shell::embed`. `
|
||||
| Each frame | `raw_input_hook` | `embed::before_input(ctx, \|output\| { ...; input })`: the closure receives the `FrameOutput` of the frame before (fired commands, announcements, chrome toggles) and returns the `FrameInput` for this frame (`RootEnv`, command states, the `Host`). eframe runs the hook for the main window only: an app that drops the window system's input there (an agent-driven session) sets `FrameInput::window_input(WindowInput::Dropped)` too, and the runtime drops it in every other OS window it hosts, before injected input joins. macOS Control+Click is the runtime's in every window; the app does not map it. |
|
||||
| Each frame | `logic`, after the app's own logic | `embed::logic(ctx, \|\| decision)`: the root window's close path. The closure runs only when the root window was asked to close, and returns `CloseDecision::Close` or `Hold`. |
|
||||
| Each pass | `ui`, before the app's UI | `embed::before_ui(ctx, frame)`: hands the runtime the root's native window (eframe's `Frame`, or any `raw_window_handle::HasWindowHandle`) on Windows, where the runtime answers the window's hit test (resize edges, the title bar's move area, snap layouts on the maximize button), and fits the root window to its monitor once. Native only; it needs no eframe feature of the facade. |
|
||||
| Each pass | `ui`, where the app draws its own document canvas | Optional: `ui::runtime::focus::host_canvas(ctx, id, KeyUse::CANVAS)` declares it as the window's canvas (Tab row below). |
|
||||
| Each pass | `ui`, where the app draws a widget of its own that Tab should reach | Optional: `ui::runtime::focus::host_stop(ctx, id, keys)` puts it into the window's one Tab order among the framework's stops (Tab row below). |
|
||||
| Each pass | `ui`, where the app draws its own document canvas | Optional: `ui::runtime::focus::host_canvas(ctx, id, KeyUse::CANVAS)` declares it as the window's canvas (Tab row below). Every other focusable egui widget the app draws is a Tab stop with no call: the window's one Tab order holds it among the framework's stops, in the order the pass draws them. |
|
||||
| Each pass | `ui`, last | Optional: `ui::runtime::keys::with_window_intents(ctx, rtl, \|intents\| ...)` reads the keys no component took (below). |
|
||||
|
||||
`install` takes over these parts of the context for the whole window, not only for framework components:
|
||||
|
||||
| What | Effect on the app's own egui code |
|
||||
| --- | --- |
|
||||
| Tab | Bare Tab moves framework focus and never reaches egui, unless the focused framework stop keeps Tab or an app's own widget has the focus (below), or nothing has the focus in a window that registered no focus stop: egui then moves its own focus into the app's widgets. A window with stops but no Tab entry (on the Mac, where Tab reaches only text fields by default) keeps the Tab from egui, which would otherwise focus framework controls the platform's rule skips. With `RootEnv::tab_toggles_chrome`, Tab toggles the chrome in a window that shows a document canvas, with nothing focused or the canvas focused, and arrives in `FrameOutput::chrome_toggles`. The canvas is a framework canvas, or the app's own egui canvas declared each pass with `ui::runtime::focus::host_canvas`. A canvas that keeps Tab (`KeyUse::CANVAS.with_keep(KeepKeys::Tab)`) gets the press in egui's input only while it has the focus; with nothing focused, Tab moves focus into the window or toggles the chrome, so the canvas cannot trap keyboard navigation. In a window with framework stops, the app's own widgets take part in Tab order as stops registered each pass with `host_stop`, in the order the pass registers them; a window whose stops are all the app's (`host_canvas`, `host_stop`) leaves Tab from nothing or from those stops to egui, whose order holds them with the app's other widgets. A focused canvas whose editor part keeps Tab reads Shift+Tab as `Intent::BackTab` (`EditorInput::BackTab`); no other stop gets it as an intent, and a text field keeps Shift+Tab as a focus move. |
|
||||
| Tab | Bare Tab moves focus over the window's one Tab order and never reaches egui, unless the focused framework stop keeps Tab, the app's own focused widget keeps it by its egui key filter (a multi-line `TextEdit` with `lock_focus`, a code editor), or an egui popup is open (below). The order holds the framework's stops and every focusable egui widget the app draws (egui's focus candidates of the pass), in the order the pass registers and draws them, each inside the framework scope it was drawn in; a `TextEdit` is a text stop. So the app's own menu bar, buttons and fields are reached where it draws them, with no registration. A window with stops but no Tab entry (on the Mac, where Tab reaches only text fields by default) keeps the Tab from egui, which would otherwise focus controls the platform's rule skips. With `RootEnv::tab_toggles_chrome`, Tab toggles the chrome in a window that shows a document canvas, with nothing focused or the canvas focused, and arrives in `FrameOutput::chrome_toggles`. The canvas is a framework canvas, or the app's own egui canvas declared each pass with `ui::runtime::focus::host_canvas`, which takes the canvas's keys at the canvas's place in the order. A canvas that keeps Tab (`KeyUse::CANVAS.with_keep(KeepKeys::Tab)`) gets the press in egui's input only while it has the focus; with nothing focused, Tab moves focus into the window or toggles the chrome, so the canvas cannot trap keyboard navigation. A focused canvas whose editor part keeps Tab reads Shift+Tab as `Intent::BackTab` (`EditorInput::BackTab`); no other stop gets it as an intent, and a text field keeps Shift+Tab as a focus move. |
|
||||
| F6 | F6 and Shift+F6 move between panes and never reach egui. They are the defaults of the commands `NavCommand::NextPane` and `NavCommand::PreviousPane` (ids `window.next_pane` and `window.previous_pane`; name them by `NavCommand::NextPane.id()` in code): a default chord that another command binds is that command's, and the overrides move or unbind them (`CommandInput::overrides`). An app whose own shortcut table keeps F6 unbinds them there. |
|
||||
| Escape | Plain Escape (Alt and Shift may be held) goes to the focused framework stop and its scopes; with no framework stop focused, it goes to the window as `Intent::Cancel`. A held Escape cancels once: its repeats raise no `Cancel`. It reaches egui only while an app's own widget has the focus (below). An Escape the runtime takes outside a captured framework press also ends egui's own drag in that pass, as egui's Escape does. |
|
||||
| F10, Alt+letter | Taken while a framework menu bar is registered: F10 (`NavCommand::FocusMenuBar`, id `window.focus_menu_bar`, bound and yielded as F6 is) focuses the bar, Alt+letter opens a menu (not on macOS) unless the keymap binds it to an enabled command, which runs instead. |
|
||||
| Claimed chords | The chords the app's canvas claims (`KeyUse::CANVAS.with_claims(..)` in `host_canvas`) stay in egui's input for it while it has the focus and, with nothing focused, while it is the window's key target; no command fires with them. On Windows and Linux, Alt+numpad code entry takes every other Alt+digit (egui reports keypad and top-row digits alike), so an app's Alt+digit shortcut works only when its canvas claims the chord. |
|
||||
| Edit chords | Taken while a framework editor is focused. With nothing focused, the edit chords and egui's copy, cut and paste events of the commands in the window canvas's edit set (`KeyUse::edits`, `host_canvas`) stay in egui's input for it, and no command fires with them. Otherwise egui's copy, cut and paste events become the ⌘C/X/V chord for the app's commands, unless an app's own widget has the focus (below). While egui holds a label text selection, copy and cut stay egui's, and egui copies the selection. |
|
||||
| IME | Taken while a framework editor owns the IME: its events and `PlatformOutput.ime` are the runtime's. Otherwise they stay egui's, for the app's own `TextEdit` or IME code. |
|
||||
| An app's own focused widget | While egui focus is on a widget no framework component made, or an egui popup is open, and no framework press or drag is captured, Tab, Shift+Tab, Escape and egui's clipboard events stay in egui's input for it, and the runtime routes nothing for them. While egui focus is on such a widget, the arrows and Tab move egui focus among the app's widgets as egui does; while a framework stop has the focus, egui's arrow moves are off. |
|
||||
| An app's own focused widget | While egui focus is on a widget no framework component made, or an egui popup is open, and no framework press or drag is captured, Escape, the plain Enter and egui's clipboard events stay in egui's input for it, and the runtime routes nothing for them; Tab and Shift+Tab are the window's focus moves (Tab row) unless the widget keeps Tab or the popup is open. While egui focus is on such a widget, the arrows move egui focus among the app's widgets as egui does; while a framework stop has the focus, egui's arrow moves are off. |
|
||||
| Releases | The release of every key the runtime took is taken too. |
|
||||
| Focus surrender | The runtime moves its own focus on press (8.3): a press a framework component takes moves focus to it; a press no component takes drops the framework's focus. egui's click-away never takes the framework's focus. egui's surrender option (`InputOptions::surrender_focus_on`) stays the app's and governs the focus of the app's own widgets, as in egui alone: a press no component takes leaves that focus to egui's rule. |
|
||||
| Clicks | egui's click options (`InputOptions::max_click_dist`, `max_click_duration`) stay the app's, for its own widgets. A framework component clicks and drags by the framework's press lifecycle: a release within the slop (`HitSizes::slop`), whatever its duration. Read a component's click with `contract::clicked(&response)` or its output's `clicked()`; egui's `Response::clicked()` on a component's response also needs a click by egui's options. |
|
||||
@@ -170,7 +169,7 @@ An app with its own eframe `App` calls the hooks in `craft::ui::shell::embed`. `
|
||||
| App modals | A modal the app draws with its own egui code blocks nothing outside egui by itself. While one shows, the app names its window each frame with `FrameInput::app_modal(Some(viewport))`: the app's other windows, panels floated into windows of their own among them, are then blocked as under a framework app-modal layer (their presses, keys, wheel and text are dropped, a press there brings the modal's window forward, and they refuse to close). |
|
||||
| Input pacing | One press per pass: extra presses in one frame wait for the next passes. A press outside an open framework menu closes the menu and goes no further. After an OS resize of the window, the held pointer is released. |
|
||||
|
||||
The window's keys are the ones the runtime routes to no component: an Escape or a plain Enter while nothing has the focus, neither a framework stop nor one of the app's own widgets or popups, and the arrows' nudge. The window's plain Enter also stays in egui's input. `with_window_intents` offers them to its closure while nothing has framework focus. The closure takes what it handles (`Intents::take(Intent::Cancel)`; `Intent` and the other types `Intents` reads are in `ui::runtime::keys`) and returns whether it took anything; the rest stays for later readers. A framework scope that ran earlier in the pass takes them first (an open dialog takes the Escape that closes it), so the app reads them last in its UI to see what no component took. App code that read `Key::Escape`, `Key::Tab`, F6 or F10 from egui while none of its own widgets had focus reads these intents and `FrameOutput::chrome_toggles` instead; its own focused widgets and popups keep reading Tab, Escape and the plain Enter from egui, and no window intent comes of them.
|
||||
The window's keys are the ones the runtime routes to no component: an Escape or a plain Enter while nothing has the focus, neither a framework stop nor one of the app's own widgets or popups, and the arrows' nudge. The window's plain Enter also stays in egui's input. `with_window_intents` offers them to its closure while nothing has framework focus. The closure takes what it handles (`Intents::take(Intent::Cancel)`; `Intent` and the other types `Intents` reads are in `ui::runtime::keys`) and returns whether it took anything; the rest stays for later readers. A framework scope that ran earlier in the pass takes them first (an open dialog takes the Escape that closes it), so the app reads them last in its UI to see what no component took. App code that read `Key::Escape`, `Key::Tab`, F6 or F10 from egui while none of its own widgets had focus reads these intents and `FrameOutput::chrome_toggles` instead; its own focused widgets and popups keep reading Escape and the plain Enter from egui (Tab only where the widget keeps it or a popup is open), and no window intent comes of them.
|
||||
|
||||
Framework dialogs the app keeps as values run on a `DialogHost`: the app calls `run(ui)` once per pass after its own UI and reads results with `take`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user