From 6e5490edc32f9812b29a21ba9e4254cdb66fa603 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 22:23:59 +0100 Subject: [PATCH 1/6] WIP: Layers panel: a hidden layer's eye box stays empty under the pointer (photocraft#16321) From 7843e29364f507689ceefc3bfb5b55dbced5ffcb Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 22:50:45 +0100 Subject: [PATCH 2/6] Layers panel: a hidden layer's eye box stays empty under the pointer (photocraft#16321) A list toggle cell drew its off icon under the pointer, so hiding a layer showed a crossed-out eye in its box until the pointer left. The reference application leaves a hidden layer's box empty in every state. ToggleCell gains `empty_off()`, which never draws the off icon, and the Layers panel's layer and sub-row eye cells use it. Co-Authored-By: Claude Opus 5.5 --- crates/layers/src/ui/panel/row.rs | 5 +-- crates/layers/tests/it/main.rs | 1 + crates/layers/tests/it/panel_eye.rs | 47 +++++++++++++++++++++++++ crates/ui-widgets/src/list/row/paint.rs | 2 +- crates/ui-widgets/src/list/toggle.rs | 31 ++++++++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 crates/layers/tests/it/panel_eye.rs diff --git a/crates/layers/src/ui/panel/row.rs b/crates/layers/src/ui/panel/row.rs index 1f45b557a..4be0ab4ea 100644 --- a/crates/layers/src/ui/panel/row.rs +++ b/crates/layers/src/ui/panel/row.rs @@ -249,7 +249,8 @@ fn layer_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id) -> ListR let contents = cx.options.thumbnail_contents; let active = cx.selection.active.as_ref() == Some(id); - let mut eye = ToggleCell::eye(EYE, info.visible).name(named(&words.visibility, &info.name)); + // A hidden layer's eye box stays empty, also under the pointer (the reference application, photocraft#16321). + let mut eye = ToggleCell::eye(EYE, info.visible).empty_off().name(named(&words.visibility, &info.name)); if let Some(color) = info.label { eye = eye.fill(DataColor::new(paint_color(color.fill()))); } @@ -369,7 +370,7 @@ fn sub_row<'r, T: LayerTree>(cx: &'r PanelContext<'r, T>, id: &T::Id, group: Sub row = row.ink(RowInk::Dimmed); } if sub.eye_shown { - row = row.toggle(ToggleCell::eye(EYE, sub.on).name(named(&words.visibility, &sub.label))); + row = row.toggle(ToggleCell::eye(EYE, sub.on).empty_off().name(named(&words.visibility, &sub.label))); } let size = cx.options.thumbnail_size; let header_mask = group == SubRowGroup::SmartFilters && index.is_none() && sub.mask && size != ThumbSize::None; diff --git a/crates/layers/tests/it/main.rs b/crates/layers/tests/it/main.rs index cc236b5a0..36c2b8fa5 100644 --- a/crates/layers/tests/it/main.rs +++ b/crates/layers/tests/it/main.rs @@ -3,6 +3,7 @@ pub(crate) mod blend_rows; pub(crate) mod comps; pub(crate) mod panel_drag_menu; +pub(crate) mod panel_eye; pub(crate) mod panel_filter; pub(crate) mod panel_input; pub(crate) mod panel_memo; diff --git a/crates/layers/tests/it/panel_eye.rs b/crates/layers/tests/it/panel_eye.rs new file mode 100644 index 000000000..54d74cbf1 --- /dev/null +++ b/crates/layers/tests/it/panel_eye.rs @@ -0,0 +1,47 @@ +//! `LayersPanel` eye boxes: a hidden layer's box stays empty, also under the pointer (photocraft#16321). + +use craft_layers::ui::mock::FakeLayers; +use craft_layers::ui::panel::LayersPanel; +use craft_layers::ui::tree::{LayerInfo, LayerKind}; +use craft_ui::contract::Tracked; +use craft_ui::testing::{Fixture, pointer, trial}; +use egui::{Rect, Vec2}; +use std::cell::RefCell; +use std::rc::Rc; + +/// A visible layer over a hidden one. +fn rig() -> Fixture { + let mut tree = FakeLayers::default(); + tree.add(None, LayerInfo::new("Shown", LayerKind::Pixel), false); + let mut hidden = LayerInfo::new("Hidden", LayerKind::Pixel); + hidden.visible = false; + tree.add(None, hidden, false); + let tree = Rc::new(RefCell::new(Tracked::new(tree))); + let mut fixture = Fixture::new(move |ui| { + let tree = tree.borrow(); + let _ = LayersPanel::new(&tree).show(ui); + }); + fixture.room(Vec2::new(420.0, 560.0)); + fixture.settle(); + fixture +} + +/// How many shapes the frame paints wholly inside the eye box `cell`: its icon, not the row's fill around it. +fn drawn_in(fixture: &mut Fixture, cell: Rect) -> usize { + fixture.frame_shapes().iter().filter(|shape| cell.contains_rect(shape.visual_bounding_rect())).count() +} + +/// The pointer over a hidden layer's eye box draws nothing there (no crossed-out eye), while a visible layer's box +/// under the pointer draws its eye. +#[trial] +fn a_hidden_layers_eye_box_stays_empty_under_the_pointer() { + let mut fixture = rig(); + let shown = fixture.by_label("Visibility Shown").unwrap_or_else(|| panic!("no eye box for Shown")).rect; + let hidden = fixture.by_label("Visibility Hidden").unwrap_or_else(|| panic!("no eye box for Hidden")).rect; + + fixture.frame(vec![pointer::moved(shown.center())]).idle(2); + assert!(drawn_in(&mut fixture, shown) > 0, "the visible layer's eye is drawn"); + + fixture.frame(vec![pointer::moved(hidden.center())]).idle(2); + assert_eq!(drawn_in(&mut fixture, hidden), 0, "the hidden layer's box stays empty under the pointer"); +} diff --git a/crates/ui-widgets/src/list/row/paint.rs b/crates/ui-widgets/src/list/row/paint.rs index 2a1db4a3f..fd98cf443 100644 --- a/crates/ui-widgets/src/list/row/paint.rs +++ b/crates/ui-widgets/src/list/row/paint.rs @@ -91,7 +91,7 @@ impl ListRow<'_> { ToggleFace::Icons { on, off } => { let shown = match toggle.state { ToggleState::On | ToggleState::Mixed => Some(on), - ToggleState::Off if toggle.always_visible || cx.part(part).hovered => Some(off), + ToggleState::Off if toggle.shows_off(cx.part(part).hovered) => Some(off), ToggleState::Off => None, }; if let Some(id) = shown { diff --git a/crates/ui-widgets/src/list/toggle.rs b/crates/ui-widgets/src/list/toggle.rs index 3cfeee149..82f8f8149 100644 --- a/crates/ui-widgets/src/list/toggle.rs +++ b/crates/ui-widgets/src/list/toggle.rs @@ -80,6 +80,9 @@ pub struct ToggleCell { pub fill: Option, /// The off icon shows in every row, not only under the pointer. No effect on a check face. pub always_visible: bool, + /// The off icon never shows, also under the pointer: an off cell stays empty (a hidden layer's eye box). Wins + /// over `always_visible`. No effect on a check face. + pub empty_off: bool, /// A screen reader announces a check box instead of a toggle button: for a setting the row carries rather than /// an action on the row. pub check_box: bool, @@ -99,6 +102,7 @@ impl ToggleCell { tooltip: None, fill: None, always_visible: false, + empty_off: false, check_box: false, row_press: false, } @@ -162,10 +166,37 @@ impl ToggleCell { self } + /// The off icon never shows, also under the pointer: an off cell stays an empty box. + #[must_use] + pub fn empty_off(mut self) -> Self { + self.empty_off = true; + self + } + /// A press on the row's own area shows on the cell, for a row whose click turns on what the cell shows. #[must_use] pub fn row_press(mut self) -> Self { self.row_press = true; self } + + /// Whether an off cell draws its off icon, under the pointer when `hovered`. + pub(super) fn shows_off(&self, hovered: bool) -> bool { + !self.empty_off && (self.always_visible || hovered) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn an_empty_off_cell_never_draws_its_off_icon() { + let eye = ToggleCell::eye(ColumnKey::new("eye"), false); + assert!(!eye.shows_off(false) && eye.shows_off(true), "a plain off cell shows its off icon only under the pointer"); + assert!(eye.clone().always_visible().shows_off(false), "always_visible shows it in every row"); + let empty = eye.empty_off(); + assert!(!empty.shows_off(true), "an empty_off cell stays empty under the pointer"); + assert!(!empty.always_visible().shows_off(true), "empty_off wins over always_visible"); + } } From c1a34f7d8d3ce1faf87d585fe978483491065461 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 22:58:36 +0100 Subject: [PATCH 3/6] WIP: menu bar: Space on the focused bar leaves it and reaches the Hand (photocraft#16327) From ca3d21835d3a3f61634a42f2b2f379c0dbeaf3b6 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 23:00:28 +0100 Subject: [PATCH 4/6] WIP: Canvas scroll bars: pasteboard range and a thumb that stays under the pointer (photocraft#16328, photocraft#16329) From 0712064ab1058cb2980fc42a54ab1a9e88945834 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 23:02:38 +0100 Subject: [PATCH 5/6] Canvas scroll bars: pasteboard range, thumb stays under the pointer (photocraft#16328, photocraft#16329) With Overscroll on, the bars' range takes in the pasteboard: at either end of a track 100 screen points of the document stay in view at the opposite edge, at any zoom and for documents larger or smaller than the window, as measured in the reference application. Overscroll off is unchanged. A thumb drag keeps the range the bar had at the press and maps the pointer's movement from the press onto it, so the thumb stays under the pointer: past a track's end the view waits, and moving back moves it again in the same drag. Co-Authored-By: Claude Opus 5.5 --- crates/ui-canvas/src/canvas/scrollbars/mod.rs | 148 +++++++++++++++--- .../ui-canvas/tests/it/canvas/scrollbars.rs | 110 +++++++++++++ 2 files changed, 232 insertions(+), 26 deletions(-) diff --git a/crates/ui-canvas/src/canvas/scrollbars/mod.rs b/crates/ui-canvas/src/canvas/scrollbars/mod.rs index a4311c53b..6b64e1624 100644 --- a/crates/ui-canvas/src/canvas/scrollbars/mod.rs +++ b/crates/ui-canvas/src/canvas/scrollbars/mod.rs @@ -3,9 +3,13 @@ //! thickness at rest and under the pointer. 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, a document smaller than the window can also be scrolled from -//! one edge of the window to the other. With overscroll off the app clamps the view before it draws -//! ([`CanvasScrollbars::clamp`]). +//! the track to page by one screenful. With overscroll on, the extent also takes in the pasteboard around the document, +//! as in the reference application: at either end of a track [`KEPT_IN_VIEW`] points of the document stay in view at +//! the opposite edge, whether the document is larger or smaller than the window. With overscroll off the app clamps the +//! view before it draws ([`CanvasScrollbars::clamp`]). +//! +//! A thumb drag keeps the extent it began with and follows the pointer from the press: the thumb stays under the +//! pointer, also after the pointer went past a track's end and came back. //! //! The bars measure the view along the screen axes, so on a rotated view they show the extent of the unrotated //! document. @@ -44,6 +48,10 @@ const ARROW_STEP_PIXELS: f64 = 16.0; const ARROW_HOLD_DELAY: f64 = 0.4; const ARROW_HOLD_INTERVAL: f64 = 0.06; +/// With overscroll on, how much of the document stays in view, in screen points, when a thumb is at either end of its +/// track: the reference application keeps 100 screen pixels at every zoom, on both axes. +const KEPT_IN_VIEW: f64 = 100.0; + /// The popup of the tip beside a dragged vertical thumb. const TIP: &str = "tip"; @@ -76,26 +84,30 @@ struct Span { /// First and last visible coordinate. v0: f64, v1: f64, + /// [`KEPT_IN_VIEW`] in document units on this axis. + kept: f64, } impl Span { - /// The axis of a view: `size` screen points at `zoom` around `center`. - fn of(len: f64, center: f64, size: f64, zoom: f64) -> Option { + /// The axis of a view: `size` screen points at `zoom` around `center`; `kept` is [`KEPT_IN_VIEW`] in the same + /// points (the horizontal axis divides both by the pixel aspect). + fn of(len: f64, center: f64, size: f64, zoom: f64, kept: f64) -> Option { let zoom = if zoom.is_finite() && zoom > 0.0 { zoom } else { return None }; let half = size / zoom / 2.0; - let span = Span { len, v0: center - half, v1: center + half }; + let span = Span { len, v0: center - half, v1: center + half, kept: kept / zoom }; (span.len.is_finite() && span.len > 0.0 && span.v0.is_finite() && span.v1.is_finite() && span.v1 > span.v0).then_some(span) } - /// The scrollable extent: the document and the visible span. With `overscroll`, a document shorter than the span - /// may slide edge to edge within it. + /// The scrollable extent: the document and the visible span. With `overscroll` also the pasteboard on both sides, + /// up to where only [`KEPT_IN_VIEW`] of the document (all of a shorter one) is left in view at the opposite edge. fn content(&self, overscroll: bool) -> Range { let (lo, hi) = (self.v0.min(0.0), self.v1.max(self.len)); if !overscroll { return lo..hi; } - let visible = self.v1 - self.v0; - lo.min(self.len - visible)..hi.max(visible) + let kept = if self.kept.is_finite() { self.kept.clamp(0.0, self.len) } else { self.len }; + let room = (self.v1 - self.v0 - kept).max(0.0); + lo.min(-room)..hi.max(self.len + room) } fn scroll(&self, overscroll: bool) -> ScrollSpan { @@ -142,6 +154,26 @@ impl Bar { } } +/// A pressed thumb: the extent and the visible range it was pressed at. Its drag maps the pointer's movement from the +/// press onto that extent, so the track does not grow or shrink under the pointer while the view moves, and the thumb +/// stays under the pointer. +#[derive(Clone, Debug, Default, PartialEq)] +struct HeldThumb { + horizontal: bool, + content: Range, + visible: Range, +} + +impl HeldThumb { + fn of(axis: Axis, span: &ScrollSpan) -> Self { + HeldThumb { horizontal: axis == Axis::X, content: span.content.clone(), visible: span.visible.clone() } + } + + fn on(&self, axis: Axis) -> bool { + self.horizontal == (axis == Axis::X) + } +} + /// The bars of a view over a document, in the order horizontal, vertical. struct Bars { horizontal: Option, @@ -198,6 +230,11 @@ fn paint_arrow(draw: &Draw<'_>, rect: Rect, axis: Axis, after: bool, color: Styl draw.stroke(&path, StrokeWidth::Thin, color); } +/// The length of a scroll bar's track along `axis`. +fn scroll_track_length(track: Rect, axis: Axis) -> f32 { + if axis == Axis::X { track.width() } else { track.height() } +} + /// How the document's x axis runs on screen: with the view flipped, backwards. fn along_x(view: &CanvasView, width: f64, c: f64) -> f64 { if view.flip_x { width - c } else { c } @@ -208,20 +245,43 @@ fn aspect(view: &CanvasView) -> f64 { } impl Bars { - /// The bars inside `rect` (bottom and right edges), `width` thick, for `view` over the document `doc`. - fn of(view: &CanvasView, doc: DocRect, overscroll: bool, horizontal: bool, rect: Rect, style: &ScrollbarsStyle) -> Bars { + /// The bars inside `rect` (bottom and right edges), `width` thick, for `view` over the document `doc`. A `held` + /// thumb's bar keeps the extent the thumb was pressed at. + fn of( + view: &CanvasView, + doc: DocRect, + overscroll: bool, + horizontal: bool, + rect: Rect, + style: &ScrollbarsStyle, + held: Option<&HeldThumb>, + ) -> Bars { let document_chrome = style.document.is_some(); let mut width = style.look.thickness; if document_chrome { width = width.min(rect.width().max(0.0)).min(rect.height().max(0.0)); } - let x = Span::of(doc.width(), along_x(view, doc.width(), view.center.x - doc.x0), f64::from(view.rect.width()) / aspect(view), view.zoom) - .filter(|_| horizontal); - let y = Span::of(doc.height(), view.center.y - doc.y0, f64::from(view.rect.height()), view.zoom); + let x = Span::of( + doc.width(), + along_x(view, doc.width(), view.center.x - doc.x0), + f64::from(view.rect.width()) / aspect(view), + view.zoom, + KEPT_IN_VIEW / aspect(view), + ) + .filter(|_| horizontal); + let y = Span::of(doc.height(), view.center.y - doc.y0, f64::from(view.rect.height()), view.zoom, KEPT_IN_VIEW); let right = if y.is_some() { rect.right() - width } else { rect.right() }; let bottom = if x.is_some() { rect.bottom() - width } else { rect.bottom() }; let corner = (document_chrome && x.is_some() && y.is_some()).then(|| Rect::from_min_max(pos2(right, bottom), rect.max)); - let bar = |span: Option, axis, rect| span.map(|span| Bar::new(rect, axis, span.scroll(overscroll), document_chrome)); + let bar = |span: Option, axis, rect| { + span.map(|span| { + let mut scroll = span.scroll(overscroll); + if let Some(held) = held.filter(|held| held.on(axis)) { + scroll.content = held.content.start.min(scroll.visible.start)..held.content.end.max(scroll.visible.end); + } + Bar::new(rect, axis, scroll, document_chrome) + }) + }; Bars { horizontal: bar(x, Axis::X, Rect::from_min_max(pos2(rect.left(), bottom), pos2(right, rect.bottom()))), vertical: bar(y, Axis::Y, Rect::from_min_max(pos2(right, rect.top()), pos2(rect.right(), bottom))), @@ -298,13 +358,24 @@ pub struct CanvasScrollbars<'a> { /// thumb on the reading-start side. #[prop] tip: Option<&'a dyn Fn(&CanvasView) -> Label>, + /// The thumb pressed in this pass, as `update` read it from the press slot, for `paint` and `access`. + held: Option, } impl<'a> CanvasScrollbars<'a> { /// Scroll bars named `label` that edit `view`, a view over the document `document` (document units). pub fn new(label: impl Into