From 84279466d43f3aee85ca9bdc1cd7a8ba3389651a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 02:50:15 -0800 Subject: [PATCH] ui-contract: a scroll bar whose track has no room paints nothing A scroll view shorter than its padding has a view whose top lies below its bottom, and its scroll bar track inherits those crossed ends. The bar painted a thumb in that track. A scroll body 6 pt tall with 6 pt of padding above and below painted a thumb of zero height, and a FileListPicker list given 12 pt with 8 pt of padding painted one with a negative height, at [254.8, 296] to [256.8, 292]. ScrollBar::shapes now returns no shapes when the track is not positive, as ScrollBar::fades already paints no fade over a view with no room. Every bar that goes through it, a scroll body's, a collection's, the canvas's and the timeline's, is covered. Bars in views that have room paint as before. --- .../ui-contract/src/primitives/scroll_bar.rs | 6 +++- crates/ui-contract/tests/it/layout/mod.rs | 1 + .../ui-contract/tests/it/layout/short_view.rs | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 crates/ui-contract/tests/it/layout/short_view.rs diff --git a/crates/ui-contract/src/primitives/scroll_bar.rs b/crates/ui-contract/src/primitives/scroll_bar.rs index 8027b18d5..3ff0a08bd 100644 --- a/crates/ui-contract/src/primitives/scroll_bar.rs +++ b/crates/ui-contract/src/primitives/scroll_bar.rs @@ -89,8 +89,12 @@ impl ScrollBar { /// The shapes of the bar in `track` along `axis` for `span`, in `state` (the bar's: hovered while the pointer is /// anywhere on it): the track and the fully round thumb, `look.thumb_width` thick along the track's outer edge (its - /// bottom, or its end side in the reading direction). + /// bottom, or its end side in the reading direction). No shapes when the track has no room: a view shorter or + /// narrower than its padding gives its bar a track of no length, or one whose ends cross. pub fn shapes(look: &ScrollBarLook, track: Rect, axis: Axis, rtl: bool, span: &ScrollSpan, state: &StateSet) -> Vec { + if !track.is_positive() { + return Vec::new(); + } let full = Self::thumb(look.min_thumb, track, axis, rtl, span); let thumb = Self::along_edge(full, state.resolve(&look.thumb_width), axis, rtl); let round = |rect: Rect| CornerRadius::from(rect.width().min(rect.height()) / 2.0); diff --git a/crates/ui-contract/tests/it/layout/mod.rs b/crates/ui-contract/tests/it/layout/mod.rs index 3c8d9f2c6..7ccab8dc8 100644 --- a/crates/ui-contract/tests/it/layout/mod.rs +++ b/crates/ui-contract/tests/it/layout/mod.rs @@ -3,3 +3,4 @@ pub(crate) mod fill; pub(crate) mod line_fill; pub(crate) mod memory; pub(crate) mod overlay_bar; +pub(crate) mod short_view; diff --git a/crates/ui-contract/tests/it/layout/short_view.rs b/crates/ui-contract/tests/it/layout/short_view.rs new file mode 100644 index 000000000..0264444f3 --- /dev/null +++ b/crates/ui-contract/tests/it/layout/short_view.rs @@ -0,0 +1,33 @@ +//! A scroll body whose rect is shorter than its padding: its view has no room, so its scroll bar paints nothing. + +use craft_ui::contract::{ContainerProps, Pad, Props as _, Scroll, Show as _, ShowContainer as _, Sizing}; +use craft_ui::testing::{Frames, pointer, trial}; +use craft_ui_test_kit::body::Slab; +use craft_ui_test_kit::contract::{Probe, Seen}; +use egui::{Pos2, Rect, Shape, Ui, Vec2}; +use std::cell::RefCell; + +/// The container's rect: shorter than the padding above and below its view. +const AT: Rect = Rect { min: Pos2::new(20.0, 20.0), max: Pos2::new(180.0, 26.0) }; + +/// The padded container that scrolls along y under `scroll`'s bar, holding a probe that paints nothing and is far +/// taller than the container. +fn short(ui: &mut Ui, seen: &RefCell, scroll: Scroll) { + let props = ContainerProps::new().pad(Pad::Control).sizing(Sizing::Fill).scroll(scroll); + Slab::new(props).id_salt("short").show_at(ui, AT, |ui, _| { + Probe::new(seen).size(Vec2::new(40.0, 400.0)).sizing(Sizing::FillWidth).id_salt("content").show(ui); + }); +} + +#[trial] +fn a_scroll_body_shorter_than_its_padding_paints_no_bar() { + for (name, scroll) in [("bar", Scroll::vertical()), ("overlay bar", Scroll::vertical().overlay())] { + let seen = RefCell::new(Seen::default()); + let mut show = |ui: &mut Ui| short(ui, &seen, scroll); + let mut frames = Frames::new(); + frames.frame(vec![pointer::moved(AT.center())], &mut show); + frames.idle(4, &mut show); + let painted: Vec = frames.frame_shapes(&mut show).iter().map(Shape::visual_bounding_rect).filter(|bounds| bounds.is_finite()).collect(); + assert!(painted.is_empty(), "{name}: the bar paints nothing: {painted:?}"); + } +}