From 59e347fced51414cc447b94e1b8df733e5e35258 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 02:59:19 -0800 Subject: [PATCH 01/11] ui-widgets: the truncation test runs through the number field in the integration binary The unit test module in text/number/rule.rs made craft-design-lint's mapped_crates_have_no_findings fail (test/cfg-test: tests in an egui-linked crate live in the integration binary). The same seven cases now type into a NumberField with truncate_typed and commit_decimals under an English number format and check the committed value. --- crates/ui-widgets/src/text/number/rule.rs | 14 -------------- crates/ui-widgets/tests/it/text/number.rs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/ui-widgets/src/text/number/rule.rs b/crates/ui-widgets/src/text/number/rule.rs index 8dcd9badb9..42141f3af9 100644 --- a/crates/ui-widgets/src/text/number/rule.rs +++ b/crates/ui-widgets/src/text/number/rule.rs @@ -282,17 +282,3 @@ impl Codec for Ruled { Cow::Owned(self.samples(current).max_by_key(|text| text.chars().count()).unwrap_or_default()) } } - -#[cfg(test)] -mod tests { - use super::truncate_to; - - #[test] - fn truncation_cuts_toward_zero_and_keeps_values_at_the_precision() { - for (value, decimals, want) in - [(2.5, 0, 2.0), (-2.5, 0, -2.0), (1.159, 2, 1.15), (1.15, 2, 1.15), (-1.15, 2, -1.15), (0.29, 2, 0.29), (1.2345678919, 9, 1.234567891)] - { - assert_eq!(truncate_to(value, decimals), want, "{value} at {decimals} decimals"); - } - } -} diff --git a/crates/ui-widgets/tests/it/text/number.rs b/crates/ui-widgets/tests/it/text/number.rs index cadff1fc89..d1e5381b48 100644 --- a/crates/ui-widgets/tests/it/text/number.rs +++ b/crates/ui-widgets/tests/it/text/number.rs @@ -210,6 +210,24 @@ fn a_localised_decimal_types_in() { assert_eq!(typed(Some(host), None, "12,5"), Some(12.5)); } +/// A field that truncates typed values cuts them toward zero to its committed decimals, and keeps a value already at +/// that precision. +#[trial] +fn a_truncating_field_cuts_a_typed_value_toward_zero_and_keeps_one_at_the_precision() { + for (text, decimals, want) in [ + ("2.5", 0, 2.0), + ("-2.5", 0, -2.0), + ("1.159", 2, 1.15), + ("1.15", 2, 1.15), + ("-1.15", 2, -1.15), + ("0.29", 2, 0.29), + ("1.2345678919", 9, 1.234567891), + ] { + let committed = typed_with(Some(region_host("en")), text, |field| field.truncate_typed().commit_decimals(decimals)); + assert_eq!(committed, Some(want), "{text} at {decimals} decimals"); + } +} + /// A whole-only field over 1 to 100 under `host`'s locale, with `text` typed over 50 and committed with Tab: the value /// kept and the range alert the commit reported. fn whole_typed(host: Option>, text: &str) -> (Option, Option) { From 8326e69c21cad729b78a271e4366160e44b76081 Mon Sep 17 00:00:00 2001 From: Martin Ball <98639962+benandez@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:15:24 +0000 Subject: [PATCH 02/11] Merge pull request #3218 from mocenigo/page-view-fit-width pages: no horizontal scroll bar while the pages fit the view's width (cherry picked from commit 58acd23cdc96a491d5f735cc0823adb993fba6e9) --- crates/pages/src/ui/view.rs | 4 + crates/pages/tests/it/views.rs | 76 +++++++++++++++++++ crates/ui-canvas/src/canvas/scrollbars/mod.rs | 14 +++- 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/crates/pages/src/ui/view.rs b/crates/pages/src/ui/view.rs index 2e344d73a6..46522ae8e2 100644 --- a/crates/pages/src/ui/view.rs +++ b/crates/pages/src/ui/view.rs @@ -1200,6 +1200,10 @@ fn run_pass( Label::from(words.page_of.fill(&[("page", label.as_str()), ("count", total.as_str())])) }; let bars = if count > 0 { bars.tip(&tip) } else { bars }; + // Pages that fit the view's width can't scroll sideways, so there is no horizontal bar. The layout drawn + // decides, as the bars measure it. + let (x_lo, x_hi) = offset_range(drawn.doc.x0, drawn.doc.x1, vw); + let bars = if x_lo >= x_hi { bars.vertical_only() } else { bars }; // Full screen's edge-to-edge view (`PageView::fill_screen`) has no scroll bars: nothing is drawn and nothing takes a press // along the window's edges. let bar_moved = if build.fill_screen { diff --git a/crates/pages/tests/it/views.rs b/crates/pages/tests/it/views.rs index e4e60c79ac..f0ec0c2e8e 100644 --- a/crates/pages/tests/it/views.rs +++ b/crates/pages/tests/it/views.rs @@ -107,6 +107,82 @@ impl PageSource for SmallPages { } } +/// Whether the view shows a horizontal scroll bar at `zoom` in a window 900 wide. +fn has_horizontal_bar(zoom: f64) -> bool { + let (fixture, _, _) = layout_rig( + 3, + state_with(|s| { + s.fit = Fit::None; + s.zoom = zoom; + }), + ); + horizontal_bar(&fixture).is_some() +} + +#[trial] +fn the_horizontal_bar_shows_only_when_the_pages_are_wider_than_the_view() { + assert!(!has_horizontal_bar(0.5), "pages that fit the width need no horizontal bar"); + assert!(has_horizontal_bar(3.0), "pages wider than the view scroll sideways"); +} + +/// The horizontal scroll bar the fixture shows, if any. +fn horizontal_bar(fixture: &Fixture) -> Option { + fixture.by_role(Role::SCROLL_BAR).iter().map(|bar| bar.rect).find(|rect| rect.width() > rect.height()) +} + +#[trial] +fn a_horizontal_thumb_held_while_the_pages_come_to_fit_keeps_its_bar_until_the_release() { + let (mut fixture, state, _) = layout_rig( + 3, + state_with(|s| { + s.fit = Fit::None; + s.zoom = 3.0; + }), + ); + let bar = horizontal_bar(&fixture).expect("pages wider than the view have a horizontal bar"); + // The view starts at the left edge, so the thumb is at the start of the track. + let from = pos2(bar.left() + 4.0, bar.center().y); + fixture.drag_hold_at(from, vec2(20.0, 0.0)); + state.borrow_mut().zoom = 0.5; + fixture.idle(3); + assert!(horizontal_bar(&fixture).is_some(), "the held thumb keeps its bar, so its release reaches it"); + fixture.release_at(from + vec2(20.0, 0.0)).idle(2); + assert!(horizontal_bar(&fixture).is_none(), "after the release, pages that fit have no horizontal bar"); +} + +#[trial] +fn a_horizontal_thumb_released_while_the_bars_are_not_shown_leaves_no_bar_behind() { + let state = Rc::new(RefCell::new(state_with(|s| { + s.fit = Fit::None; + s.zoom = 3.0; + }))); + let full_screen = Rc::new(Cell::new(false)); + let (kept, edge_to_edge) = (Rc::clone(&state), Rc::clone(&full_screen)); + let pages = DemoPages::new(3); + let mut fixture = Fixture::new(move |ui| { + let mut now = kept.borrow().clone(); + PageView::new("Pages", &pages, &mut now, PAPER).options(LayoutOptions::ACROBAT).fill_screen(edge_to_edge.get()).show(ui, |_, _| ()); + *kept.borrow_mut() = now; + }); + fixture.room(vec2(900.0, 600.0)); + fixture.settle(); + let bar = horizontal_bar(&fixture).expect("pages wider than the view have a horizontal bar"); + let from = pos2(bar.left() + 4.0, bar.center().y); + fixture.drag_hold_at(from, vec2(20.0, 0.0)); + // Full screen mid-drag: the bars go, and the release can't reach them. + full_screen.set(true); + fixture.idle(2); + fixture.release_at(from + vec2(20.0, 0.0)).idle(2); + full_screen.set(false); + { + let mut state = state.borrow_mut(); + state.fit = Fit::None; + state.zoom = 0.5; + } + fixture.idle(3); + assert!(horizontal_bar(&fixture).is_none(), "a press that ended unseen leaves no horizontal bar over pages that fit"); +} + #[trial] fn go_to_a_narrow_page_brings_it_back_into_horizontal_view() { let Rig { mut fixture, state, out, .. } = rig_over( diff --git a/crates/ui-canvas/src/canvas/scrollbars/mod.rs b/crates/ui-canvas/src/canvas/scrollbars/mod.rs index f0d190d33b..f4e30e5e3f 100644 --- a/crates/ui-canvas/src/canvas/scrollbars/mod.rs +++ b/crates/ui-canvas/src/canvas/scrollbars/mod.rs @@ -477,7 +477,9 @@ impl<'a> CanvasScrollbars<'a> { } fn bars(&self, view: &CanvasView, rect: Rect, style: &ScrollbarsStyle, held: Option<&HeldThumb>) -> Bars { - Bars::of(view, self.document, self.overscroll, !self.vertical_only, rect, style, held) + // A horizontal thumb held keeps its bar until the press ends, so its release closes the drag. + let horizontal = !self.vertical_only || held.is_some_and(|held| held.on(Axis::X)); + Bars::of(view, self.document, self.overscroll, horizontal, rect, style, held) } } @@ -547,6 +549,16 @@ impl Component for CanvasScrollbars<'_> { } let Some(view) = cx.value().copied() else { return }; let mut held = cx.press_slot::().clone(); + // A press that ended while the bars weren't shown (a full-screen view drops them) never reached them: its thumb + // is idle again, and the extent kept for it is stale. + let stale = held.as_ref().is_some_and(|held| { + let thumb = thumb_of(if held.horizontal { HORIZONTAL } else { VERTICAL }); + matches!(cx.part(thumb).press.phase, PressPhase::Idle | PressPhase::Hover) + }); + if stale { + *cx.press_slot::() = None; + held = None; + } let bars = self.bars(&view, cx.rect, cx.style, held.as_ref()); let mut ended = false; let rtl = cx.flow.is_rtl(); From 3837e0b64dac9f536e0dac6c168e3341e624af7f Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 12:35:16 +0100 Subject: [PATCH 03/11] pages: paint the anchored zoom immediately and support floating scrollbars --- crates/pages/src/ui/view.rs | 54 +++++++++++++++---- crates/pages/tests/it/views.rs | 48 +++++++++++++++++ crates/ui-canvas/src/canvas/scrollbars/mod.rs | 13 +++-- 3 files changed, 100 insertions(+), 15 deletions(-) diff --git a/crates/pages/src/ui/view.rs b/crates/pages/src/ui/view.rs index 46522ae8e2..907046fc58 100644 --- a/crates/pages/src/ui/view.rs +++ b/crates/pages/src/ui/view.rs @@ -478,6 +478,7 @@ pub struct PageView<'a> { reach: f32, go_to_place: GoToPlace, fill_screen: bool, + floating_scrollbars: bool, } /// How far from the view, in view heights above and below it (and one view width either side), the page view keeps a @@ -508,6 +509,7 @@ impl<'a> PageView<'a> { reach: PICTURE_REACH, go_to_place: GoToPlace::AfterRowAbove, fill_screen: false, + floating_scrollbars: false, } } @@ -528,6 +530,13 @@ impl<'a> PageView<'a> { self } + /// Use the theme's floating scroll indicators over the page edges. + #[must_use] + pub fn floating_scrollbars(mut self) -> Self { + self.floating_scrollbars = true; + self + } + /// The colour round the pages: the theme's by default; production's full screen view is black. #[must_use] pub fn pasteboard(mut self, colour: PasteboardColor) -> Self { @@ -696,6 +705,7 @@ impl<'a> PageView<'a> { reach, go_to_place, fill_screen, + floating_scrollbars, } = self; let mut spacing = PageMetrics::new().show_at(ui, Rect::from_min_size(rect.min, Vec2::ZERO)).spacing; // Filling the screen, the pages keep no margin above or below and no gutter beside them, and draw no border. @@ -752,8 +762,20 @@ impl<'a> PageView<'a> { let mut held = Held::new(Bind::bound(state)); let mut seen: Option = None; let mut canvas_body = |ui: &mut Ui, cx: &mut BodyCx<'_>| { - let inputs = - Inputs { source, describer, build: &build, rect, given, paper, navigation, border, keep, reach, strips: strips_clip.map(|_| full) }; + let inputs = Inputs { + source, + describer, + build: &build, + rect, + given, + paper, + navigation, + border, + keep, + reach, + floating_scrollbars, + strips: strips_clip.map(|_| full), + }; let (mut next, pending) = run_pass(ui, cx, &mut held, &inputs, |ui, page| before(ui, page, session))?; let pass = tool_pass(&cx.env); if let Some(clip) = strips_clip { @@ -817,6 +839,7 @@ struct Inputs<'a> { keep: &'a [usize], /// `PageView::picture_reach`. reach: f32, + floating_scrollbars: bool, /// With `PageView::rulers`, the view's whole rect, strips included; the canvas shows inside the strips. strips: Option, } @@ -986,7 +1009,7 @@ fn run_pass( inputs: &Inputs<'_>, mut before: impl FnMut(&mut Ui, &PageBody<'_>) -> Option, ) -> Option<(Seen, Pending)> { - let Inputs { source, describer, build, rect, given, paper, navigation, border, keep, reach, strips: _ } = *inputs; + let Inputs { source, describer, build, rect, given, paper, navigation, border, keep, reach, floating_scrollbars, strips: _ } = *inputs; let mut state = held.read(cx)?; let started = state.clone(); state.normalise(); @@ -1004,8 +1027,9 @@ fn run_pass( // A display, continuous, cover, fit or rotation other than the layout placed last keeps the current page in // view. Writing a field to the value it has changes nothing, and the first pass has no layout to differ from. let previous = mem.layout.take(); - if state.go_to.is_none() && previous.as_ref().is_some_and(|(key, _)| key.display_differs(&state)) { - state.go_to = Some(GoTo::Top { page: state.current, fraction: 0.0 }); + let reposition = state.go_to.is_none() && previous.as_ref().is_some_and(|(key, _)| key.display_differs(&state)); + if reposition { + state.go_to(state.current); } // The layout the canvas was given its view for: what this pass draws, whatever the pass makes of the state. let drawn = build.of(&state); @@ -1028,6 +1052,11 @@ fn run_pass( state.offset = offset; } } + // Switching fit or display also places the current page at the top. Use that same + // destination for this paint, before the normal go-to processing commits it. + if reposition && let Some(top) = state.go_to { + state.offset = go_to_offset(top, &geo, state.continuous, state.offset, (vw, vh), &build.spacing, build.go_to_place); + } state.zoom = geo.scale / SCREEN_POINTS_PER_POINT; // The canvas folded the wheel, a pinch and the view commands into the view it settled on: a different zoom is the @@ -1066,13 +1095,15 @@ fn run_pass( } } let mut scrolled = wheel.is_some_and(|wheel| !zooming && wheel.scroll != Vec2::ZERO); - // A zoom that does not ease draws the layout it made in its own pass, through the view of the anchored offset: the - // pages reflow and the point under the pointer stays in the pass the zoom happens, and the next pass, given that - // view, moves nothing. (Drawing the layout the pass started with, scaled, put the reflow and the spacing that does - // not scale one pass late.) An ease draws the layout it started from, scaled, until it lands. - let (drawn, drawn_frame, mut shown) = if zooming && !space.easing() { + // Wheel zooms and external scale changes both compute an anchored offset above. Paint + // through it immediately so the new page size and its placement change in the same frame. + // An animated canvas keeps drawing its easing view until it lands. + let anchored = state.offset != started.offset; + let (drawn, drawn_frame, mut shown) = if (zooming || anchored) && !space.easing() { let frame = Frame::of(&geo); - let mut view = frame.view(rect, state.offset, geo.scale / SCREEN_POINTS_PER_POINT); + let (xs, ys) = (offset_range(geo.doc.x0, geo.doc.x1, vw), geo.y_range(vh)); + let offset = (want.0.clamp(xs.0, xs.1), want.1.clamp(ys.0, ys.1)); + let mut view = frame.view(rect, offset, geo.scale / SCREEN_POINTS_PER_POINT); // As the canvas places a given view: in its own rect (inside the rulers), about the same centre. view.rect = target.rect; let view = if shown == target { view } else { pixel_aligned(view, ui.ctx().pixels_per_point()) }; @@ -1200,6 +1231,7 @@ fn run_pass( Label::from(words.page_of.fill(&[("page", label.as_str()), ("count", total.as_str())])) }; let bars = if count > 0 { bars.tip(&tip) } else { bars }; + let bars = if floating_scrollbars { bars.floating() } else { bars }; // Pages that fit the view's width can't scroll sideways, so there is no horizontal bar. The layout drawn // decides, as the bars measure it. let (x_lo, x_hi) = offset_range(drawn.doc.x0, drawn.doc.x1, vw); diff --git a/crates/pages/tests/it/views.rs b/crates/pages/tests/it/views.rs index f0ec0c2e8e..d725ac1d51 100644 --- a/crates/pages/tests/it/views.rs +++ b/crates/pages/tests/it/views.rs @@ -125,6 +125,31 @@ fn the_horizontal_bar_shows_only_when_the_pages_are_wider_than_the_view() { assert!(has_horizontal_bar(3.0), "pages wider than the view scroll sideways"); } +#[trial] +fn floating_page_scrollbars_use_narrower_tracks_and_keep_the_same_page_layout() { + let measure = |floating: bool| { + let pages = DemoPages::new(4); + let mut state = state_with(|s| { + s.fit = Fit::None; + s.zoom = 2.0; + }); + let page = Rc::new(RefCell::new(egui::Rect::NOTHING)); + let drawn = Rc::clone(&page); + let mut fixture = Fixture::new(move |ui| { + let view = PageView::new("Pages", &pages, &mut state, PAPER); + let shown = if floating { view.floating_scrollbars() } else { view }.show(ui, |_, _| {}); + *drawn.borrow_mut() = shown.pages[0].rect; + }); + fixture.room(vec2(900.0, 600.0)).idle(3); + let bar = horizontal_bar(&fixture).expect("wide pages scroll sideways"); + (bar.height(), *page.borrow()) + }; + let (floating, float_page) = measure(true); + let (docked, dock_page) = measure(false); + assert!(floating < docked); + assert_eq!(float_page, dock_page); +} + /// The horizontal scroll bar the fixture shows, if any. fn horizontal_bar(fixture: &Fixture) -> Option { fixture.by_role(Role::SCROLL_BAR).iter().map(|bar| bar.rect).find(|rect| rect.width() > rect.height()) @@ -489,6 +514,29 @@ fn assert_centre_kept(out: &Out, before: (usize, kurbo::Point), what: &str) { ); } +/// A zoom entered in a toolbar draws the page in its final position immediately. A pass at +/// the new scale with the old offset makes the page jump sideways and vertically on the next frame. +#[trial] +fn a_written_zoom_draws_the_anchored_page_on_its_first_frame() { + let mut view = rig( + 5, + state_with(|s| { + s.fit = Fit::None; + s.zoom = 1.0; + }), + ); + for (fit, zoom) in [(Fit::None, 2.0), (Fit::None, 1.0), (Fit::Width, 1.0), (Fit::None, 2.0)] { + view.state.borrow_mut().fit = fit; + view.state.borrow_mut().zoom = zoom; + view.fixture.idle(1); + let first = view.out.borrow().pages[0].rect; + view.fixture.idle(2); + let settled = view.out.borrow().pages[0].rect; + assert!((first.min - settled.min).length() < 1.0, "at {zoom}: first {first:?}, settled {settled:?}"); + assert!((first.size() - settled.size()).length() < 1.0); + } +} + /// A written zoom keeps the point at the centre; a new room (a panel opened beside the view) refits and keeps the /// current page's top where it was, as production did. #[trial] diff --git a/crates/ui-canvas/src/canvas/scrollbars/mod.rs b/crates/ui-canvas/src/canvas/scrollbars/mod.rs index f4e30e5e3f..1b2ea363e9 100644 --- a/crates/ui-canvas/src/canvas/scrollbars/mod.rs +++ b/crates/ui-canvas/src/canvas/scrollbars/mod.rs @@ -1,6 +1,6 @@ //! `CanvasScrollbars`: the scroll bars of a canvas (20.6): a horizontal bar along the bottom of the view and a vertical -//! one along the right, always shown, in the docked look (`ScrollBarKind::Docked`): the thumb has the track's whole -//! thickness at rest and under the pointer. Document chrome uses inset thumbs, step buttons and a corner. +//! one along the right. Docked bars have full-width thumbs at rest. Floating bars use the theme's narrower resting +//! indicators. Document chrome uses inset thumbs, step buttons and a corner. //! The thumb is the visible fraction of //! the scrollable extent (the document, plus wherever the view has been scrolled past it); drag it to scroll, or press //! the track to page by one screenful. With overscroll on, the extent also takes in the pasteboard around the document, @@ -402,6 +402,10 @@ pub struct CanvasScrollbars<'a> { /// horizontal bar or corner is shown. #[prop(flag)] vertical_only: bool, + /// Use floating indicators with a narrow thumb at rest. Document chrome takes precedence. + #[prop(flag)] + #[style_key] + floating: bool, /// Wider bars with inset thumbs, step arrows and a corner for a document window. #[prop(flag)] #[style_key] @@ -424,6 +428,7 @@ impl<'a> CanvasScrollbars<'a> { overscroll: false, vertical_only: false, document_chrome: false, + floating: false, tip: None, held: None, } @@ -490,8 +495,8 @@ impl Component for CanvasScrollbars<'_> { type Output = CanvasScrollbarsOutput; fn style(cx: &StyleCx<'_>, key: CanvasScrollbarsStyleKey) -> ScrollbarsStyle { - let mut look = cx.scroll_bar_of(ScrollBarKind::Docked); - look.thickness = cx.tokens.size.icon.md; + let kind = if key.floating && !key.document_chrome { ScrollBarKind::Floating } else { ScrollBarKind::Docked }; + let mut look = cx.scroll_bar_of(kind); let margin = if key.document_chrome { 0.0 } else { cx.tokens.space.gap.tight }; let document = key.document_chrome.then(|| { let color = &cx.tokens.color; From 6afe03f5b6de3c288ddcd3dbf0bb0320a2b20ca8 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 12:41:37 +0100 Subject: [PATCH 04/11] pages: retain docked scrollbar sizing and exercise both floating thumbs --- crates/pages/tests/it/views.rs | 30 +++++++++++++++---- crates/ui-canvas/src/canvas/scrollbars/mod.rs | 3 ++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/crates/pages/tests/it/views.rs b/crates/pages/tests/it/views.rs index d725ac1d51..f039e4cdb5 100644 --- a/crates/pages/tests/it/views.rs +++ b/crates/pages/tests/it/views.rs @@ -141,12 +141,32 @@ fn floating_page_scrollbars_use_narrower_tracks_and_keep_the_same_page_layout() *drawn.borrow_mut() = shown.pages[0].rect; }); fixture.room(vec2(900.0, 600.0)).idle(3); - let bar = horizontal_bar(&fixture).expect("wide pages scroll sideways"); - (bar.height(), *page.borrow()) + let horizontal = horizontal_bar(&fixture).expect("wide pages scroll sideways"); + let vertical = fixture + .by_role(Role::SCROLL_BAR) + .into_iter() + .map(|node| node.rect) + .find(|rect| rect.height() > rect.width()) + .expect("long documents scroll vertically"); + let initial = *page.borrow(); + if floating { + // Hover the thumb at the start of each track, then drag from inside its hover area. + for (grab, delta) in [ + (pos2(horizontal.left() + 4.0, horizontal.center().y), vec2(35.0, 0.0)), + (pos2(vertical.center().x, vertical.top() + 4.0), vec2(0.0, 35.0)), + ] { + fixture.frame(vec![craft_ui::testing::pointer::moved(grab)]); + let before = page.borrow().min; + fixture.drag_hold_at(grab, delta).release_at(grab + delta).idle(2); + let moved = before - page.borrow().min; + assert!(moved.dot(delta) > 1.0, "the thumb drag must scroll its own axis: {delta:?} -> {moved:?}"); + } + } + (horizontal.height(), vertical.width(), initial) }; - let (floating, float_page) = measure(true); - let (docked, dock_page) = measure(false); - assert!(floating < docked); + let (float_h, float_v, float_page) = measure(true); + let (dock_h, dock_v, dock_page) = measure(false); + assert!(float_h < dock_h && float_v < dock_v); assert_eq!(float_page, dock_page); } diff --git a/crates/ui-canvas/src/canvas/scrollbars/mod.rs b/crates/ui-canvas/src/canvas/scrollbars/mod.rs index 1b2ea363e9..61a6127d3f 100644 --- a/crates/ui-canvas/src/canvas/scrollbars/mod.rs +++ b/crates/ui-canvas/src/canvas/scrollbars/mod.rs @@ -497,6 +497,9 @@ impl Component for CanvasScrollbars<'_> { fn style(cx: &StyleCx<'_>, key: CanvasScrollbarsStyleKey) -> ScrollbarsStyle { let kind = if key.floating && !key.document_chrome { ScrollBarKind::Floating } else { ScrollBarKind::Docked }; let mut look = cx.scroll_bar_of(kind); + if kind == ScrollBarKind::Docked { + look.thickness = cx.tokens.size.icon.md; + } let margin = if key.document_chrome { 0.0 } else { cx.tokens.space.gap.tight }; let document = key.document_chrome.then(|| { let color = &cx.tokens.color; From 3093928272fa09b6034d7b0118871aa096d0874b Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 13:30:23 +0100 Subject: [PATCH 05/11] ui: inset titled dock headers and allow text tabs to match menu labels --- crates/ui-panels/src/docking/group.rs | 11 ++++++++++- crates/ui-panels/tests/it/dock_group.rs | 7 ++++++- crates/ui-widgets/src/tabs/tab.rs | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 60581b8e3f..98eeff34db 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -349,7 +349,6 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> { wheel_selects_tabs: bool, /// The header shows the shown panel's title (with its count) and a close button in place of the tab strip, as a /// single titled panel does: the panels are shown from a rail, not by tabs. - #[prop(flag)] titled: bool, /// The dock whose drop registry the group's spots go to. #[prop] @@ -414,6 +413,16 @@ impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup< .label(title) } + /// Shows the active panel title with the standard panel inset, aligned with the body beneath it. + #[must_use] + pub fn titled(mut self) -> Self { + self.titled = true; + if let Some(header) = self.props.header.as_mut() { + header.inset = crate::contract::Pad::Regular; + } + self + } + /// The shown panel's footer: the closure fills a footer bar pinned under the body, across the group, that stays in /// view while the body scrolls. A minimized group shows none. #[must_use] diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs index 5533928f06..e4840d2b66 100644 --- a/crates/ui-panels/tests/it/dock_group.rs +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -85,7 +85,12 @@ fn a_titled_group_shows_the_panel_title_and_a_close_button_instead_of_tabs() { } }); fixture.settle(); - assert!(fixture.by_label("Accessibility Checker").is_some(), "the title shows whole"); + let title = fixture + .by_role(craft_ui::contract::Role::LABEL) + .into_iter() + .find(|node| fixture.tree().name_of(node.node) == Some("Accessibility Checker")) + .expect("the title shows whole"); + assert!(title.rect.left() > 10.0, "the title clears the panel edge"); assert!(fixture.by_label("Pages").is_none(), "no tab for the other panel"); let Some(close) = fixture.by_label("Close Accessibility Checker") else { panic!("a close button shows") }; fixture.click(&close).settle(); diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 6bae784b42..38fa3ffd90 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -175,6 +175,10 @@ pub struct Tab<'a> { #[style_key] #[prop] role: TabRole, + /// The text-tab label role when the strip shares a row with another control, such as a menu bar. + #[style_key] + #[prop] + text_role: Option, /// Large Tabs: the strip's taller form with the body type. #[style_key] #[prop(flag)] @@ -214,6 +218,7 @@ impl<'a> Tab<'a> { common: Common::new(), kind: TabKind::Document, role: TabRole::default(), + text_role: None, large: false, detail: None, icon: None, @@ -342,7 +347,9 @@ impl Component for Tab<'_> { // A ribbon tab measures at the shown tab's semibold type, so showing a tab does not move its neighbours. let role = if ribbon { TypeRole::BodyStrong - } else if text_only || key.large { + } else if text_only { + key.text_role.unwrap_or(TypeRole::Body) + } else if key.large { TypeRole::Body } else { TypeRole::Label From d4a504b054e565fc3e87e3b7c6fae34458c32806 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 13:36:54 +0100 Subject: [PATCH 06/11] pdf: bound pattern shadings to the rendered cell --- crates/pdf/tests/upstream_raster.rs | 31 +++++++++++++++++++++++++++ vendor/hayro-interpret/src/pattern.rs | 8 +++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/crates/pdf/tests/upstream_raster.rs b/crates/pdf/tests/upstream_raster.rs index 3adae408c5..7f05c247a0 100644 --- a/crates/pdf/tests/upstream_raster.rs +++ b/crates/pdf/tests/upstream_raster.rs @@ -19,6 +19,37 @@ fn render(bytes: &[u8]) -> Pixels { Pixels { width: raster.width, height: raster.height, rgba: raster.bytes().to_vec() } } +/// An axial shading fills a pattern cell even when the page is rendered smaller than the cell +/// or the caller requests just a tile. The upper and lower corners show opposite gradient ends. +#[cfg_attr(not(target_arch = "wasm32"), test)] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +fn shading_covers_pattern_cell_at_each_viewport_scale() { + let content = "/Pattern cs /P scn 5 6 150 108 re f"; + let bytes = format!( + "%PDF-1.7\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n\ + 2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj\n\ + 3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 160 120] /Contents 4 0 R /Resources << /Pattern << /P 5 0 R >> >> >> endobj\n\ + 4 0 obj << /Length {} >> stream\n{content}\nendstream endobj\n\ + 5 0 obj << /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 1 /BBox [0 0 200 144] /XStep 200 /YStep 144\n\ + /Matrix [.75 0 0 -.75 5 114] /Resources << /Shading << /S << /ShadingType 2 /ColorSpace /DeviceRGB /Coords [0 0 0 144]\n\ + /Function << /FunctionType 2 /Domain [0 1] /C0 [1 0 0] /C1 [0 0 1] /N 1 >> /Extend [true true] >> >> >> /Length 5 >>\n\ + stream\n/S sh\nendstream endobj\ntrailer << /Root 1 0 R >>\n%%EOF", + content.len() + ); + let pdf = open_slice(bytes.as_bytes(), None).unwrap(); + for (scale, size, offset) in [(0.5, [80, 60], [0.0, 0.0]), (1.5, [180, 150], [30.0, 15.0])] { + let opts = Options { scale: [scale; 2], size: Some(size), offset, background: [255; 4], ..Default::default() }; + let image = raster::render(&pdf.pages()[0], &RenderCache::new(), &Default::default(), &opts).unwrap(); + for x in [size[0] / 10, size[0] * 9 / 10] { + for (y, upper) in [(size[1] / 10, true), (size[1] * 9 / 10, false)] { + let i = ((y * image.width + x) * 4) as usize; + let rgb = &image.bytes()[i..i + 3]; + assert!(rgb[1] < 8 && if upper { rgb[0] > rgb[2] } else { rgb[2] > rgb[0] }, "{scale} ({x}, {y}): {rgb:?}"); + } + } + } +} + // These frozen RGB8 values were computed outside the renderer in f64 from the // CIE Lab inverse, the full XYZ adaptation matrix B^-1 diag(B*D65 / B*white) B, // and the standard sRGB matrix/transfer function. No production helper is used. diff --git a/vendor/hayro-interpret/src/pattern.rs b/vendor/hayro-interpret/src/pattern.rs index bc3b99c943..c9c0b11a72 100644 --- a/vendor/hayro-interpret/src/pattern.rs +++ b/vendor/hayro-interpret/src/pattern.rs @@ -164,7 +164,6 @@ pub struct TilingPattern<'a> { cache_key: u128, /// PdfCraft patch (78): see [`Self::instance`]. instance: u64, - ctx_bbox: Rect, /// The bbox of the tiling pattern. pub bbox: Rect, /// The step in the x direction. @@ -238,7 +237,6 @@ impl<'a> TilingPattern<'a> { .unwrap_or_default(); let state = ctx.get().clone(); - let ctx_bbox = ctx.bbox(); let fill_cs = state .graphics_state @@ -270,7 +268,6 @@ impl<'a> TilingPattern<'a> { x_step, y_step, matrix, - ctx_bbox, is_color, stream, stroke_paint, @@ -301,8 +298,9 @@ impl<'a> TilingPattern<'a> { let mut context = Context::new_with( state.ctm, - // TODO: bbox? - (initial_transform * self.ctx_bbox.to_path(0.1)).bounding_box(), + // Shadings cover the cell's device bounds. The caller may be a differently + // scaled page, or a page tile with a different origin. + initial_transform.transform_rect_bbox(self.bbox), &self.cache, self.xref, self.settings.clone(), From 29c6a28d668c8edb23e63f92b46984da8c8bb0b8 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 13:55:52 +0100 Subject: [PATCH 07/11] rails: preserve the Edit toolbar button's activation in the rail output --- crates/ui-panels/src/rails/tool.rs | 8 +++++++- crates/ui-panels/src/rails/tool/trials.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/ui-panels/src/rails/tool.rs b/crates/ui-panels/src/rails/tool.rs index 7a80165ae6..73c95a1aa3 100644 --- a/crates/ui-panels/src/rails/tool.rs +++ b/crates/ui-panels/src/rails/tool.rs @@ -85,6 +85,7 @@ enum RailEvent { DoubleClicked(T), Flyout(SlotId), Dropped(ToolDropped), + EditToolbar(Response), } type FooterFn<'a> = Box; @@ -293,6 +294,9 @@ fn grid(props: &mut GridProps<'_, T>, ui: &mut let icon = props.edit_icon.clone().unwrap_or_else(|| IconId::new("more")); let more = IconButton::new(icon).id_salt("edit-toolbar").label(label).show(ui); edit_toolbar = Some(more.response.id); + if crate::contract::clicked(&more.response) { + sent.send(RailEvent::EditToolbar(more.response)); + } } } } @@ -332,18 +336,20 @@ impl<'a, T: Value + MemoProps + PlainData + 'static> ToolRail<'a, T> { let (mut events, mut edit_toolbar) = (Vec::new(), None); let shown = self.show(ui, |ui, _| edit_toolbar = draw.run(ui, &mut events)); let (mut select, mut double_clicked, mut flyout, mut dropped) = (None, None, None, None); + let mut edit_activation = None; for event in events { match event { RailEvent::Select(tool) => select = Some(tool), RailEvent::DoubleClicked(tool) => double_clicked = Some(tool), RailEvent::Flyout(slot) => flyout = Some(slot), RailEvent::Dropped(drop) => dropped = Some(drop), + RailEvent::EditToolbar(response) => edit_activation = Some(response), } } ToolRailOutput { select, double_clicked, - edit_toolbar: edit_toolbar.and_then(|id| ui.ctx().read_response(id)), + edit_toolbar: edit_activation.or_else(|| edit_toolbar.and_then(|id| ui.ctx().read_response(id))), flyout, dropped, last_used: last, diff --git a/crates/ui-panels/src/rails/tool/trials.rs b/crates/ui-panels/src/rails/tool/trials.rs index 4c0d564c35..951fab6cae 100644 --- a/crates/ui-panels/src/rails/tool/trials.rs +++ b/crates/ui-panels/src/rails/tool/trials.rs @@ -215,6 +215,7 @@ struct Seen { footer_runs: usize, selected: Vec, edit_toolbar: Option, + edit_clicks: usize, } /// A rail with the Edit Toolbar button, a footer and a tool held in `Seen::current`. @@ -231,12 +232,21 @@ fn memo_rail() -> (Fixture, Rc>) { }); let mut seen = shared.borrow_mut(); seen.selected.extend(out.select); + seen.edit_clicks += usize::from(out.edit_toolbar.as_ref().is_some_and(crate::contract::clicked)); seen.edit_toolbar = out.edit_toolbar.map(|response| response.rect); }); fixture.room(Vec2::new(200.0, 600.0)).settle(); (fixture, seen) } +#[trial] +fn the_rail_reports_an_edit_button_activation_once() { + let (mut fixture, seen) = memo_rail(); + let button = fixture.by_label("Edit Toolbar").expect("the edit button is present"); + fixture.access(crate::testing::focus::AccessActionKind::Click, &button).settle(); + assert_eq!(seen.borrow().edit_clicks, 1); +} + /// How the slot grid took part in the last frame: (ran, replayed). fn grid_runs(fixture: &Fixture) -> (usize, usize) { let runs = last_frame_memo_runs(fixture.ctx()); From ddb7340bacbf4c548afc774f6f8cdbab7ab1fe67 Mon Sep 17 00:00:00 2001 From: Ap3pp3rs94 Date: Mon, 30 Nov 2026 06:57:16 -0600 Subject: [PATCH 08/11] fix(pptx): preserve font subset preference (#3410) --- crates/pptx/src/lib.rs | 3 +++ crates/pptx/src/read.rs | 1 + crates/pptx/src/write.rs | 6 +++++- crates/pptx/tests/it/write.rs | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/pptx/src/lib.rs b/crates/pptx/src/lib.rs index d206caaa94..5f868eadde 100644 --- a/crates/pptx/src/lib.rs +++ b/crates/pptx/src/lib.rs @@ -1083,6 +1083,8 @@ pub struct Presentation { pub next_id: u32, /// Embedded fonts. The face bytes live in [`Self::media`]. pub embedded_fonts: Vec, + /// Whether the next save should keep only the characters used by embedded fonts. + pub save_subset_fonts: bool, /// Table styles defined in the file (`ppt/tableStyles.xml`). #[serde(skip_serializing_if = "Vec::is_empty")] pub table_styles: Vec, @@ -1131,6 +1133,7 @@ impl Default for Presentation { first_slide_number: 1, next_id: 0, embedded_fonts: vec![], + save_subset_fonts: false, table_styles: vec![], tags: vec![], kept_parts: vec![], diff --git a/crates/pptx/src/read.rs b/crates/pptx/src/read.rs index 588ba1357b..b3fd815c06 100644 --- a/crates/pptx/src/read.rs +++ b/crates/pptx/src/read.rs @@ -575,6 +575,7 @@ fn read_presentation_settings(imp: &mut Imp, p: &mut Presentation, pres_part: &P p.notes_size = Size::new(sane_len(w, 540.0), sane_len(h, 720.0)); } p.first_slide_number = pres_el.attr_local("firstSlideNum").and_then(value::to_u32_lossy).unwrap_or(1).min(9999); + p.save_subset_fonts = pres_el.attr_local("saveSubsetFonts").and_then(value::to_bool).unwrap_or(false); if let Some(dts) = pres_el.child(Local("defaultTextStyle")) { p.default_text_style = dml::list_style(&mut Src(imp, pres_part), dts); } diff --git a/crates/pptx/src/write.rs b/crates/pptx/src/write.rs index 30c0b83df2..2b0d8825d3 100644 --- a/crates/pptx/src/write.rs +++ b/crates/pptx/src/write.rs @@ -1153,7 +1153,11 @@ fn presentation_xml(x: &mut Exp, o: &mut Out, masters: &[(u64, String)], notes: let p = x.p; let mut w = Writer::document(); let first = (p.first_slide_number != 1).then_some(p.first_slide_number.min(9999)); - root_open(&mut w, "p:presentation", A::new().a("saveSubsetFonts", 1).t("embedTrueTypeFonts", !fonts.is_empty()).o("firstSlideNum", first)); + root_open( + &mut w, + "p:presentation", + A::new().t("saveSubsetFonts", p.save_subset_fonts).t("embedTrueTypeFonts", !fonts.is_empty()).o("firstSlideNum", first), + ); w.open("p:sldMasterIdLst", &[]); for (id, rid) in masters { w.tag("p:sldMasterId").attr("id", id).attr("r:id", rid).empty(); diff --git a/crates/pptx/tests/it/write.rs b/crates/pptx/tests/it/write.rs index 46db7041de..5a7e13859c 100644 --- a/crates/pptx/tests/it/write.rs +++ b/crates/pptx/tests/it/write.rs @@ -100,6 +100,25 @@ fn a_deck_without_masters_gets_the_callers() { assert_eq!(q.slides[0].layout, q.masters[0].layouts[0].id); } +#[test] +fn subset_font_setting_is_not_invented_and_survives_when_present() { + let bytes = craft_pptx::export(&deck(), &Plain).unwrap(); + assert!(!part(&bytes, "ppt/presentation.xml").contains("saveSubsetFonts"), "a new deck must not opt into font subsetting"); + let with_subset = common::rewrite( + &bytes, + |name, data| { + if name != "ppt/presentation.xml" { + return Some(data.to_vec()); + } + let xml = String::from_utf8(data.to_vec()).unwrap(); + Some(xml.replace(" Date: Mon, 30 Nov 2026 14:02:16 +0100 Subject: [PATCH 09/11] rails: backport docked button responses on replay from 47d6a3e09 --- crates/ui-contract/src/contract/mod.rs | 2 +- crates/ui-contract/src/contract/values.rs | 10 ++- crates/ui-contract/src/primitives/sensing.rs | 26 +++++++- crates/ui-panels/src/rails/tool.rs | 10 ++- .../tests/it/docking/group_view.rs | 63 +++++++++++++++++++ 5 files changed, 100 insertions(+), 11 deletions(-) diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 25a5cf6b22..48fc2b8237 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -109,7 +109,7 @@ pub use registry::{CollectionEntry, ContainerEntry, Exemption, LeafEntry, Patter pub use sampler::{CanvasGesture, Sampler}; pub use settle::SettleCx; pub use text::EDIT_MENU; -pub use values::{Bind, BindCheck, BindMut, EditResponse, Hover, ItemOutput, NoValue, Outcome, Validity, ValueOf, clicked, pressed}; +pub use values::{Bind, BindCheck, BindMut, EditResponse, Hover, ItemOutput, NoValue, Outcome, Validity, ValueOf, clicked, pressed, response_of}; use crate::runtime::memory::sub; use crate::runtime::overlay::CloseReason; diff --git a/crates/ui-contract/src/contract/values.rs b/crates/ui-contract/src/contract/values.rs index 91390e6b14..f43f4926cf 100644 --- a/crates/ui-contract/src/contract/values.rs +++ b/crates/ui-contract/src/contract/values.rs @@ -7,7 +7,7 @@ use crate::runtime::memory::{MemoryStage, Savable, SaveKey, StageAccess}; use crate::runtime::reads::{self, BindKey}; use craft_behavior::{Applied, CanvasView, EditEvent, EditEvents, EditPolicy, Mixed, Value}; use egui::Id; -use egui::Response; +use egui::{Response, Ui}; use std::any::TypeId; use std::cell::Cell; use std::sync::Arc; @@ -64,6 +64,14 @@ pub fn clicked(response: &Response) -> bool { crate::runtime::egui::response::clicked(response) } +/// The `Response` of the component `id` in the running pass: its root's egui widget, or the response its arena gives a +/// member of one (a component in a collection's rows or in an arena body, which registers no egui widget). A +/// memoized view's replay shows its components again, so a host reads the response of a component a replayed view +/// showed. `None` for an id no component showed in this pass or the last. +pub fn response_of(ui: &Ui, id: Id) -> Option { + ui.ctx().read_response(id).or_else(|| crate::primitives::sensing::member_response(ui, id)) +} + /// Whether a pointer press went down on `response`'s component and is still held. pub fn pressed(response: &Response) -> bool { crate::runtime::egui::response::is_pressed(response) diff --git a/crates/ui-contract/src/primitives/sensing.rs b/crates/ui-contract/src/primitives/sensing.rs index f5d6671c55..14095b5815 100644 --- a/crates/ui-contract/src/primitives/sensing.rs +++ b/crates/ui-contract/src/primitives/sensing.rs @@ -173,6 +173,7 @@ pub(crate) struct MemberDecl { pub rect: Rect, pub sense: Sense, pub parts: SmallVec<[PartDecl; 4]>, + pub enabled: bool, /// The shapes lie in the body layer's space; `join` sets it. pub local: bool, /// The stack position of the member's `over` parts: just above the member until its body has run, then above @@ -182,8 +183,8 @@ pub(crate) struct MemberDecl { impl MemberDecl { /// A member `id` over `rect` sensing `sense`, with `parts`. - pub(crate) fn new(id: Id, rect: Rect, sense: Sense, parts: &[PartDecl]) -> Self { - MemberDecl { id, rect, sense, parts: parts.iter().cloned().collect(), local: false, over_at: 0 } + pub(crate) fn new(id: Id, rect: Rect, sense: Sense, parts: &[PartDecl], enabled: bool) -> Self { + MemberDecl { id, rect, sense, parts: parts.iter().cloned().collect(), enabled, local: false, over_at: 0 } } } @@ -876,7 +877,7 @@ pub(crate) fn sense_members(ui: &Ui, arena: ArenaId, specs: &[MemberSpec<'_>]) - let outcome = with_arena(ctx, arena, pass_nr, |state| { rotate(state, pass_nr); for spec in specs { - let decl = MemberDecl::new(spec.id, spec.rect, spec.sense, spec.parts); + let decl = MemberDecl::new(spec.id, spec.rect, spec.sense, spec.parts, spec.enabled); if recording { recorded.push(decl.clone()); } @@ -905,6 +906,25 @@ pub(crate) fn sense_members(ui: &Ui, arena: ArenaId, specs: &[MemberSpec<'_>]) - .collect() } +/// The `Response` of the arena member `id` in the running pass, as `sense_members` gives it: from its arena's latest +/// registration of it, a replay's included, and the arena's outcome of the pass. `None` when no arena of the viewport +/// holds `id`. +pub(crate) fn member_response(ui: &Ui, id: Id) -> Option { + let ctx = ui.ctx(); + let viewport = pass::current_viewport(ctx); + let pass_nr = pass::pass_nr(ctx, viewport); + let pointer_pos = pointer::with_frame(ctx, |_, hover| hover); + let (decl, outcome) = PerViewport::::with(ctx, viewport, |arenas| { + arenas.by_root.values().find_map(|state| { + let find = |members: &[MemberDecl]| members.iter().find(|member| member.id == id).cloned(); + // Until the arena's root runs in this pass, `members` holds last pass's registrations. + let decl = find(&state.members).or_else(|| (state.pass == pass_nr).then(|| find(&state.previous)).flatten())?; + Some((decl, state.outcome.filter(|outcome| outcome.pass == pass_nr).unwrap_or_default())) + }) + })?; + Some(response::member(ui, id, decl.rect, decl.enabled, member_view(&outcome, id, decl.local, pointer_pos))) +} + fn member_view(outcome: &Outcome, id: Id, local: bool, pointer_pos: Option) -> MemberView { MemberView { hovered: outcome.hover.find(|hit| hit.owner == id).is_some(), diff --git a/crates/ui-panels/src/rails/tool.rs b/crates/ui-panels/src/rails/tool.rs index 73c95a1aa3..80d19136ba 100644 --- a/crates/ui-panels/src/rails/tool.rs +++ b/crates/ui-panels/src/rails/tool.rs @@ -294,9 +294,7 @@ fn grid(props: &mut GridProps<'_, T>, ui: &mut let icon = props.edit_icon.clone().unwrap_or_else(|| IconId::new("more")); let more = IconButton::new(icon).id_salt("edit-toolbar").label(label).show(ui); edit_toolbar = Some(more.response.id); - if crate::contract::clicked(&more.response) { - sent.send(RailEvent::EditToolbar(more.response)); - } + sent.send(RailEvent::EditToolbar(more.response)); } } } @@ -336,20 +334,20 @@ impl<'a, T: Value + MemoProps + PlainData + 'static> ToolRail<'a, T> { let (mut events, mut edit_toolbar) = (Vec::new(), None); let shown = self.show(ui, |ui, _| edit_toolbar = draw.run(ui, &mut events)); let (mut select, mut double_clicked, mut flyout, mut dropped) = (None, None, None, None); - let mut edit_activation = None; + let mut shown_button = None; for event in events { match event { RailEvent::Select(tool) => select = Some(tool), RailEvent::DoubleClicked(tool) => double_clicked = Some(tool), RailEvent::Flyout(slot) => flyout = Some(slot), RailEvent::Dropped(drop) => dropped = Some(drop), - RailEvent::EditToolbar(response) => edit_activation = Some(response), + RailEvent::EditToolbar(response) => shown_button = Some(response), } } ToolRailOutput { select, double_clicked, - edit_toolbar: edit_activation.or_else(|| edit_toolbar.and_then(|id| ui.ctx().read_response(id))), + edit_toolbar: shown_button.or_else(|| edit_toolbar.and_then(|id| crate::contract::response_of(ui, id))), flyout, dropped, last_used: last, diff --git a/crates/ui-patterns/tests/it/docking/group_view.rs b/crates/ui-patterns/tests/it/docking/group_view.rs index 5fca1c27b4..a58d19f52d 100644 --- a/crates/ui-patterns/tests/it/docking/group_view.rs +++ b/crates/ui-patterns/tests/it/docking/group_view.rs @@ -9,6 +9,8 @@ use craft_ui::display::Text; use craft_ui::docking::{DockConfig, DockGrid, DockPanels, DockSizes, DragUnit, GroupAt, GroupDrag, PanelSpec, PanelSpecs}; use craft_ui::layout_components::Stack; use craft_ui::patterns::dock::DockArea; +use craft_ui::rails::{LastUsed, RailTool, ToolRail, ToolSlot}; +use craft_ui::runtime::commands::EditCommands; use craft_ui::runtime::drag; use craft_ui::testing::{Fixture, last_pass_runs, pointer, trial}; use egui::{Rect, Shape, Ui, Vec2}; @@ -257,3 +259,64 @@ fn a_panels_footer_stays_in_view_under_a_scrolling_body() { assert!(row(&fixture).top() < before.top(), "the body scrolls: {before:?}, then {:?}", row(&fixture)); assert_eq!(fixture.by_label("Apply all").map(|action| action.rect), Some(footer), "the footer stays where it was"); } + +/// The host shows a real tool rail with its Edit Toolbar button, as an app's Tools panel does, and records whether each +/// shown pass reported the button and whether a click on it was reported. +struct ToolRailPanels { + slots: Tracked>>, + last: Tracked>, + reported: Rc>>, + clicked: Rc>, +} + +impl DockPanels for ToolRailPanels { + fn body(&mut self, _: &usize, _: &mut Ui, _: &mut BodyCx<'_>) {} + + fn group_view(&mut self, panels: &[usize], _: usize, ui: &mut Ui, at: GroupAt, _: &mut BodyCx<'_>) -> Option { + if !panels.contains(&RAIL) { + return None; + } + let rail = ToolRail::new("Tools", &self.slots, &0, &self.last).edit_toolbar("Edit Toolbar"); + match at { + GroupAt::Measure(width) => Some(rail.measure_rail(ui, width, |_, _| {}).y), + GroupAt::Show(rect) => { + let out = rail.show_rail(ui, |_, _| {}); + self.reported.borrow_mut().push(out.edit_toolbar.is_some()); + self.clicked.set(self.clicked.get() || out.edit_toolbar.as_ref().is_some_and(craft_ui::contract::clicked)); + Some(rect.height()) + } + } + } +} + +/// A tool rail its host shows in a docked column reports its Edit Toolbar button in every pass it shows, settled or +/// not, and the click on it, so the app can open its drawer. +#[trial] +fn a_docked_tool_rail_reports_its_edit_toolbar_button() { + let tools: Vec> = [EditCommands::Undo, EditCommands::Redo] + .into_iter() + .zip(0u8..) + .map(|(command, id)| ToolSlot::new(u32::from(id), vec![RailTool::new(id, command)])) + .collect(); + let (reported, clicked) = (Rc::new(RefCell::new(Vec::new())), Rc::new(Cell::new(false))); + let mut panels = + ToolRailPanels { slots: Tracked::new(tools), last: Tracked::new(LastUsed::default()), reported: reported.clone(), clicked: clicked.clone() }; + let dock = Node::dock(DockEdge::Start, vec![Column::new(vec![Group::new(vec![RAIL], 0)]).with_steps(1)]); + let root = Node::split(Axis::X, SplitSize::FixedFirst(120.0), dock, Node::tabs(vec![1], 0)); + let mut workspace = Arc::new(Workspace::new(Layout::new(Some(root), Vec::new()))); + let specs = Tracked::new(RailSpecs); + let mut fixture = Fixture::new(move |ui| { + let _ = DockArea::new("Rail dock", Bind::bound(&mut workspace), &specs, &mut panels, DockConfig::default()).show(ui); + }); + fixture.room(Vec2::new(800.0, 600.0)).settle(); + assert!( + !reported.borrow().is_empty() && reported.borrow().iter().all(|seen| *seen), + "every shown pass reports the button: {:?}", + reported.borrow() + ); + let button = fixture.by_label("Edit Toolbar").expect("the docked rail shows its Edit Toolbar button"); + reported.borrow_mut().clear(); + fixture.click(&button).idle(3); + assert!(reported.borrow().iter().all(|seen| *seen), "the passes of the click report the button: {:?}", reported.borrow()); + assert!(clicked.get(), "the click on the button is reported"); +} From f31beb26d4bf677406f2957a60d6688ea3d27681 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 13:52:04 +0100 Subject: [PATCH 10/11] Place overlays using the actual monitor and dim the full modal region (cherry picked from commit 18059c80fa830233780b0981be512e407e818ae4) --- .../ui-contract/src/contract/overlay/host.rs | 5 +++- crates/ui-contract/src/runtime/egui/areas.rs | 18 ++++++++++-- crates/window/src/desktop.rs | 2 +- crates/window/src/desktop/work_area.rs | 29 +++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/src/contract/overlay/host.rs b/crates/ui-contract/src/contract/overlay/host.rs index 95e1cc563c..bdb31662d8 100644 --- a/crates/ui-contract/src/contract/overlay/host.rs +++ b/crates/ui-contract/src/contract/overlay/host.rs @@ -174,7 +174,10 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U Backdrop::None => egui::Color32::TRANSPARENT, }; let through = crate::runtime::sampler::through(ctx, crate::runtime::egui::pass::current_viewport(ctx), layer.id); - areas::show_cover_layer(ctx, areas::CoverLayer { id: cover_id, tier, screen: bounds, scrim, through, absorbs: !layer.exiting }); + // Work-area constraints place the dialog. Its modal cover spans the whole + // client region, including the part on a neighbouring monitor. + let screen = layer.region.map_or_else(|| ctx.content_rect(), |region| region.intersect(ctx.content_rect())); + areas::show_cover_layer(ctx, areas::CoverLayer { id: cover_id, tier, screen, scrim, through, absorbs: !layer.exiting }); Some(areas::layer_of(tier, cover_id)) } _ => None, diff --git a/crates/ui-contract/src/runtime/egui/areas.rs b/crates/ui-contract/src/runtime/egui/areas.rs index 4b3140e179..4027be3253 100644 --- a/crates/ui-contract/src/runtime/egui/areas.rs +++ b/crates/ui-contract/src/runtime/egui/areas.rs @@ -402,10 +402,22 @@ pub(crate) fn safe_rect(ctx: &Context) -> Rect { /// `safe_rect` without noting the read: for the root env, which moves `Input::Shell` by it. pub(crate) fn safe_rect_raw(ctx: &Context) -> Rect { let content = ctx.content_rect(); - ctx.input(|input| { + let (size, inner, state) = ctx.input(|input| { let viewport = input.viewport(); - craft_window::desktop::visible_part(content, viewport.monitor_size, viewport.inner_rect, craft_window::desktop::WindowState::of(viewport)) - }) + (viewport.monitor_size, viewport.inner_rect, craft_window::desktop::WindowState::of(viewport)) + }); + if state != craft_window::desktop::WindowState::FullScreen + && let Some(window) = inner + && let Some(visible) = craft_window::desktop::visible_part_on_monitors( + content, + window, + ctx.pixels_per_point(), + &crate::runtime::windows::WindowHost::of(ctx).monitors(), + ) + { + return visible; + } + craft_window::desktop::visible_part(content, size, inner, state) } /// Hands egui the whole layer order of the running pass, bottom first. egui consumes it by the end of the pass. diff --git a/crates/window/src/desktop.rs b/crates/window/src/desktop.rs index f49fc6d453..ff18f02de6 100644 --- a/crates/window/src/desktop.rs +++ b/crates/window/src/desktop.rs @@ -6,7 +6,7 @@ mod work_area; #[cfg(feature = "ui")] -pub use work_area::{TASKBAR, WindowState, fits, visible_part}; +pub use work_area::{TASKBAR, WindowState, fits, visible_part, visible_part_on_monitors}; #[cfg(target_os = "linux")] mod icon_theme; diff --git a/crates/window/src/desktop/work_area.rs b/crates/window/src/desktop/work_area.rs index cd10048e39..79d5e41bb1 100644 --- a/crates/window/src/desktop/work_area.rs +++ b/crates/window/src/desktop/work_area.rs @@ -6,6 +6,7 @@ //! window's content rect then run under the taskbar: [`visible_part`] is the content rect cut to //! the monitor less that room. +use craft_behavior::{Monitor, placement::monitor_of}; use egui::{Rect, Vec2, ViewportInfo, pos2, vec2}; /// Room kept free at the monitor's bottom edge for a taskbar or Dock egui can't see (the Windows @@ -84,6 +85,23 @@ pub fn visible_part(content: Rect, monitor: Option, inner: Option, s trusted(content, usable.translate(shift)) } +/// The visible part when the host knows the actual desktop layout. Monitor positions +/// are in physical pixels, while the window rectangle uses the current UI scale. +pub fn visible_part_on_monitors(content: Rect, inner: Rect, pixels_per_point: f32, monitors: &[Monitor]) -> Option { + if !inner.is_finite() || !pixels_per_point.is_finite() || pixels_per_point <= 0.0 { + return None; + } + let window_px = Rect::from_min_max(inner.min * pixels_per_point, inner.max * pixels_per_point); + let monitor = monitor_of(monitors, window_px)?; + let mut work = monitor.points_at(pixels_per_point); + if let Some(([x, y], [w, h])) = monitor.work_px { + work = Rect::from_min_size(pos2(x as f32, y as f32) / pixels_per_point, vec2(w as f32, h as f32) / pixels_per_point); + } else { + work.max.y -= TASKBAR; + } + Some(trusted(content, work.translate(content.min - inner.min))) +} + /// `content` cut to `usable`, unless that leaves too little to be a sensible guess. fn trusted(content: Rect, usable: Rect) -> Rect { let visible = content.intersect(usable); @@ -120,6 +138,17 @@ mod tests { assert_eq!(visible_part(content, Some(MONITOR), Some(inner), Normal).bottom(), 768.0 - TASKBAR); } + #[test] + fn a_staggered_monitors_window_keeps_its_visible_top_left_corner() { + let m = Monitor::new(craft_behavior::MonitorKey::new("secondary", [1920, 1200]), [1200, 770], [1920, 1200], 1.0) + .with_work_px([1200, 770], [1920, 1156]); + for scale in [1.0, 1.5] { + let content = Rect::from_min_size(pos2(0.0, 0.0), vec2(1920.0, 1156.0) / scale); + let inner = content.translate(vec2(1200.0, 770.0) / scale); + assert_eq!(visible_part_on_monitors(content, inner, scale, std::slice::from_ref(&m)), Some(content)); + } + } + #[test] fn maximized_unknown_or_nonsense_input_keeps_the_window() { let (content, inner) = window(0.0, 0.0, 1440.0, 900.0); From 8aa1d255d92941130e2b83967df9480f44323ac5 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 14:26:30 +0100 Subject: [PATCH 11/11] window: cover an offset portrait display at mixed DPI --- crates/window/src/desktop/work_area.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/window/src/desktop/work_area.rs b/crates/window/src/desktop/work_area.rs index 79d5e41bb1..18aafe9af6 100644 --- a/crates/window/src/desktop/work_area.rs +++ b/crates/window/src/desktop/work_area.rs @@ -149,6 +149,20 @@ mod tests { } } + #[test] + fn a_menu_keeps_its_client_anchor_on_an_offset_portrait_monitor() { + let laptop = Monitor::new(craft_behavior::MonitorKey::new("laptop", [1920, 1080]), [0, 0], [1920, 1080], 1.0); + let portrait = Monitor::new(craft_behavior::MonitorKey::new("portrait", [1080, 1920]), [1920, -240], [1080, 1920], 1.5) + .with_work_px([1920, -240], [1080, 1872]); + let monitors = [laptop, portrait]; + for scale in [1.0, 1.5] { + let content = Rect::from_min_size(pos2(0.0, 0.0), vec2(1040.0, 1100.0) / scale); + let inner = content.translate(vec2(1920., -240.) / scale); + assert_eq!(visible_part_on_monitors(content, inner, scale, &monitors), Some(content)); + assert!(visible_part(content, Some(vec2(1080., 1920.) / scale), Some(inner), Normal).left() > 0.); + } + } + #[test] fn maximized_unknown_or_nonsense_input_keeps_the_window() { let (content, inner) = window(0.0, 0.0, 1440.0, 900.0);