From 759abc01abef8db2ddb27438d2aa179515a762b4 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:04:56 +0000 Subject: [PATCH 1/9] The Magnetic Lasso closes within 8 screen points of its first point, so a click where the outline began closes it --- crates/imaging/src/ui/select/magnetic.rs | 16 ++++++++++------ crates/imaging/tests/it/select.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/imaging/src/ui/select/magnetic.rs b/crates/imaging/src/ui/select/magnetic.rs index bad19bebe..bd0c7e1be 100644 --- a/crates/imaging/src/ui/select/magnetic.rs +++ b/crates/imaging/src/ui/select/magnetic.rs @@ -9,7 +9,7 @@ use egui::{CornerRadius, Pos2, Rect as ScreenRect, Vec2}; use kurbo::Point; use serde::{Deserialize, Serialize}; -use super::lasso::{DraftKey, draft_command, outline_access, reach}; +use super::lasso::{DraftKey, draft_command, outline_access}; use super::{Place, Report, SelectEvent, SelectPhase, SelectToolPass, SelectionProbe, SelectionShape}; /// Where the magnetic lasso cursor's icon touches the document: the icon's own origin. @@ -521,7 +521,7 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { }); return ToolAction::Claimed; }; - if pointer.clicks >= 2 || o.near_start(p, close_radius(cx, &place)) { + if pointer.clicks >= 2 || o.near_start(p, close_radius(&place)) { tool.close(pointer.mods.alt); return ToolAction::Claimed; } @@ -635,7 +635,7 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { draw.stroke(&square, StrokeWidth::Thin, style.color(overlay.handle_stroke)); } if let Some(pointer) = cx.pointer - && o.near_start(place.doc(pointer.pos), close_radius(cx, &place)) + && o.near_start(place.doc(pointer.pos), close_radius(&place)) { // The closing cursor: a small circle beside the pointer. let ring = PaintShape::Circle(pointer.pos + side, tokens.shape.radius.sm); @@ -656,7 +656,11 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { } } -/// How near the first point a press closes the outline, in document units. -fn close_radius(cx: &ToolContext<'_>, place: &Place) -> f64 { - reach(cx).close / place.zoom().max(0.01) +/// How near the first point a press closes the outline, in screen points. Wider than the slop: the first point snaps +/// to the edge, a few points from the press that placed it, and a press back where the outline began closes it. +const CLOSE_REACH: f64 = 8.0; + +/// [`CLOSE_REACH`] in document units. +fn close_radius(place: &Place) -> f64 { + CLOSE_REACH / place.zoom().max(0.01) } diff --git a/crates/imaging/tests/it/select.rs b/crates/imaging/tests/it/select.rs index 31372842a..5b662dc61 100644 --- a/crates/imaging/tests/it/select.rs +++ b/crates/imaging/tests/it/select.rs @@ -891,6 +891,20 @@ fn magnetic_closes_by_start_click_double_click_or_enter_and_retracts_to_the_firs assert!(rig.tool_mut().events().is_empty(), "retracting commits nothing"); } +// The first point snaps to the edge a few points from the press that placed it, farther than the slop: a click back +// where the outline began closes it, as a click on the start itself does. +#[trial] +fn a_click_where_the_magnetic_outline_began_closes_it() { + let (mut rig, _) = magnetic(); + let began = CENTRE + circle_offset(0.0) * ((RADIUS + 5.0) / RADIUS); + click(&mut rig, pt(began), NONE); + glide_along(&mut rig, 0.0, std::f64::consts::TAU); + rig.fixture().advance(1.0); + click(&mut rig, pt(began), NONE); + let points = committed_polygon(&rig.tool_mut().events()); + assert!(points.len() >= 3 && points.iter().all(|&p| on_circle(p)), "a click where the outline began closes: {points:?}"); +} + // `[` and `]` change the width by 1 within 1..=256 while an outline is open. // With `pressure_width` on, a pen sample at pressure 0.5 halves the searched width (minus one); a mouse sample never From c481e1c1fd53216cd2200c25d38a5e3d968ada63 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:06:12 +0000 Subject: [PATCH 2/9] The freehand Lasso follows every move from its press, so a lasso drawn inside the click distance selects --- crates/imaging/src/ui/select/lasso.rs | 8 +++++--- crates/imaging/tests/it/select.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/imaging/src/ui/select/lasso.rs b/crates/imaging/src/ui/select/lasso.rs index cf3dee6f5..25f9a8461 100644 --- a/crates/imaging/src/ui/select/lasso.rs +++ b/crates/imaging/src/ui/select/lasso.rs @@ -401,10 +401,12 @@ impl CanvasTool for SelectToolPass<'_, LassoTool> { outline_access(self.tool.draft.points(), cx) } - /// A selection drag takes every move from the press, so a drag of a pixel or two moves the selection; - /// [`MoveGesture::left_press`](craft_behavior::geometry::MoveGesture::left_press) alone decides its click. + /// A selection drag and an outline with the button down take every move from the press: a drag of a pixel or two + /// moves the selection, and the outline follows the pointer from where it went down, so a lasso drawn inside the + /// click distance still selects. [`MoveGesture::left_press`](craft_behavior::geometry::MoveGesture::left_press) + /// decides a selection drag's click, and the draft an outline's (fewer than 3 points, [`OutlineDraft::close`]). fn takes_every_move(&self) -> bool { - self.tool.inside.is_some() + self.tool.inside.is_some() || self.tool.draft.is_down() } fn command_form(&self) -> ToolPath { diff --git a/crates/imaging/tests/it/select.rs b/crates/imaging/tests/it/select.rs index 5b662dc61..4a302e8e5 100644 --- a/crates/imaging/tests/it/select.rs +++ b/crates/imaging/tests/it/select.rs @@ -614,6 +614,22 @@ fn a_lasso_click_deselects_only_in_new_mode() { ); } +// A freehand outline drawn inside the click distance still closes into a selection: the lasso follows the pointer from +// the press, and only an outline of fewer than three points is a click. +#[trial] +fn a_lasso_drawn_inside_the_click_distance_selects() { + let mut rig = rig("Lasso", LassoTool::new(), Fake::empty()); + down(&mut rig, (100.0, 100.0), NONE); + for point in [(101.0, 100.0), (100.0, 100.75)] { + drag_to(&mut rig, point, NONE); + } + up(&mut rig, (100.0, 100.75), NONE); + assert!( + matches!(rig.tool_mut().events().as_slice(), [SelectEvent::Commit { operation: SelectionOperation::New, .. }]), + "a lasso a pixel across selects" + ); +} + // The outline keeps the operation its first press latched: Alt at the press over a selection subtracts, and letting go // of Alt during the drag changes neither the operation the tool reports nor the commit's. No outline, no operation. #[trial] From 375a29d4809b942f3498aa119325b1d694ee9749 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:09:47 +0000 Subject: [PATCH 3/9] A dialog opened in a pass takes that pass's Escape wherever it was routed, also after the opening press moved focus --- crates/ui-contract/src/runtime/keys.rs | 2 +- .../ui-contract/src/runtime/keys/intents.rs | 23 +++++++++++++- crates/ui-contract/src/runtime/overlay.rs | 4 +-- crates/ui-contract/src/testing/key_trials.rs | 31 ++++++++++++++++++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/src/runtime/keys.rs b/crates/ui-contract/src/runtime/keys.rs index 27f4b4f2a..43505c8e5 100644 --- a/crates/ui-contract/src/runtime/keys.rs +++ b/crates/ui-contract/src/runtime/keys.rs @@ -40,7 +40,7 @@ pub use intents::settle; pub use intents::take_submit; pub use intents::with_window_intents; pub(crate) use intents::{ - Lent, context_part, context_request, give_back, lend, request_context, route_whole_reset, scope_escape, take_cancel, take_window_cancel, + Lent, context_part, context_request, give_back, lend, request_context, route_whole_reset, scope_escape, take_cancel, take_every_escape, take_window_cancel, }; pub(crate) use nodes::{redirect_node, register_expanded, register_node}; pub use route::focus_holds; diff --git a/crates/ui-contract/src/runtime/keys/intents.rs b/crates/ui-contract/src/runtime/keys/intents.rs index 66f271c39..102d82524 100644 --- a/crates/ui-contract/src/runtime/keys/intents.rs +++ b/crates/ui-contract/src/runtime/keys/intents.rs @@ -5,7 +5,7 @@ use super::{Stage, current}; use crate::runtime::focus::{self}; use craft_behavior::focus::{EscapeFacts, EscapeStep, escape_step}; use craft_behavior::{AccessRequest, CancelRule, EditCommand, EditorInput, Intent, MoveMods, NavMove, PartRef}; -use craft_keymap::{Chord, Mods}; +use craft_keymap::{Chord, Key, Mods}; use egui::{Context, Id, Vec2}; use std::sync::Arc; @@ -454,6 +454,27 @@ fn take_untaken(ctx: &Context, intent: &Intent) -> bool { current(ctx, |stage| take_from(stage, focused, intent)) } +/// Takes every Escape of this pass that no component has taken, wherever the runtime routed it: the untaken `Cancel` +/// of every stop and of the window, and every Escape chord held for a claim or a capture. For a dialog opened in this +/// pass, the top layer from then on: the stop the keys were routed to need not hold focus any more, since the press +/// that opened the dialog may have moved it. +pub(crate) fn take_every_escape(ctx: &Context) -> bool { + if crate::runtime::measure::active(ctx) { + return false; + } + current(ctx, |stage| { + let mut taken = false; + for routed in stage.routed.values_mut() { + let before = routed.items.len(); + routed.items.retain(|item| !item.intent.same_kind(&Intent::Cancel)); + taken |= routed.items.len() != before; + } + let before = stage.claimed.len(); + stage.claimed.retain(|(_, chord)| chord.key != Key::Escape); + taken || stage.claimed.len() != before + }) +} + /// What an untaken Escape does in a scope: `None` when no Escape arrived or a component took it. One scope /// takes each Escape. pub(crate) fn scope_escape(ctx: &Context, rule: CancelRule, press_captured: bool, scope_clearable: bool) -> Option { diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index 7bdf79228..ec0c1c0db 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -634,10 +634,10 @@ pub fn stack_place(ctx: &Context, place: usize, dialog: Id, show: impl FnOnce } /// A dialog host opened a dialog in this pass: it is the top layer from now on, so the Escape that arrived in this -/// pass is its, and the focused stop beneath it gets no Cancel. +/// pass is its, and nothing beneath it gets a Cancel or a claimed Escape, wherever focus is now. #[doc(hidden)] pub fn take_keys_for_new_dialog(ctx: &Context) { - crate::runtime::keys::take_cancel(ctx); + crate::runtime::keys::take_every_escape(ctx); } /// A dialog host removed `dialog`: the layers it showed for it (`stack_place`) in the running or the last pass end diff --git a/crates/ui-contract/src/testing/key_trials.rs b/crates/ui-contract/src/testing/key_trials.rs index 7d83352a4..c8acfb1d7 100644 --- a/crates/ui-contract/src/testing/key_trials.rs +++ b/crates/ui-contract/src/testing/key_trials.rs @@ -8,7 +8,7 @@ use crate::runtime::keys::{intents_of, take_shortcuts}; use crate::testing::focus::{Stop, egui_focused, named_id, register_stop, widget}; use crate::testing::input::{key_press, key_repeat}; use crate::testing::{Frames, trial}; -use craft_behavior::Input; +use craft_behavior::{Input, Intent}; use craft_keymap::Overrides; use egui::{Id, Key, Modifiers, Ui, ViewportId}; use std::sync::Arc; @@ -169,3 +169,32 @@ fn a_recorder_holds_its_presses_from_the_app() { frames.frame(vec![key_press(Key::K, Modifiers::COMMAND | Modifiers::SHIFT)], &mut show); assert!(!saw.get(), "the app reads no press the recorder holds"); } + +// A dialog opened in a pass takes that pass's Escape, also when the press that opened it moved focus off the stop the +// Escape was routed to: the stop it left gets no Cancel. +#[trial] +fn a_dialog_opened_in_a_pass_takes_its_escape_after_focus_moved() { + let opens = std::rc::Rc::new(std::cell::Cell::new(false)); + let cancels = std::rc::Rc::new(std::cell::Cell::new(0)); + let (open, seen) = (std::rc::Rc::clone(&opens), std::rc::Rc::clone(&cancels)); + let mut show = move |ui: &mut Ui| { + stop(ui, "button", KeyUse::of(Input::Pointer)); + stop(ui, "canvas", KeyUse::CANVAS); + if open.get() { + // The press on the button that opens the dialog takes focus first. + request(ui.ctx(), FocusTarget::Id(id("button"))); + crate::runtime::overlay::take_keys_for_new_dialog(ui.ctx()); + } + if intents_of(ui.ctx(), Some(id("canvas")), false).untaken(&Intent::Cancel) { + seen.set(seen.get() + 1); + } + }; + let mut frames = shown(false, &mut show); + focus_on(&mut frames, &mut show, "canvas"); + press(&mut frames, &mut show, Key::Escape, Modifiers::NONE); + assert_eq!(cancels.get(), 1, "with no dialog opening, the focused canvas gets the Escape"); + focus_on(&mut frames, &mut show, "canvas"); + opens.set(true); + press(&mut frames, &mut show, Key::Escape, Modifiers::NONE); + assert_eq!(cancels.get(), 1, "the dialog opened in the pass takes it"); +} From d8a6478210b98a146a92511b286e162200cbcee0 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:11:45 +0000 Subject: [PATCH 4/9] The checkerboard's light cell sits at the picture's top-left corner on screen, wherever the view puts it --- crates/ui-canvas/src/canvas/raster/mod.rs | 4 +++- crates/ui-canvas/tests/it/canvas/raster.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/ui-canvas/src/canvas/raster/mod.rs b/crates/ui-canvas/src/canvas/raster/mod.rs index 5fc64edce..8aa376bbd 100644 --- a/crates/ui-canvas/src/canvas/raster/mod.rs +++ b/crates/ui-canvas/src/canvas/raster/mod.rs @@ -534,8 +534,10 @@ impl Component for RasterDisplay<'_> { [areas.next(), areas.next()] } }; + // A light cell sits at the picture's top-left corner on screen, wherever the view puts the picture. + let origin = corners.map_or(shown.view.rect.min, |corners| corners[0]); for area in areas.into_iter().flatten() { - painter.painter.add(checker.shape(painter.painter.ctx(), &ui.env.tokens, CheckerArea::Quad(area), shown.view.rect.min)); + painter.painter.add(checker.shape(painter.painter.ctx(), &ui.env.tokens, CheckerArea::Quad(area), origin)); } } match (&mut self.picture, &shown.textures, &self.mapping) { diff --git a/crates/ui-canvas/tests/it/canvas/raster.rs b/crates/ui-canvas/tests/it/canvas/raster.rs index 08f84ef20..60ba2e63c 100644 --- a/crates/ui-canvas/tests/it/canvas/raster.rs +++ b/crates/ui-canvas/tests/it/canvas/raster.rs @@ -129,6 +129,24 @@ fn the_checkerboard_paints_the_same_shapes_at_any_area() { assert_eq!(small, large, "a checkerboard over the whole canvas paints as many shapes as one over a corner of it"); } +// The checkerboard's light cell sits at the document's top-left corner on screen, wherever the view puts the document, +// not at a corner of the canvas. +#[trial] +fn the_checkerboard_starts_with_a_light_cell_at_the_document_corner() { + for (width, height, zoom) in [(100, 70, 1.0), (64, 64, 0.5), (90, 30, 1.5)] { + let document = Document::new(width, height); + let center = Point::new(f64::from(width) / 2.0, f64::from(height) / 2.0); + let corner = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), center, zoom).to_screen(Point::ZERO); + let mut rig = rig(document, zoom); + let shapes = rig.fixture.frame_shapes(); + let checker = *textured(&shapes).first().expect("the checkerboard"); + let at_corner = checker.vertices.iter().find(|vertex| vertex.pos.distance(corner) < 0.5).expect("a checkerboard corner at the document's"); + let whole = |v: f32| (v - v.round()).abs() < 1e-3; + // The texture repeats every two cells, light first: a whole texture coordinate is a light cell's top-left. + assert!(whole(at_corner.uv.x) && whole(at_corner.uv.y), "{width} x {height} at {zoom}: a light cell starts at the document's corner: {:?}", at_corner.uv); + } +} + /// A canvas at 800 percent whose body shows, as a document canvas does, the pasteboard with the document's page and /// its shadow, a display of `document` with the checkerboard and the edge, and the pixel grid over it. While `painted` /// is set the display is a painted one: the app's paint adds a GPU paint callback, as an app with its own compositor From 860e108d52fd03d87eb1c1ca1d8dd2eee254c0ae Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:17:32 +0000 Subject: [PATCH 5/9] A row notice in an unbounded room keeps its natural width (DIAG: notice rooms and the Content-Aware Fill body rect) --- crates/imaging/src/ui/fill/mod.rs | 11 +++++++++++ crates/ui-widgets/src/notices/notice.rs | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/imaging/src/ui/fill/mod.rs b/crates/imaging/src/ui/fill/mod.rs index 878cf50f3..3311ebfed 100644 --- a/crates/imaging/src/ui/fill/mod.rs +++ b/crates/imaging/src/ui/fill/mod.rs @@ -651,6 +651,17 @@ impl ContentAwareFillWorkspace { self.apply_reset(FillReset::FillArea); } + { + let test = std::thread::current().name().unwrap_or("?").rsplit("::").next().unwrap_or("?").to_owned(); + if test.starts_with("an_erased_sampling") || test.starts_with("brush_strokes_change") { + eprintln!( + "DIAG {test}: fill body max_rect {:?} available {:?} measuring {}", + ui.max_rect(), + ui.available_size(), + craft_ui::runtime::measure::active(ui.ctx()) + ); + } + } Row::new().fill().show(ui, |ui, _| { let rail = ToolRail::new(words.tools.clone(), slots, &self.tool, &self.last_used).show_rail(ui, |_, _| {}); if let Some(next) = rail.last_used { diff --git a/crates/ui-widgets/src/notices/notice.rs b/crates/ui-widgets/src/notices/notice.rs index ceb52d767..6c4ae9ae6 100644 --- a/crates/ui-widgets/src/notices/notice.rs +++ b/crates/ui-widgets/src/notices/notice.rs @@ -558,9 +558,15 @@ impl Component for Notice<'_> { room.map_or(width, |room| width.min(room)) } (NoticeLayout::Centred, None) => natural.min(cx.style.reading_width), - (_, Some(room)) => room, - (_, None) => natural, + // A row notice takes the room it is given; an unbounded room (a column sized by its content) leaves it at + // its natural width. + (_, Some(room)) if room.is_finite() => room, + (_, _) => natural, }; + if !width.is_finite() || cx.room.is_some_and(|room| !room.is_finite()) { + let test = std::thread::current().name().unwrap_or("?").rsplit("::").next().unwrap_or("?").to_owned(); + eprintln!("DIAG {test}: notice measure room {:?} natural {natural} width {width}", cx.room); + } Vec2::new(width, self.plan(cx, &texts, self.wrap_width(cx, width)).height) } From 66072b36430297809956d0e940a57d4c0f1fab32 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:20:20 +0000 Subject: [PATCH 6/9] Replay notes come only from the thread that runs the pass: a job thread's wake or progress report no longer takes the pass state --- crates/ui-contract/src/runtime/replay.rs | 5 ++++- crates/ui-contract/src/testing/mod.rs | 1 + .../ui-contract/src/testing/replay_trials.rs | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 crates/ui-contract/src/testing/replay_trials.rs diff --git a/crates/ui-contract/src/runtime/replay.rs b/crates/ui-contract/src/runtime/replay.rs index 6ae7d5d91..6f1c4589e 100644 --- a/crates/ui-contract/src/runtime/replay.rs +++ b/crates/ui-contract/src/runtime/replay.rs @@ -139,7 +139,10 @@ pub(crate) fn replay(ctx: &Context, record: &Record) { } fn with_open(ctx: &Context, f: impl FnOnce(&mut Facts)) { - if OPEN.load(Ordering::Acquire) > 0 { + // Records are open only around runs of a pass on its own thread. A job's thread (a finished job's wake, a progress + // report) runs no pass of `ctx`: it has no record to note into and must not take the pass state that the pass's + // thread holds. + if OPEN.load(Ordering::Acquire) > 0 && frame::running(ctx).is_some() { pass_state::with::(ctx, |recorder| { if let Some(open) = recorder.open.last_mut() { f(&mut open.facts); diff --git a/crates/ui-contract/src/testing/mod.rs b/crates/ui-contract/src/testing/mod.rs index 9568a7694..57e5054ff 100644 --- a/crates/ui-contract/src/testing/mod.rs +++ b/crates/ui-contract/src/testing/mod.rs @@ -23,6 +23,7 @@ pub mod memory; pub mod pictures; pub mod pointer; pub mod relations; +mod replay_trials; pub mod sensing; #[cfg(all(feature = "snapshot", not(target_arch = "wasm32")))] pub mod snapshot; diff --git a/crates/ui-contract/src/testing/replay_trials.rs b/crates/ui-contract/src/testing/replay_trials.rs new file mode 100644 index 000000000..69b9f5c35 --- /dev/null +++ b/crates/ui-contract/src/testing/replay_trials.rs @@ -0,0 +1,21 @@ +//! Trials of the replay records' notes. + +use crate::runtime::egui::{fixture, repaint}; +use crate::runtime::replay; +use crate::testing::{Frames, trial}; + +// A job's thread asks for a pass (a finished job's wake, a progress report) while a pass of the same context records a +// region on the UI thread: the request notes nothing in that pass's records and leaves its pass state alone. +#[trial] +fn a_repaint_from_a_job_thread_leaves_the_running_pass_s_records_alone() { + let mut frames = Frames::new(); + let mut joined = None; + frames.frame(Vec::new(), |ui| { + let ctx = ui.ctx().clone(); + replay::open(&ctx); + let worker = ctx.clone(); + joined = Some(std::thread::spawn(move || repaint::request(&worker)).join().is_ok()); + let _record = replay::close(&ctx, fixture::layer_of(ui)); + }); + assert_eq!(joined, Some(true), "the job thread's repaint request returns"); +} From 82610cb78bab8b8e6de2d55bf010e6b8d9b0dc4d Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:20:53 +0000 Subject: [PATCH 7/9] Checkerboard trial: documents whose corners land on whole points --- crates/ui-canvas/tests/it/canvas/raster.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-canvas/tests/it/canvas/raster.rs b/crates/ui-canvas/tests/it/canvas/raster.rs index 60ba2e63c..79c44ae0f 100644 --- a/crates/ui-canvas/tests/it/canvas/raster.rs +++ b/crates/ui-canvas/tests/it/canvas/raster.rs @@ -133,7 +133,7 @@ fn the_checkerboard_paints_the_same_shapes_at_any_area() { // not at a corner of the canvas. #[trial] fn the_checkerboard_starts_with_a_light_cell_at_the_document_corner() { - for (width, height, zoom) in [(100, 70, 1.0), (64, 64, 0.5), (90, 30, 1.5)] { + for (width, height, zoom) in [(100, 70, 1.0), (64, 64, 0.5), (80, 40, 1.5)] { let document = Document::new(width, height); let center = Point::new(f64::from(width) / 2.0, f64::from(height) / 2.0); let corner = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), center, zoom).to_screen(Point::ZERO); From 33b48b72a77919025ad8a789c24653a457ded862 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:25:09 +0000 Subject: [PATCH 8/9] Every Label node reads its words by value as well as its name, by one rule in the node writer; the label scope's patch only makes a hidden label's node, and a short caption is named by its full words --- crates/ui-contract/src/contract/label/leaf.rs | 10 ++++ crates/ui-contract/src/contract/label/step.rs | 3 ++ .../ui-contract/src/runtime/access/scope.rs | 4 +- .../src/runtime/egui/access/node.rs | 11 ++++- .../src/runtime/egui/access/patch.rs | 11 ++--- crates/ui-contract/tests/it/access/mod.rs | 1 + .../tests/it/access/static_text.rs | 49 +++++++++++++++++++ 7 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 crates/ui-contract/tests/it/access/static_text.rs diff --git a/crates/ui-contract/src/contract/label/leaf.rs b/crates/ui-contract/src/contract/label/leaf.rs index 8af330cec..ad573beb5 100644 --- a/crates/ui-contract/src/contract/label/leaf.rs +++ b/crates/ui-contract/src/contract/label/leaf.rs @@ -6,6 +6,7 @@ use crate::contract::InBar; use crate::contract::{Component, Props}; use crate::contract::{Cx, MeasureCx, PaintUi, PartsCx, Styled as _}; use crate::primitives::{IconSpec, TextRun, Wrap}; +use crate::runtime::access::{Access, Name}; use crate::runtime::env::{Env, Label}; use crate::runtime::words::CommonWords; use crate::style::{ComponentStyle, ResetMarkLook, Stateful, StyleColor, StyleCx, TextLook, TypeRole}; @@ -92,6 +93,8 @@ pub(super) struct LabelLeaf { pub(super) trailing: Vec2, /// The name shows; false for a label that shows only its content (`SideLabel::content_only`). pub(super) named: bool, + /// The words a short label stands for: its accessible name; `None` names it by the text it shows. + pub(super) words: Option, double_click: bool, dot_click: bool, activated: bool, @@ -129,6 +132,7 @@ impl LabelLeaf { claimed: false, trailing: Vec2::ZERO, named: true, + words: None, double_click: false, dot_click: false, activated: false, @@ -252,6 +256,12 @@ impl Component for LabelLeaf { Vec2::new(width + self.slot, height) } + fn access(&self, access: &mut Access, _: &Cx<'_, Self>) { + if let Some(words) = &self.words { + access.name(Name::Text(words.clone())); + } + } + /// A click on the label focuses its control (the scope's `FieldLabel::activated`), so a label takes clicks; a /// claimed label is its control's to sense. fn sense(&self) -> Sense { diff --git a/crates/ui-contract/src/contract/label/step.rs b/crates/ui-contract/src/contract/label/step.rs index 181740eb6..c8dc3dacd 100644 --- a/crates/ui-contract/src/contract/label/step.rs +++ b/crates/ui-contract/src/contract/label/step.rs @@ -165,6 +165,9 @@ pub(crate) fn run(ui: &mut Ui, env: &Env, input: &LabelIn<'_>, trailing: Option< leaf.differs = reset.as_ref().is_some_and(|fact| fact.differs); leaf.default = reset.as_ref().and_then(|fact| fact.default.clone()); leaf.named = !input.side.content_only(content); + if matches!(input.side.kind, LabelKind::Short(_)) { + leaf.words = Some(input.text.as_str().to_owned()); + } leaf.colon = colon(env, input).filter(|_| leaf.named); leaf.after = input.side.layout == FieldLayout::After; leaf.claimed = input.claims; diff --git a/crates/ui-contract/src/runtime/access/scope.rs b/crates/ui-contract/src/runtime/access/scope.rs index 6fddf4a36..999882d85 100644 --- a/crates/ui-contract/src/runtime/access/scope.rs +++ b/crates/ui-contract/src/runtime/access/scope.rs @@ -451,8 +451,8 @@ pub(crate) struct Merged { /// One change a label scope makes to a node, decided here and written by `runtime::egui::access`. #[derive(Clone, Debug, PartialEq)] pub(crate) enum LabelPatch { - /// The label's own node: the role `Label` and the label's text, each only where the node has none yet, and - /// disabled when every control it labels is. + /// The label's own node: made with the role `Label` and the label's text where no component wrote it (a hidden + /// label), and disabled when every control it labels is. Label { id: Id, text: String, disabled: bool }, /// `node` keeps its name and is described by `label`. DescribedBy { node: Id, label: Id }, diff --git a/crates/ui-contract/src/runtime/egui/access/node.rs b/crates/ui-contract/src/runtime/egui/access/node.rs index 59e1d2771..6fcfcab2f 100644 --- a/crates/ui-contract/src/runtime/egui/access/node.rs +++ b/crates/ui-contract/src/runtime/egui/access/node.rs @@ -163,6 +163,15 @@ fn write_numeric(node: &mut accesskit::Node, numeric: &Numeric) { } } +/// Names `node` `text`, after its role is set. A `Label` also reads its words by value, as AccessKit expects of static +/// text and egui names its own labels; a value written later (`NodeSpec::value`) replaces it. +pub(crate) fn write_name(node: &mut accesskit::Node, text: &str) { + node.set_label(text.to_owned()); + if node.role() == accesskit::Role::Label { + node.set_value(text.to_owned()); + } +} + fn write_identity(node: &mut accesskit::Node, spec: &NodeSpec) { node.set_role(spec.role); if let Some(rect) = spec.rect { @@ -172,7 +181,7 @@ fn write_identity(node: &mut accesskit::Node, spec: &NodeSpec) { node.set_hidden(); } if let Some(text) = &spec.label { - node.set_label(text.clone()); + write_name(node, text); } if let Some(text) = &spec.description { node.set_description(text.clone()); diff --git a/crates/ui-contract/src/runtime/egui/access/patch.rs b/crates/ui-contract/src/runtime/egui/access/patch.rs index 2acf1cb48..b820ae389 100644 --- a/crates/ui-contract/src/runtime/egui/access/patch.rs +++ b/crates/ui-contract/src/runtime/egui/access/patch.rs @@ -9,16 +9,11 @@ pub(crate) fn write_label_patch(ctx: &Context, patch: &LabelPatch) { match patch { LabelPatch::Label { id, text, disabled } => { ctx.accesskit_node_builder(*id, |node| { + // A shown label's leaf wrote its node, named, in this pass; a hidden label has no component, and its + // node is made here, named by the same rule. if node.role() == accesskit::Role::Unknown { node.set_role(accesskit::Role::Label); - } - // A `Label` is named by its value, as egui names its own labels; other roles by their label. - if node.role() == accesskit::Role::Label { - if node.value().is_none() { - node.set_value(text.clone()); - } - } else if node.label().is_none() { - node.set_label(text.clone()); + super::node::write_name(node, text); } if *disabled { node.set_disabled(); diff --git a/crates/ui-contract/tests/it/access/mod.rs b/crates/ui-contract/tests/it/access/mod.rs index 0cf44771a..67a826aac 100644 --- a/crates/ui-contract/tests/it/access/mod.rs +++ b/crates/ui-contract/tests/it/access/mod.rs @@ -5,5 +5,6 @@ mod face_record; mod face_state; mod nodes; mod scope; +mod static_text; mod sub_node_keys; mod viewports; diff --git a/crates/ui-contract/tests/it/access/static_text.rs b/crates/ui-contract/tests/it/access/static_text.rs new file mode 100644 index 000000000..046e6431f --- /dev/null +++ b/crates/ui-contract/tests/it/access/static_text.rs @@ -0,0 +1,49 @@ +//! Static text reads its words by value, as AccessKit expects of a `Label`. + +use craft_ui::contract::{Common, Component, Cx, PaintUi, Props as _, Role, Show as _}; +use craft_ui::primitives::TextRun; +use craft_ui::style::StyleCx; +use craft_ui::testing::{Fixture, trial}; +use craft_ui_test_kit::contract::PlainStyle; +use egui::{Pos2, Rect, Response}; + +const AT: Rect = Rect { min: Pos2::new(10.0, 10.0), max: Pos2::new(310.0, 40.0) }; + +/// A line of static text, named by its label, as a display text is. +#[derive(craft_ui::contract::Component)] +struct Words { + #[common] + common: Common, +} + +impl Component for Words { + const ROLE: Role = Role::LABEL; + type Style = PlainStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: WordsStyleKey) -> PlainStyle { + PlainStyle::default() + } + + fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { + ui.draw().text(cx.content_rect, &TextRun::new(cx.resolved.label)); + } + + fn finish(self, cx: Cx<'_, Self>) -> Response { + cx.response.clone() + } +} + +// A plain text's node carries its words as its value, where assistive technology and kittest read a `Label`'s words, +// as well as its name. +#[trial] +fn a_plain_text_reads_its_words_by_value() { + let mut fixture = Fixture::new(|ui| { + Words { common: Common::new() }.label("Esc to cancel").show_at(ui, AT); + }); + fixture.settle(); + let tree = fixture.tree(); + let labels = tree.with_role(Role::LABEL); + let node = labels.iter().copied().find(|key| tree.name_of(*key) == Some("Esc to cancel")).expect("the text's node"); + assert_eq!(tree.value_of(node), Some("Esc to cancel"), "the words are the node's value"); +} From f34f115a9acebc9ce3d264279e3fae231d52d3df Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:29:30 +0000 Subject: [PATCH 9/9] A minimized dock group is closed: the body step runs its header alone, and its body leaves no node or hit record --- crates/ui-panels/src/docking/group.rs | 11 +++++++- crates/ui-panels/tests/it/dock_group.rs | 35 +++++++++++++++++++++++++ crates/ui-panels/tests/it/main.rs | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 crates/ui-panels/tests/it/dock_group.rs diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 9ad29c1e5..80a8b4a76 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -8,7 +8,7 @@ use super::words::DockWords; use super::{PanelDrag, PanelKey, PanelTitle}; use crate::buttons::IconButton; use crate::contract::{ - Access, BodyCx, Common, Component, Container, ContainerProps, ContextMenuRequest, Cx, HeaderEdge, HeaderParts, HeaderRegion, ListDrag, MeasureCx, + Access, Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, ContextMenuRequest, Cx, HeaderEdge, HeaderParts, HeaderRegion, ListDrag, MeasureCx, Name, Outcome, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, PopupKind, Props as _, Role, ShowCollection as _, ShowContainer as _, Sizing, WordSetCx as _, }; @@ -220,6 +220,8 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> { /// Only the header shows; the body and its drop spots are left out. #[prop(flag)] minimized: bool, + /// The open state the body step reads: closed while minimized, so no body runs. + open: Bind<'a, bool>, /// The grip drags the group. #[prop] movable: bool, @@ -266,6 +268,7 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> { panels, active, minimized: false, + open: Bind::given(true), movable: true, closable: false, wheel_selects_tabs: false, @@ -409,6 +412,12 @@ impl Component for DockGroup<'_, P> { } impl Container for DockGroup<'_, P> { + /// Closed while minimized: the body step runs the header alone, and the body leaves no node, shape or stop. + fn open(&mut self) -> Option> { + self.open = Bind::given(!self.minimized); + Some(self.open.reborrow()) + } + /// The drag band, then the panel menu button when it shows, at the header's end edge. fn header_parts(&self, cx: &MeasureCx<'_, Self>) -> HeaderParts { let band = grip_width(cx.tokens); diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs new file mode 100644 index 000000000..7ad349b83 --- /dev/null +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -0,0 +1,35 @@ +//! A docked panel group. + +use craft_ui::buttons::Button; +use craft_ui::contract::{Show as _, ShowContainer as _}; +use craft_ui::docking::{DockGroup, PanelKey, PanelTitle}; +use craft_ui::testing::{Fixture, trial}; +use egui::{Pos2, Rect, Vec2}; +use std::cell::Cell; +use std::rc::Rc; + +// A minimized group shows its header alone: its body does not run, so it leaves no node and nothing a press could +// reach under the groups below it. Expanded, the same body shows. +#[trial] +fn a_minimized_group_runs_no_body() { + let body = |minimized: bool| { + let runs = Rc::new(Cell::new(0)); + let counted = Rc::clone(&runs); + let panels = vec![PanelTitle::new(PanelKey::new(1), "Color")]; + let mut fixture = Fixture::new(move |ui| { + let group = DockGroup::new(1usize, &panels, panels[0].key); + let group = if minimized { group.minimized() } else { group }; + let counted = Rc::clone(&counted); + group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(240.0, 200.0)), move |ui, _| { + counted.set(counted.get() + 1); + Button::new("Body button").show(ui); + }); + }); + fixture.idle(4); + let found = fixture.by_label("Body button").is_some(); + (runs.get(), found) + }; + let (runs, found) = body(false); + assert!(runs > 0 && found, "an expanded group shows its body: {runs} runs, node {found}"); + assert_eq!(body(true), (0, false), "a minimized group runs no body and leaves no node"); +} diff --git a/crates/ui-panels/tests/it/main.rs b/crates/ui-panels/tests/it/main.rs index ba3b1d0fb..1a8ff8e60 100644 --- a/crates/ui-panels/tests/it/main.rs +++ b/crates/ui-panels/tests/it/main.rs @@ -6,6 +6,7 @@ extern crate craft_ui_panels as craft_ui; mod access; pub(crate) mod body; mod dialogs; +mod dock_group; // outer edit mod edit; // end of outer edit