From bb4c8268190b1e45f37f0bc24c2c51d015b470f2 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 25 Nov 2026 02:00:59 +0000 Subject: [PATCH] Bypass walk: the stop every focusable egui widget gets by itself (Stop::automatic) is no registration, so a raw egui widget beside a component is a finding again --- crates/ui-contract/src/runtime/focus/nav.rs | 5 ++--- crates/ui-contract/src/runtime/focus/registration.rs | 10 ++++++++-- crates/ui-contract/src/testing/bypass.rs | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/ui-contract/src/runtime/focus/nav.rs b/crates/ui-contract/src/runtime/focus/nav.rs index 3284bb4f1..f40500b34 100644 --- a/crates/ui-contract/src/runtime/focus/nav.rs +++ b/crates/ui-contract/src/runtime/focus/nav.rs @@ -231,11 +231,10 @@ impl State { /// 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 + /// (`Stop::automatic`). 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 { - 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))) + !made && !self.stops.iter().chain(&self.last_stops).any(|rec| !rec.stop.automatic() && (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 diff --git a/crates/ui-contract/src/runtime/focus/registration.rs b/crates/ui-contract/src/runtime/focus/registration.rs index 56eaddb64..a83dc80a2 100644 --- a/crates/ui-contract/src/runtime/focus/registration.rs +++ b/crates/ui-contract/src/runtime/focus/registration.rs @@ -37,8 +37,8 @@ pub struct Stop { /// The arena root the stop is shown in (a canvas whose body holds it), whether or not it joined the arena: a text /// stop keeps its own egui widget. A removed stop hands focus back to it. pub arena: Option, - /// The app's own egui widget (`focus::host_canvas`), which reads its keys from egui's input: the key stage leaves - /// the presses it routes to the stop there. + /// The app's own egui widget (`focus::host_canvas`, or any focusable egui widget the app draws), which reads its + /// keys from egui's input: the key stage leaves the presses it routes to the stop there. pub host: bool, } @@ -128,6 +128,12 @@ impl Stop { self } + /// Whether this is the stop every focusable egui widget the app draws gets by itself (`focus::take_app_widgets`): + /// the app's own widget, not declared as its canvas (`KeyUse::chrome_key`). No component or app call registered it. + pub fn automatic(&self) -> bool { + self.host && !self.keys.chrome_key + } + pub(crate) fn key(&self) -> StopKey { (self.id, self.part) } diff --git a/crates/ui-contract/src/testing/bypass.rs b/crates/ui-contract/src/testing/bypass.rs index ec44a2076..815bf3628 100644 --- a/crates/ui-contract/src/testing/bypass.rs +++ b/crates/ui-contract/src/testing/bypass.rs @@ -1,7 +1,8 @@ //! Bypass detection (24.2): the pass-end walk that finds what a component made without the runtime. //! //! Every interactive egui widget of the latest pass must be one a component registered (a root or one of its -//! widgets, a focus stop's root) or one the runtime noted. Every AccessKit node that declares an action must +//! widgets, the root of a focus stop that something registered: not the stop every focusable egui widget gets by +//! itself, `Stop::automatic`) or one the runtime noted. Every AccessKit node that declares an action must //! come from the runtime's node writer. A raw `ui.interact`, `ui.button` or `ui.add(Slider)` in a component //! fails here, with the id of the offender. @@ -24,7 +25,7 @@ pub fn findings(fixture: &Fixture) -> Vec { let mut registered: HashSet = pointer::registered_widgets(ctx); registered.extend(noted_widgets); focus::with_viewport(ctx, egui::ViewportId::ROOT, |state| { - registered.extend(state.stops.iter().chain(&state.last_stops).map(|rec| rec.stop.root)); + registered.extend(state.stops.iter().chain(&state.last_stops).filter(|rec| !rec.stop.automatic()).map(|rec| rec.stop.root)); }); let mut found: Vec = widgets::interactive(ctx) .into_iter()