From d9bcc7f542c06bd44821d08216c57fa37edaa3dd Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 13:31:40 +0000 Subject: [PATCH 1/3] look-chrome: a menu end item of a tab strip shows the menu chevron StripEnd::menu's full face ends with DisclosureGlyph::menu_button(), as every button that opens a menu does (WordCraft's Editing item). Trial a_menu_end_item_shows_the_menu_chevron; story tab_strip_ribbon_end_buttons shows framed end items (two outlined, one accent). Co-Authored-By: Claude Opus 5.5 --- crates/ui-widgets/src/tabs/strip/end.rs | 4 +-- crates/ui-widgets/src/tabs/strip/stories.rs | 12 +++++++ crates/ui-widgets/tests/it/tabs.rs | 37 +++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/crates/ui-widgets/src/tabs/strip/end.rs b/crates/ui-widgets/src/tabs/strip/end.rs index 4c21c10af..53c7374c4 100644 --- a/crates/ui-widgets/src/tabs/strip/end.rs +++ b/crates/ui-widgets/src/tabs/strip/end.rs @@ -73,12 +73,12 @@ impl<'a> StripEnd<'a> { self.command_ref().is_none_or(|command| cx.resolve_command(command.clone()).is_none_or(|resolved| resolved.enabled)) } - /// The face with the label beside the icon. + /// The face with the label beside the icon; a menu item's ends with the chevron of a button that opens a menu. fn full_face(&self) -> Button<'a> { let face = Button::new(self.label.clone()).icon(self.icon.clone()).variant(self.variant); match self.command_ref() { Some(command) => face.command(command.clone()).label(self.label.clone()), - None => face, + None => face.trailing_icon(crate::controls::disclosure::DisclosureGlyph::menu_button()), } } diff --git a/crates/ui-widgets/src/tabs/strip/stories.rs b/crates/ui-widgets/src/tabs/strip/stories.rs index 9b0775a36..69bf359d9 100644 --- a/crates/ui-widgets/src/tabs/strip/stories.rs +++ b/crates/ui-widgets/src/tabs/strip/stories.rs @@ -174,6 +174,18 @@ fn tab_strip_ribbon_end_items_narrow(ui: &mut Ui, data: &mut StoryData) -> Story }) } +/// End items as framed buttons: two outlined, the menu one with its chevron, and the last filled with the accent. +#[story(TabStrip<'static, usize>, covers = [], drive = Drive::Never)] +fn tab_strip_ribbon_end_buttons(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let rows = comment_rows(); + let items = [ + StripEnd::command("Comments", IconId::new("list").into(), EditCommands::Paste).variant(craft_theme::Variant::SECONDARY), + StripEnd::menu("Editing", IconId::new("list").into(), &rows).variant(craft_theme::Variant::SECONDARY), + StripEnd::command("Share", IconId::new("link").into(), EditCommands::Copy).variant(craft_theme::Variant::PRIMARY), + ]; + ribbon(ui, data, TabStrip::new("Ribbon").trailing(&items), &PLAIN) +} + /// The contextual tab is listed for the first frames and then dropped by the source: it fades out at its slot. The /// story reads the frame it is in rather than counting its runs, so a measuring run or a second pass of one frame /// lists the same tabs as the frame's other runs. diff --git a/crates/ui-widgets/tests/it/tabs.rs b/crates/ui-widgets/tests/it/tabs.rs index ae52004e8..ef4623d8d 100644 --- a/crates/ui-widgets/tests/it/tabs.rs +++ b/crates/ui-widgets/tests/it/tabs.rs @@ -537,6 +537,43 @@ fn end_items_drop_their_labels_before_a_tab_overflows() { assert!(kept, "a room keeps the contextual tab while a plain tab overflows"); } +/// The width of the one end item, named "Comments", of a ribbon strip in a wide room: a menu item when `menu`, else a +/// command item with the same label and icon. +fn comments_width(menu: bool) -> f32 { + use craft_behavior::IconId; + use craft_ui::contract::Entry; + use craft_ui::runtime::commands::{CommandRef, EditCommands}; + use craft_ui::tabs::StripEnd; + let rows: [Entry; 1] = [Entry::new(EditCommands::Paste.into(), "Show comments")]; + let item = if menu { + StripEnd::menu("Comments", IconId::new("list").into(), &rows) + } else { + StripEnd::command("Comments", IconId::new("list").into(), EditCommands::Copy) + }; + let items = [item]; + let mut frames = Frames::new(); + let mut show = |ui: &mut Ui| { + ui.set_max_width(2000.0); + let keys: Vec = (0..RIBBON.len()).collect(); + let source = keyed(&keys, |key: &usize| *key); + let strip = TabStrip::new("Ribbon").kind(TabKind::Ribbon).shown(1).roles(ribbon_role).trailing(&items); + strip.show_items(ui, &source, &mut |key, _| Tab::new(RIBBON[*key]).role(ribbon_role(key))); + }; + frames.idle(3, &mut show); + let tree = frames.tree(); + let buttons = tree.with_role(Role::BUTTON); + buttons.iter().find(|key| tree.name_of(**key) == Some("Comments")).and_then(|key| tree.bounds_of(*key)).map_or(0.0, |rect| rect.width()) +} + +/// An end item that opens a menu shows the chevron of a menu button after its label, as every button that opens a +/// menu does; an item that runs a command shows none, so the menu item is wider by the chevron. +#[trial] +fn a_menu_end_item_shows_the_menu_chevron() { + let (menu, command) = (comments_width(true), comments_width(false)); + assert!(command > 0.0, "the command item shows"); + assert!(menu > command + 4.0, "the menu item is wider by its chevron: {menu} against {command}"); +} + /// A contextual tab the source drops fades out at its slot: while it fades it has no node, a click on its slot /// selects nothing and the overflow menu does not list it; once the fade ends it is not painted. A frame of two /// passes paints the fade as one does. A contextual tab that comes back is hit from its first frame. From 738d21ba8e8b08d0ed0d6dc10bda9c794c7c68a0 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 13:31:44 +0000 Subject: [PATCH 2/3] look-chrome: rulers paint ticks only over their extent; column lighter than margins TextRuler::paint_ticks drops the tick rule's extra labelled step beyond each end where the ruler is cut to an extent (a page's x range), so no ticks show past the page. TextRuler and VerticalRuler fill the column with surface.sunken and the margins with surface.canvas: the margins were the lighter part (surface.sunken is #fff in ArtCraft light), the reverse of a word processor's ruler. Trials a_ruler_cut_to_an_extent_paints_no_tick_past_it and the_ruler_column_is_lighter_than_its_margins. Co-Authored-By: Claude Opus 5.5 --- crates/pages/src/ui/page_rulers.rs | 5 +- crates/text/src/ui/ruler.rs | 6 ++- crates/text/src/ui/ruler/paint.rs | 10 +++- crates/text/tests/it/ruler.rs | 78 ++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/crates/pages/src/ui/page_rulers.rs b/crates/pages/src/ui/page_rulers.rs index 3f290121c..df43fec94 100644 --- a/crates/pages/src/ui/page_rulers.rs +++ b/crates/pages/src/ui/page_rulers.rs @@ -177,8 +177,9 @@ impl Component for VerticalRuler<'_> { VerticalRulerStyle { metrics: Metrics::new(), focus: cx.focus_look(), - fill: cx.color(colors.surface.chrome), - margin: cx.color(colors.surface.sunken), + // As `TextRuler`'s: the text range is the light well, the margins are shaded as the desk round the page. + fill: cx.color(colors.surface.sunken), + margin: cx.color(colors.surface.canvas), tick: cx.color(colors.text.muted), marker: cx.color(colors.text.normal), label: TextLook::new(TypeRole::Caption, craft_ui::style::Stateful::new(cx.color(colors.text.muted))), diff --git a/crates/text/src/ui/ruler.rs b/crates/text/src/ui/ruler.rs index 55adb5134..69de50e98 100644 --- a/crates/text/src/ui/ruler.rs +++ b/crates/text/src/ui/ruler.rs @@ -491,8 +491,10 @@ impl Component for TextRuler<'_> { TextRulerStyle { metrics: Metrics::new(), focus: cx.focus_look(), - fill: cx.color(colors.surface.chrome), - margin: cx.color(colors.surface.sunken), + // The column is the light well the text goes in; the margins are shaded as the desk round the page, so the + // column reads lighter than the margins in both modes. + fill: cx.color(colors.surface.sunken), + margin: cx.color(colors.surface.canvas), tick: cx.color(colors.text.muted), marker_fill: cx.color(colors.surface.raised), marker_off: cx.color(colors.text.faint), diff --git a/crates/text/src/ui/ruler/paint.rs b/crates/text/src/ui/ruler/paint.rs index c92c78faf..027f820ec 100644 --- a/crates/text/src/ui/ruler/paint.rs +++ b/crates/text/src/ui/ruler/paint.rs @@ -118,7 +118,15 @@ impl TextRuler<'_> { f64::from(g.scale), (f64::from(lo) * per_doc)..=(f64::from(hi) * per_doc), ); - let marks: Vec = ticks.iter().map(|tick| Tick::new(g.x((tick.value / per_doc) as f32) - g.strip.min.x, tick.rank)).collect(); + // The tick rule adds a labelled step beyond each end; a ruler cut to its extent (a page's) shows none past it. + let covered = g.visible().x_range(); + let marks: Vec = ticks + .iter() + .map(|tick| g.x((tick.value / per_doc) as f32)) + .zip(&ticks) + .filter(|(x, _)| covered.contains(*x)) + .map(|(x, tick)| Tick::new(x - g.strip.min.x, tick.rank)) + .collect(); ui.content_painter(cx).ticks(g.strip, TickEdge::Bottom, &marks); let draw = ui.draw(); let color: StyleColor = cx.resolve(&style.label.color); diff --git a/crates/text/tests/it/ruler.rs b/crates/text/tests/it/ruler.rs index 3601a4a6d..05f30abf5 100644 --- a/crates/text/tests/it/ruler.rs +++ b/crates/text/tests/it/ruler.rs @@ -195,6 +195,84 @@ fn ruler_numbers_skip_margins_and_markers_thin_out_mirror_for_rtl_and_keep_clear } } +/// A ruler cut to an extent (a page's x range) paints its ticks over that extent only: the tick rule's labelled step +/// beyond each end stays off the strip, as nothing of the ruler shows past the page. +#[trial] +fn a_ruler_cut_to_an_extent_paints_no_tick_past_it() { + const FROM: f32 = 100.0; + const TO: f32 = 300.0; + let values = Rc::new(RefCell::new(RulerValues::default())); + let strip_at: Rc>> = Rc::new(RefCell::new(None)); + let seen = strip_at.clone(); + let mut fixture = Fixture::new(move |ui| { + let stage = craft_ui::testing::stage(ui); + let (strip, _) = Rulers::strips(ui, stage); + *seen.borrow_mut() = Some(strip); + TextRuler::new("Ruler", Bind::bound(&mut *values.borrow_mut()), 140.0) + .unit(DocUnit::new(UnitKind::Inches, 96.0)) + .origin(strip.min.x + 130.0) + .extent(egui::Rangef::new(strip.min.x + FROM, strip.min.x + TO)) + .scale(1.0) + .show_at(ui, strip); + }); + fixture.settle(); + let shapes = fixture.frame_shapes(); + let strip = strip_at.borrow().expect("the ruler showed"); + let (from, to) = (strip.min.x + FROM - 0.5, strip.min.x + TO + 0.5); + let ticks: Vec = shapes + .iter() + .map(egui::Shape::visual_bounding_rect) + .filter(|rect| rect.is_finite() && rect.width() <= 2.0 && rect.height() > 0.0) + .filter(|rect| rect.min.y >= strip.min.y - 0.5 && rect.max.y <= strip.max.y + 0.5) + .collect(); + assert!(ticks.iter().any(|rect| rect.center().x > from && rect.center().x < to), "the ruler paints ticks over its extent"); + let past: Vec<&egui::Rect> = ticks.iter().filter(|rect| rect.center().x < from || rect.center().x > to).collect(); + assert!(past.is_empty(), "no tick past the extent {from}..{to}: {past:?}"); +} + +/// The ruler's column (the text's width) is lighter than its margins, as a word processor's ruler reads: the column +/// takes the light well colour and the margins the shade of the desk round the page. +#[trial] +fn the_ruler_column_is_lighter_than_its_margins() { + const FROM: f32 = 100.0; + const TO: f32 = 300.0; + const ORIGIN: f32 = 130.0; + const WIDTH: f32 = 140.0; + let values = Rc::new(RefCell::new(RulerValues::default())); + let strip_at: Rc>> = Rc::new(RefCell::new(None)); + let seen = strip_at.clone(); + let mut fixture = Fixture::new(move |ui| { + let stage = craft_ui::testing::stage(ui); + let (strip, _) = Rulers::strips(ui, stage); + *seen.borrow_mut() = Some(strip); + TextRuler::new("Ruler", Bind::bound(&mut *values.borrow_mut()), WIDTH) + .origin(strip.min.x + ORIGIN) + .extent(egui::Rangef::new(strip.min.x + FROM, strip.min.x + TO)) + .scale(1.0) + .show_at(ui, strip); + }); + fixture.settle(); + let shapes = fixture.frame_shapes(); + let strip = strip_at.borrow().expect("the ruler showed"); + // The fill of the filled rect that spans the strip's depth over exactly `from..to` (strip x). + let fill_over = |from: f32, to: f32| { + shapes.iter().find_map(|shape| match shape { + egui::Shape::Rect(r) + if (r.rect.min.x - (strip.min.x + from)).abs() < 0.6 + && (r.rect.max.x - (strip.min.x + to)).abs() < 0.6 + && (r.rect.height() - strip.height()).abs() < 0.6 => + { + Some(r.fill) + } + _ => None, + }) + }; + let luma = |c: egui::Color32| 0.2126 * f32::from(c.r()) + 0.7152 * f32::from(c.g()) + 0.0722 * f32::from(c.b()); + let column = fill_over(ORIGIN, ORIGIN + WIDTH).expect("the column is filled"); + let margins = fill_over(FROM, TO).expect("the ruler's extent is filled with the margin shade"); + assert!(luma(column) > luma(margins), "the column {column:?} is lighter than the margins {margins:?}"); +} + /// Only the primary button starts a stop drag; Escape cancels it; a release well away from the strip clears the stop and /// one near the strip keeps it. #[trial] From 95928362a927009d66541dab4e0eab1dffd2dbf1 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 13:31:44 +0000 Subject: [PATCH 3/3] look-chrome: WordCraft's canvas colour in the ArtCraft app layer surface.canvas #e6e6e6 light, #141414 dark: WordCraft's desk round the pages. Co-Authored-By: Claude Opus 5.5 --- crates/theme/themes/artcraft.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/theme/themes/artcraft.json b/crates/theme/themes/artcraft.json index 4853d1252..9f225d373 100644 --- a/crates/theme/themes/artcraft.json +++ b/crates/theme/themes/artcraft.json @@ -66,6 +66,7 @@ "accent.soft": "#dde3f8", "accent.solid": "#3b5bdb", "accent.text": "#2b47b5", + "surface.canvas": "#e6e6e6", "surface.chrome": "#f0f0f0", "text.on_accent": "#ffffff" }, @@ -73,6 +74,7 @@ "accent.soft": "#2e3a66", "accent.solid": "#7a93f0", "accent.text": "#9cb0f5", + "surface.canvas": "#141414", "surface.chrome": "#1f1f1f", "text.on_accent": "#11162e" }