mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 22:37:12 +00:00
Editor part: its focus widget is an egui focus candidate only while its component takes focus, so egui's arrows never reach a disabled editor; trial ids through the crate's id helpers
This commit is contained in:
@@ -72,7 +72,8 @@ pub(crate) fn run<C: Component>(cx: &mut Cx<'_, C>, ui: &mut Ui, step: &mut supe
|
||||
}
|
||||
let (ctx, id) = (cx.core.ctx.clone(), cx.core.id);
|
||||
let widget = ImeSurface::of(id, decl.key).widget();
|
||||
let focused = egui_editor::show(ui, widget, decl.rect, egui_focus::event_filter(keys.keep, false));
|
||||
let focusable = super::steps::takes_focus(cx.core.resolved);
|
||||
let focused = egui_editor::show(ui, widget, decl.rect, egui_focus::event_filter(keys.keep, false), focusable);
|
||||
// The focus widget is the component's, enabled or not: it is never one of the app's own widgets (`take_app_widgets`).
|
||||
crate::runtime::pointer::record_text_widget(&ctx, widget, id);
|
||||
let read_only = cx.core.resolved.read_only || !cx.core.resolved.enabled;
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
use egui::{EventFilter, Id, Rect, Ui};
|
||||
|
||||
/// Registers the editor's focus widget over `rect` and applies `filter` while it holds focus; returns whether it holds
|
||||
/// focus.
|
||||
pub(crate) fn show(ui: &mut Ui, id: Id, rect: Rect, filter: EventFilter) -> bool {
|
||||
let response = ui.interact(rect, id, egui::Sense::focusable_noninteractive());
|
||||
/// focus. The widget is one of egui's focus candidates only while `focusable` (its component takes focus), so neither
|
||||
/// Tab nor egui's arrows reach the editor of a disabled component.
|
||||
pub(crate) fn show(ui: &mut Ui, id: Id, rect: Rect, filter: EventFilter, focusable: bool) -> bool {
|
||||
let sense = if focusable { egui::Sense::focusable_noninteractive() } else { egui::Sense::hover() };
|
||||
let response = ui.interact(rect, id, sense);
|
||||
let focused = response.has_focus();
|
||||
if focused {
|
||||
ui.memory_mut(|memory| memory.set_focus_lock_filter(id, filter));
|
||||
|
||||
@@ -714,9 +714,13 @@ fn each_focus_candidate_of_a_pass_is_classified_once() {
|
||||
let lookups = |n: usize| {
|
||||
let mut show = move |ui: &mut Ui| {
|
||||
for at in 0..n {
|
||||
fixture::host_button(ui, Id::new(("app", at)), Rect::from_min_size(Pos2::new(10.0, 30.0 * at as f32), egui::vec2(60.0, 20.0)));
|
||||
widget(ui, Id::new(("framework", at)));
|
||||
register_stop(ui.ctx(), Stop::new(Id::new(("framework", at)), KeyUse::of(Input::Pointer)));
|
||||
fixture::host_button(
|
||||
ui,
|
||||
crate::runtime::egui::memory::unique(("app", at)),
|
||||
Rect::from_min_size(Pos2::new(10.0, 30.0 * at as f32), egui::vec2(60.0, 20.0)),
|
||||
);
|
||||
widget(ui, crate::runtime::egui::memory::unique(("framework", at)));
|
||||
register_stop(ui.ctx(), Stop::new(crate::runtime::egui::memory::unique(("framework", at)), KeyUse::of(Input::Pointer)));
|
||||
}
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
|
||||
@@ -1030,16 +1030,21 @@ fn an_alt_chord_bound_only_out_of_scope_leaves_its_text_typed() {
|
||||
assert!(fired.is_empty(), "nothing ran: {fired:?}");
|
||||
}
|
||||
|
||||
/// A disabled editor registers no stop, and its focus widget is still the component's own: it never becomes a Tab stop
|
||||
/// of the app's own widgets. With every control in Tab order, Tab and Shift+Tab land on the button beside it each time.
|
||||
/// A disabled editor registers no stop, and its focus widget is still the component's own and no egui focus candidate:
|
||||
/// it never becomes a Tab stop of the app's own widgets, and egui's arrows from the app's own focused widget never
|
||||
/// reach it. With every control in Tab order, Tab and Shift+Tab land on the button beside it each time.
|
||||
#[trial]
|
||||
fn tab_never_focuses_a_disabled_editor_s_widget() {
|
||||
let log = RefCell::new(Vec::new());
|
||||
let seen = RefCell::new(Seen::default());
|
||||
let (editor, button) = (Cell::new(Id::NULL), Cell::new(Id::NULL));
|
||||
// The app's own egui button, level with the editor on its right: the editor lies straight to its left.
|
||||
let app = craft_ui::testing::focus::named_id("app button");
|
||||
let app_at = Rect::from_min_size(Pos2::new(AT.right() + 40.0, AT.center().y - 10.0), egui::vec2(60.0, 20.0));
|
||||
let mut show = |ui: &mut egui::Ui| {
|
||||
editor.set(Probe::new(&log, true).label("Source").enabled(false).id_salt("code").show_at(ui, AT).id);
|
||||
button.set(Button::new(&seen).id_salt("next").show_at(ui, NEXT).id);
|
||||
ui.interact(app_at, app, egui::Sense::click());
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
frames.root({
|
||||
@@ -1053,6 +1058,17 @@ fn tab_never_focuses_a_disabled_editor_s_widget() {
|
||||
frames.frame(vec![key_press(Key::Tab, mods), key_release(Key::Tab, mods)], &mut show);
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
let focused = craft_ui::testing::focus::egui_focused(&frames.ctx);
|
||||
assert_eq!(focused, Some(button.get()), "Tab (shift {shift}) lands on the button, never on the disabled editor {:?}", editor.get());
|
||||
assert!(
|
||||
focused == Some(button.get()) || focused == Some(app),
|
||||
"Tab (shift {shift}) lands on a control, never on the disabled editor {:?}: {focused:?}",
|
||||
editor.get()
|
||||
);
|
||||
}
|
||||
craft_ui::runtime::focus::request(&frames.ctx, craft_ui::runtime::focus::FocusTarget::Id(app));
|
||||
frames.idle(2, &mut show);
|
||||
assert_eq!(craft_ui::testing::focus::egui_focused(&frames.ctx), Some(app), "the app's button has the focus");
|
||||
frames.frame(vec![key_press(Key::ArrowLeft, Modifiers::NONE), key_release(Key::ArrowLeft, Modifiers::NONE)], &mut show);
|
||||
frames.frame(Vec::new(), &mut show);
|
||||
let focused = craft_ui::testing::focus::egui_focused(&frames.ctx);
|
||||
assert!(focused == Some(app) || focused == Some(button.get()), "the arrow never reaches the disabled editor {:?}: {focused:?}", editor.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user