Header brand and Home are Tab stops, tab strips are one stop, keyboard focus reads the framework's focused node

This commit is contained in:
aiongg
2026-11-24 22:24:26 +00:00
parent 74f2d1e8dc
commit 9df2d92bfa
3 changed files with 16 additions and 10 deletions
+4 -4
View File
@@ -813,9 +813,9 @@ pub fn base64(data: &[u8]) -> String {
pub fn inspect(app: &EffectcraftApp, ctx: &egui::Context) -> Value {
// A logic-only tick refreshes the viewport information but not `InputState`'s screen rect.
let size = ctx.input(|i| i.viewport().inner_rect).map_or_else(|| ctx.content_rect().size(), |r| r.size());
let keyboard_focus = ctx.memory(|m| m.focused()).map(|id| {
let response = ctx.read_response(id);
let rect = response.as_ref().map(|r| [r.rect.min.x, r.rect.min.y, r.rect.width(), r.rect.height()]);
let keyboard_focus = craft_ui::runtime::access::focused_node(ctx).or_else(|| ctx.memory(|m| m.focused())).map(|id| {
let automation = app.auto.elements.iter().chain(app.auto.previous.iter()).find(|e| e.response_id == Some(id));
let rect = ctx.read_response(id).map(|r| [r.rect.min.x, r.rect.min.y, r.rect.width(), r.rect.height()]).or_else(|| automation.map(|e| e.rect));
// The registry names screen elements independently of egui's internal ids. Report
// exact rectangle matches rather than guessing which enclosing panel owns focus.
let candidates: Vec<&str> = app
@@ -825,7 +825,7 @@ pub fn inspect(app: &EffectcraftApp, ctx: &egui::Context) -> Value {
.filter(|e| rect.is_some_and(|r| e.rect.iter().zip(r).all(|(a, b)| (*a - b).abs() < 0.01)))
.map(|e| e.id.as_str())
.collect();
let automation_id = app.auto.elements.iter().chain(app.auto.previous.iter()).find(|e| e.response_id == Some(id)).map(|e| e.id.as_str());
let automation_id = automation.map(|e| e.id.as_str());
json!({"id": format!("{:016x}", id.value()), "rect": rect, "automationId": automation_id, "registryCandidates": candidates})
});
let mut ui = json!(app.ui);
+2
View File
@@ -43,6 +43,7 @@ fn brand_and_home(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter
paint_logo(p, brand);
let bresp = ui.interact(brand, egui::Id::unique("brand"), Sense::click());
app.auto.add_response("header.about", &bresp, "About EffectCraft");
craft_ui::runtime::focus::host_stop(ui.ctx(), bresp.id, KeyUse::of(Input::Pointer));
widgets::focus_outline(ui, &bresp, &t);
if bresp.on_hover_text(tr("About EffectCraft")).clicked() {
app.dialog = Some(Dialog::About);
@@ -52,6 +53,7 @@ fn brand_and_home(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter
let home = Rect::from_min_size(pos2(x, cy - 13.0), vec2(26.0, 26.0));
let home_response = widgets::icon_button(ui, home, Icon::Home, app.ui.start_screen, &t, egui::Id::unique("tool-home")).on_hover_text(tr("Home"));
app.auto.add_response("header.home", &home_response, "Home");
craft_ui::runtime::focus::host_stop(ui.ctx(), home_response.id, KeyUse::of(Input::Pointer));
if home_response.clicked() {
app.ui.start_screen = !app.ui.start_screen;
}
+10 -6
View File
@@ -189,10 +189,12 @@ fn tab_traversal_activates_an_inactive_dock_tab_without_editing_the_project() {
for _ in 0..200 {
key(&mut h, Key::Tab, Modifiers::NONE);
tabs += 1;
if tab_focused(&h, target) {
if tab_focused(&h, "Project") {
break;
}
}
assert!(tab_focused(&h, "Project"));
key(&mut h, Key::ArrowRight, Modifiers::NONE);
assert!(tab_focused(&h, target));
println!("Tab presses from no focus to Effect Controls: {tabs}");
assert_eq!(h.state().ui.dock, before, "traversal alone must not activate a tab");
@@ -205,7 +207,7 @@ fn tab_traversal_activates_an_inactive_dock_tab_without_editing_the_project() {
assert!(Arc::ptr_eq(&h.state().session.project, &project));
let inspected = effectcraft_ui_egui::control::inspect(h.state(), &h.ctx);
assert_eq!(inspected["keyboardFocus"]["automationId"], "panel.tab.EffectControls");
key(&mut h, Key::Tab, Modifiers::SHIFT);
key(&mut h, Key::ArrowLeft, Modifiers::NONE);
assert!(tab_focused(&h, "Project"));
key(&mut h, Key::Enter, Modifiers::NONE);
assert_eq!(h.state().ui.focused, PanelKind::Project);
@@ -295,15 +297,17 @@ fn control_root_divider_drag_after_toolbar_and_dock_tab_keyboard_activation() {
for tabs in 1..=200 {
d.ok("ui.key", json!({"key":"Tab"}), true);
assert!(d.h.state().ui.mini_flowchart.is_none(), "dock-tab traversal must not open a foreground popup");
if tab_focused(&d.h, target) {
println!("control Tab presses to Effect Controls: {tabs}");
if tab_focused(&d.h, "Project") {
println!("control Tab presses to Project: {tabs}");
break;
}
}
assert!(tab_focused(&d.h, target), "Effect Controls must remain reachable by control-channel Tab traversal");
// A tab strip is one Tab stop: Tab reaches the shown tab, the arrows move between tabs.
d.ok("ui.key", json!({"key":"ArrowRight"}), true);
assert!(tab_focused(&d.h, target), "Effect Controls must remain reachable by control-channel keyboard traversal");
d.ok("ui.key", json!({"key":"Space"}), true);
assert_eq!(d.h.state().ui.focused, PanelKind::EffectControls);
d.ok("ui.key", json!({"key":"Tab","shift":true}), true);
d.ok("ui.key", json!({"key":"ArrowLeft"}), true);
d.ok("ui.key", json!({"key":"Enter"}), true);
assert_eq!(d.h.state().ui.focused, PanelKind::Project);
let before = d.h.state().ui.dock.clone();