diff --git a/crates/draw/src/ui/measure/stories.rs b/crates/draw/src/ui/measure/stories.rs index b3ef964242..573bdf4e52 100644 --- a/crates/draw/src/ui/measure/stories.rs +++ b/crates/draw/src/ui/measure/stories.rs @@ -9,7 +9,7 @@ use craft_ui::bars::{Bar, BarKind}; use craft_ui::canvas::RasterSource as _; use craft_ui::contract::{Bind, Show as _, ShowContainer as _}; use craft_ui::testing::canvas_story::{OUTLINE, StoryDocument, StoryPicture, StoryShape, accent, on_picture, paint_shapes}; -use craft_ui::testing::{Drive, Grip, StoryData, StoryHost, StoryOutput, ToolStory, story, tool_story}; +use craft_ui::testing::{Drive, EditKind, Grip, StoryData, StoryHost, StoryOutput, ToolStory, story, tool_story}; use egui::{Color32, Ui}; fn line() -> RulerLine { @@ -43,10 +43,12 @@ fn ruler_tool(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let _ = host.run(ui, &mut tool.pass(*line)); }; tool_story(ui, data, ToolStory::new("Document", &picture), RulerTool::new, Some(line()), body, |run| { - for event in run.tool.take_events() { + let events = run.tool.take_events(); + let edits = events.iter().filter_map(EditKind::of).collect(); + for event in events { let _ = event.apply(run.document); } - StoryOutput::default() + StoryOutput { edits, ..StoryOutput::default() } }) } diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index ca0efe6d2c..2e13fda468 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -343,7 +343,7 @@ fn show_row( let title_line = if icons.untitled { 0.0 } else { launcher_side }; let start = cx.style::().map_or(0.0, |style| style.start); // The row moves through the slide container's own offset, which places its body on a layer of its own. - let shown = Region::slide(lead) + let _ = Region::slide(lead) .show(ui, |ui, _| { // The row's line is as high as its tallest group, at least the body's least height over a title line: // every group fills the line, so the titles at the groups' feet share one line. @@ -355,26 +355,23 @@ fn show_row( body(&mut row, key); row.groups }); - (row.output.id, row.output.rect, row.inner.unwrap_or_default()) + chevrons(ui, row.output.id, row.output.rect, &row.inner.unwrap_or_default(), chevron); }) .inner; - if let Some((owner, view, groups)) = shown { - chevrons(ui, owner, view, &groups, chevron, lead); - } }) .output } /// The edge chevrons of a row `view` whose `groups` do not all show: one at each edge that has a group past it, each /// stepping the scrolling body `owner` by one group toward its side (`contract::scroll_step`). `view` and `groups` are -/// in the points of the row's layer, which the slide offsets by `lead`; the chevrons sit at the edges as they show. +/// in the points of the row's layer; the chevrons share that layer so they paint and take input above its content. /// `width` is a chevron's width. -fn chevrons(ui: &mut Ui, owner: Id, view: Rect, groups: &[Rect], width: f32, lead: f32) { +fn chevrons(ui: &mut Ui, owner: Id, view: Rect, groups: &[Rect], width: f32) { // Half a point past the edge counts as inside: less than a pixel shows at any scale. let left = groups.iter().any(|group| group.min.x < view.min.x - 0.5); let right = groups.iter().any(|group| group.max.x > view.max.x + 0.5); let words = Env::of(ui).words::(); - let edges = view.translate(vec2(lead, 0.0)); + let edges = view; let size = Vec2::new(width, view.height()); for (on, right_side, icon, name) in [(left, false, "chevron_left", words.scroll_left.clone()), (right, true, "chevron_right", words.scroll_right.clone())] diff --git a/crates/ui-contract/src/contract/run/typed.rs b/crates/ui-contract/src/contract/run/typed.rs index c3e9e325e1..5f41548806 100644 --- a/crates/ui-contract/src/contract/run/typed.rs +++ b/crates/ui-contract/src/contract/run/typed.rs @@ -772,12 +772,17 @@ pub(crate) fn paint_face( if !source.reported { return (baseline, None); } - let name = cx.core.paint.borrow().elided.clone().unwrap_or_else(|| step1.label.as_str().to_owned()); // The face's own `access` adds its facts; the composite's step 16 fills the part's sub-node from the record. let mut access = Access::default(); #[cfg(feature = "testing")] crate::runtime::measure::count_access_build(&ctx); face.access(&mut access, &cx); + let name = match access.name { + crate::runtime::access::Name::FromLabel => { + crate::runtime::access::Name::Text(cx.core.paint.borrow().elided.clone().unwrap_or_else(|| step1.label.as_str().to_owned())) + } + name => name, + }; let record = FaceRecord { part, name, diff --git a/crates/ui-contract/src/contract/steps/report.rs b/crates/ui-contract/src/contract/steps/report.rs index 5976dc39f8..07d8cdbb53 100644 --- a/crates/ui-contract/src/contract/steps/report.rs +++ b/crates/ui-contract/src/contract/steps/report.rs @@ -228,7 +228,7 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_> } } if let Some(folded) = &folded { - keys::register_node(ctx, id, folded.inner, None, focusable); + keys::register_node(ctx, id, folded.inner, None, focusable, false); } let editor_record = || { let widget = core.editor.as_ref()?.widget; diff --git a/crates/ui-contract/src/primitives/record.rs b/crates/ui-contract/src/primitives/record.rs index dbba9becea..b4ed185dda 100644 --- a/crates/ui-contract/src/primitives/record.rs +++ b/crates/ui-contract/src/primitives/record.rs @@ -54,8 +54,8 @@ impl std::fmt::Debug for Adopted { pub struct FaceRecord { /// The part the face looks for. pub part: PartRef, - /// The instance's resolved label, the full text when elided. - pub name: String, + /// The face's declared accessible name, or its resolved label when it declares none. + pub name: crate::runtime::access::Name, /// The face's value flags. pub flags: crate::style::Flags, /// The face's role. diff --git a/crates/ui-contract/src/runtime/access.rs b/crates/ui-contract/src/runtime/access.rs index 4cf96c8067..0f88126e1c 100644 --- a/crates/ui-contract/src/runtime/access.rs +++ b/crates/ui-contract/src/runtime/access.rs @@ -519,7 +519,7 @@ pub struct SubNode { /// A numeric value: the value, its range and, with a step, the Increment and Decrement actions; SetValue is /// declared with any numeric value. Increment and Decrement arrive as `take_access` requests naming the part, /// including when it is focusable. Handle these before `take_move` or `take_move_where`, which convert untaken - /// requests to plain Forward or Back moves. SetValue arrives through `take_set_value_at(part)`. + /// requests on focusable numeric parts to plain Forward or Back moves. SetValue arrives through `take_set_value_at(part)`. pub numeric: Option, /// A plain text value, for a sub-node that has one and no number. pub(crate) value: Option, diff --git a/crates/ui-contract/src/runtime/access/emit.rs b/crates/ui-contract/src/runtime/access/emit.rs index 74bccc7196..299b6a355e 100644 --- a/crates/ui-contract/src/runtime/access/emit.rs +++ b/crates/ui-contract/src/runtime/access/emit.rs @@ -84,7 +84,7 @@ pub struct SubDecl<'a> { /// What the face painted for a part adds to the part's sub-node. #[doc(hidden)] pub struct FaceFacts<'a> { - pub name: &'a str, + pub name: &'a Name, pub flags: Flags, pub numeric: Option<&'a Numeric>, pub expanded: Option, @@ -329,7 +329,7 @@ pub(crate) fn report(ctx: &Context, own: &Own<'_>) { .controls(!relations.controls.is_empty()), true, ); - keys::register_node(ctx, own.id, own.id, None, own.focusable); + keys::register_node(ctx, own.id, own.id, None, own.focusable, numeric.is_some()); keys::register_expanded(ctx, own.id, expanded); scope::register( ctx, @@ -367,11 +367,13 @@ pub fn report_sub(ctx: &Context, decl: &SubDecl<'_>) { widths: &run.widths, }, ); - keys::register_node(ctx, id, decl.owner, Some(node.part), false); + keys::register_node(ctx, id, decl.owner, Some(node.part), false, false); return; } - let face_name = decl.face.as_ref().map(|face| face.name); - let name = named(&node.name, face_name.unwrap_or(decl.label), &[]); + let name = match (&node.name, decl.face.as_ref()) { + (Name::FromLabel, Some(face)) => named(face.name, decl.label, &[]), + (name, _) => named(name, decl.label, &[]), + }; if name.hidden { return; } @@ -423,7 +425,7 @@ pub fn report_sub(ctx: &Context, decl: &SubDecl<'_>) { .expanded(expanded), false, ); - keys::register_node(ctx, id, decl.owner, Some(node.part), decl.focusable); + keys::register_node(ctx, id, decl.owner, Some(node.part), decl.focusable, numeric.is_some()); keys::register_expanded(ctx, id, expanded); if decl.active { adapter::set_focus(ctx, id); diff --git a/crates/ui-contract/src/runtime/access/text.rs b/crates/ui-contract/src/runtime/access/text.rs index 46d255a9aa..8c3e1da1d2 100644 --- a/crates/ui-contract/src/runtime/access/text.rs +++ b/crates/ui-contract/src/runtime/access/text.rs @@ -113,7 +113,7 @@ pub(crate) fn report_text(ctx: &Context, owner: Id, facts: &TextFacts, unit: Opt &RunNode { id, parent: owner, rect: line.rect, text, rtl: run.rtl, positions: &run.positions, widths: &run.widths }, ); let index = u64::try_from(entries.len()).ok(); - keys::register_node(ctx, id, owner, Some(PartRef { key: RUN, index }), false); + keys::register_node(ctx, id, owner, Some(PartRef { key: RUN, index }), false, false); entries.push(Entry { node: adapter::node_key(id), line: line_at, bytes: run.bytes.clone(), text: text.to_owned() }); } } diff --git a/crates/ui-contract/src/runtime/keys.rs b/crates/ui-contract/src/runtime/keys.rs index 9e1f035709..c54cb94899 100644 --- a/crates/ui-contract/src/runtime/keys.rs +++ b/crates/ui-contract/src/runtime/keys.rs @@ -251,6 +251,7 @@ struct Source { #[derive(Clone, Default)] struct Routed { items: Vec, + numeric_parts: Vec, nudge: Option, /// The chords a recorder stop's presses spell this pass. chords: Vec, @@ -264,6 +265,7 @@ struct Node { owner: Id, part: Option, focusable: bool, + numeric: bool, /// The node's expanded state this pass, `None` when it has none. expanded: Option, } diff --git a/crates/ui-contract/src/runtime/keys/intents.rs b/crates/ui-contract/src/runtime/keys/intents.rs index e8f077bc8f..d3ca4f9f9f 100644 --- a/crates/ui-contract/src/runtime/keys/intents.rs +++ b/crates/ui-contract/src/runtime/keys/intents.rs @@ -16,6 +16,8 @@ pub struct Intents { /// The press or text each of `items` came from (`keys::Item::source`); read by index, so an item pushed without /// one has none. sources: Vec>, + /// Only focusable numeric parts opt into the default move fallback; other parts have their own access actions. + numeric_parts: Vec, took_arrows: Vec, nudge: Option, chords: Vec, @@ -93,7 +95,7 @@ impl Intents { /// Takes the next move, whichever it is: for a component that acts on every move. A move taken is the component's, /// so the Page Up, Page Down, Home and End it takes never reach the scroll owner around it (a page view under a /// focused page part); a component that acts on some moves takes those with [`take_move_where`](Self::take_move_where) - /// and leaves the rest. Untaken numeric Increment and Decrement requests become plain Forward and Back moves; + /// and leaves the rest. Untaken focusable numeric Increment and Decrement requests become plain Forward and Back moves; /// components that need the requested part take those access requests first. pub fn take_move(&mut self) -> Option<(NavMove, MoveMods)> { self.take_move_where(|_, _| true) @@ -106,7 +108,7 @@ impl Intents { if *taken { return None; } - let (mv, mods) = move_of(item)?; + let (mv, mods) = move_of(item, &self.numeric_parts)?; wanted(mv, mods).then_some((at, mv, mods)) })?; self.items[at].1 = true; @@ -249,10 +251,10 @@ impl Intents { } /// Numeric requests retain their target until a component chooses default navigation. -fn move_of(intent: &Intent) -> Option<(NavMove, MoveMods)> { +fn move_of(intent: &Intent, numeric_parts: &[PartRef]) -> Option<(NavMove, MoveMods)> { match intent { Intent::Move(mv, mods) => Some((*mv, *mods)), - Intent::Access(request) => match request.action { + Intent::Access(request) if request.target.is_some_and(|part| numeric_parts.contains(&part)) => match request.action { accesskit::Action::Increment => Some((NavMove::Forward, MoveMods::PLAIN)), accesskit::Action::Decrement => Some((NavMove::Back, MoveMods::PLAIN)), _ => None, @@ -301,6 +303,7 @@ pub fn intents_of(ctx: &Context, id: Option, rtl: bool) -> Intents { Intents { items, sources, + numeric_parts: routed.numeric_parts, took_arrows: Vec::new(), nudge: routed.nudge, chords: routed.chords, diff --git a/crates/ui-contract/src/runtime/keys/nodes.rs b/crates/ui-contract/src/runtime/keys/nodes.rs index 5cb66d5313..d6b3c1886d 100644 --- a/crates/ui-contract/src/runtime/keys/nodes.rs +++ b/crates/ui-contract/src/runtime/keys/nodes.rs @@ -32,14 +32,14 @@ pub(crate) fn register_expanded(ctx: &Context, node: Id, expanded: Option) } /// Registers an AccessKit node so a request that targets it reaches `owner`. -pub(crate) fn register_node(ctx: &Context, node: Id, owner: Id, part: Option, focusable: bool) { +pub(crate) fn register_node(ctx: &Context, node: Id, owner: Id, part: Option, focusable: bool, numeric: bool) { crate::runtime::replay::journal( ctx, - || (node, owner, part, focusable), - |ctx, &(node, owner, part, focusable)| register_node(ctx, node, owner, part, focusable), + || (node, owner, part, focusable, numeric), + |ctx, &(node, owner, part, focusable, numeric)| register_node(ctx, node, owner, part, focusable, numeric), ); crate::runtime::replay::note_node_owner(ctx, owner); current(ctx, |stage| { - stage.nodes.insert(node_key(node), Node { owner, part, focusable, expanded: None }); + stage.nodes.insert(node_key(node), Node { owner, part, focusable, numeric, expanded: None }); }); } diff --git a/crates/ui-contract/src/runtime/keys/route.rs b/crates/ui-contract/src/runtime/keys/route.rs index 1acb560a76..1bc6db2923 100644 --- a/crates/ui-contract/src/runtime/keys/route.rs +++ b/crates/ui-contract/src/runtime/keys/route.rs @@ -864,8 +864,11 @@ fn route_access(ctx: &Context, request: &Action, nodes: &HashMap, rou Some(rec) => route_activate(ctx, &rec, routed, activated), None => push(routed, owner, Intent::Activate, false), }, - ActionKind::Increment | ActionKind::Decrement if node.part.is_some() => { - push(routed, owner, Intent::Access(request.request(node.part)), false) + ActionKind::Increment | ActionKind::Decrement if node.part.is_some() && (node.numeric || !node.focusable) => { + push(routed, owner, Intent::Access(request.request(node.part)), false); + if let Some(part) = node.part.filter(|_| node.numeric && node.focusable) { + routed.entry(owner).or_default().numeric_parts.push(part); + } } ActionKind::Increment => push(routed, owner, Intent::Move(NavMove::Forward, MoveMods::PLAIN), false), ActionKind::Decrement => push(routed, owner, Intent::Move(NavMove::Back, MoveMods::PLAIN), false), diff --git a/crates/ui-contract/src/testing/focus.rs b/crates/ui-contract/src/testing/focus.rs index 6ea67d6f4a..d8f22961ee 100644 --- a/crates/ui-contract/src/testing/focus.rs +++ b/crates/ui-contract/src/testing/focus.rs @@ -152,7 +152,7 @@ pub fn activated_member(ctx: &Context, root: Id) -> Option { /// Registers an AccessKit node so a request that targets it reaches `owner`. pub fn register_node(ctx: &Context, node: Id, owner: Id, part: Option, focusable: bool) { - keys::register_node(ctx, node, owner, part, focusable); + keys::register_node(ctx, node, owner, part, focusable, false); } /// The rect `id`'s context request of this pass opens at, when it made one. diff --git a/crates/ui-widgets/src/buttons/stories.rs b/crates/ui-widgets/src/buttons/stories.rs index 56d73c96cd..eb3070a5b9 100644 --- a/crates/ui-widgets/src/buttons/stories.rs +++ b/crates/ui-widgets/src/buttons/stories.rs @@ -400,7 +400,7 @@ fn toggle_button_on(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { } /// The story remembers the last activation's count so the readout survives settling passes. -#[story(ToggleButton<'static>, covers = [], drive = Drive::Custom(double_click_toggle), title = "Double click")] +#[story(ToggleButton<'static>, covers = [], title = "Double click")] fn toggle_button_double_click(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let shown = ToggleButton::new("Snap to grid", data.bind("double_click", false)).show(ui); let clicks = data.value("clicks", 0); @@ -416,13 +416,6 @@ fn toggle_button_double_click(ui: &mut Ui, data: &mut StoryData) -> StoryOutput StoryOutput::from(shown).readout(words) } -fn double_click_toggle(fixture: &mut Fixture) { - if let Some(toggle) = fixture.by_label("Snap to grid") { - fixture.click(&toggle); - fixture.click(&toggle); - } -} - #[story(ToggleButton<'static>, covers = [Default])] fn toggle_button(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let size = *data.choice("size", ControlSize::Md, &SIZES); diff --git a/crates/ui-widgets/src/tile_grid/grid/stories.rs b/crates/ui-widgets/src/tile_grid/grid/stories.rs index 6ac41de113..3813557250 100644 --- a/crates/ui-widgets/src/tile_grid/grid/stories.rs +++ b/crates/ui-widgets/src/tile_grid/grid/stories.rs @@ -25,7 +25,9 @@ fn editable_groups(ui: &mut Ui, data: &mut StoryData, moving: bool) -> StoryOutp let pictures = StoryPictures::of(ui.ctx()); let grid = TileGrid::new("Library").groups(&groups).can_rename_groups(); let grid = if moving { grid.can_move_groups() } else { grid }; - let out = grid.show_items(ui, &source, &mut |key, _| photo(&pictures, *key, 0)); + let mut ratings = Ratings::of(data, keys.len()); + let out = grid.show_items(ui, &source, &mut |key, _| photo(&pictures, *key, ratings.0[*key])); + ratings.apply(&out.events); for event in &out.events { match event { GridEvent::GroupRenamed { group, title, .. } => titles[order[*group]] = title.clone(), diff --git a/crates/ui-widgets/tests/it/text/step_arrows.rs b/crates/ui-widgets/tests/it/text/step_arrows.rs index a99cd0ff10..20c2f44b20 100644 --- a/crates/ui-widgets/tests/it/text/step_arrows.rs +++ b/crates/ui-widgets/tests/it/text/step_arrows.rs @@ -17,7 +17,7 @@ const START: f64 = 50.0; const LABEL: &str = "Size"; /// A field with step arrows at `arrows`, `enabled` and `read_only` as given, and the number it reports. -fn field(arrows: StepArrows, enabled: bool, read_only: bool) -> (Fixture, Rc>) { +fn field(arrows: StepArrows, enabled: bool, read_only: bool, direction: Direction) -> (Fixture, Rc>) { let value = Rc::new(Cell::new(START)); let shown = value.clone(); let mut fixture = Fixture::hosted(move |ui| { @@ -35,7 +35,7 @@ fn field(arrows: StepArrows, enabled: bool, read_only: bool) -> (Fixture, Rc