red-fw-2: framework batch trial fixes (numeric-only targeted Increment/Decrement, stories, ribbon chevrons)

Written by a Codex red fixer; committed by the lead (runs/codex/red-fw-2.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-27 06:17:42 +00:00
1 parent bd264e5b47
commit 98664589dd
16 files changed
+58 -50

No files matched your search

+5 -3
View File
@@ -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() }
})
}
+5 -8
View File
@@ -343,7 +343,7 @@ fn show_row<T: Clone + Eq + Hash + Send + Sync + Debug + 'static>(
let title_line = if icons.untitled { 0.0 } else { launcher_side };
let start = cx.style::<Region>().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<T: Clone + Eq + Hash + Send + Sync + Debug + 'static>(
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::<RibbonWords>();
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())]
+6 -1
View File
@@ -772,12 +772,17 @@ pub(crate) fn paint_face<C: Show>(
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,
@@ -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;
+2 -2
View File
@@ -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.
+1 -1
View File
@@ -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<Numeric>,
/// A plain text value, for a sub-node that has one and no number.
pub(crate) value: Option<String>,
@@ -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<bool>,
@@ -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);
@@ -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() });
}
}
+2
View File
@@ -251,6 +251,7 @@ struct Source {
#[derive(Clone, Default)]
struct Routed {
items: Vec<Item>,
numeric_parts: Vec<PartRef>,
nudge: Option<Nudge>,
/// The chords a recorder stop's presses spell this pass.
chords: Vec<Chord>,
@@ -264,6 +265,7 @@ struct Node {
owner: Id,
part: Option<PartRef>,
focusable: bool,
numeric: bool,
/// The node's expanded state this pass, `None` when it has none.
expanded: Option<bool>,
}
@@ -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<Option<Source>>,
/// Only focusable numeric parts opt into the default move fallback; other parts have their own access actions.
numeric_parts: Vec<PartRef>,
took_arrows: Vec<NavMove>,
nudge: Option<Nudge>,
chords: Vec<Chord>,
@@ -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<Id>, rtl: bool) -> Intents {
Intents {
items,
sources,
numeric_parts: routed.numeric_parts,
took_arrows: Vec::new(),
nudge: routed.nudge,
chords: routed.chords,
+4 -4
View File
@@ -32,14 +32,14 @@ pub(crate) fn register_expanded(ctx: &Context, node: Id, expanded: Option<bool>)
}
/// 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<PartRef>, focusable: bool) {
pub(crate) fn register_node(ctx: &Context, node: Id, owner: Id, part: Option<PartRef>, 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 });
});
}
+5 -2
View File
@@ -864,8 +864,11 @@ fn route_access(ctx: &Context, request: &Action, nodes: &HashMap<u64, Node>, 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),
+1 -1
View File
@@ -152,7 +152,7 @@ pub fn activated_member(ctx: &Context, root: Id) -> Option<Id> {
/// Registers an AccessKit node so a request that targets it reaches `owner`.
pub fn register_node(ctx: &Context, node: Id, owner: Id, part: Option<PartRef>, 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.
+1 -8
View File
@@ -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);
@@ -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(),
@@ -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<Cell<f64>>) {
fn field(arrows: StepArrows, enabled: bool, read_only: bool, direction: Direction) -> (Fixture, Rc<Cell<f64>>) {
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<Cel
Some(out.edit.into())
});
fixture.probe_purity();
fixture.settle();
fixture.direction(direction).settle();
(fixture, value)
}
@@ -57,7 +57,7 @@ fn press_up(fixture: &mut Fixture) {
/// reruns passes inside a frame, which must change nothing.
#[trial]
fn a_held_step_arrow_repeats_and_a_disabled_one_takes_no_press() {
let (mut fixture, value) = field(StepArrows::Leading, true, false);
let (mut fixture, value) = field(StepArrows::Leading, true, false, Direction::Ltr);
press_up(&mut fixture);
assert_eq!(value.get(), START + 1.0, "the press steps once");
@@ -77,7 +77,7 @@ fn a_held_step_arrow_repeats_and_a_disabled_one_takes_no_press() {
assert!(fixture.impure().is_empty(), "a rerun pass changed something: {:?}", fixture.impure());
for (enabled, read_only) in [(false, false), (true, true)] {
let (mut fixture, value) = field(StepArrows::Leading, enabled, read_only);
let (mut fixture, value) = field(StepArrows::Leading, enabled, read_only, Direction::Ltr);
press_up(&mut fixture);
fixture.advance(HoldRepeat::DELAY);
fixture.idle(2);
@@ -90,10 +90,9 @@ fn a_held_step_arrow_repeats_and_a_disabled_one_takes_no_press() {
#[trial]
fn trailing_step_arrows_sit_at_the_end_edge_and_step() {
for direction in [Direction::Ltr, Direction::Rtl] {
let (mut fixture, value) = field(StepArrows::Trailing, true, false);
fixture.direction(direction).settle();
let (mut fixture, value) = field(StepArrows::Trailing, true, false, direction);
let root = fixture.root_id().expect("the field is shown");
let text = fixture.part_rect(root, super::kit::TEXT).expect("the text part");
let text = fixture.ctx().read_response(craft_ui::testing::text::widget_id(root, super::kit::TEXT)).expect("the text part").rect;
let up = fixture.part_rect(root, NumberField::STEP_UP).expect("the up half");
let down = fixture.part_rect(root, NumberField::STEP_DOWN).expect("the down half");
let field = fixture.by_label(LABEL).expect("the field node").rect;