diff --git a/crates/behavior/src/cursor.rs b/crates/behavior/src/cursor.rs index 3b6a67f78..2d69e7ff7 100644 --- a/crates/behavior/src/cursor.rs +++ b/crates/behavior/src/cursor.rs @@ -208,13 +208,15 @@ pub enum PaintedCursor { end: bool, }, /// A pointer with the tool's icon below and right of it: a crosshair (Perspective Crop), or an arrow with its tip - /// on the hotspot (Paint Bucket, Ruler). + /// on the hotspot (Paint Bucket, Ruler, the lassos). #[non_exhaustive] PointerTool { /// The pointer the icon rides beside. pointer: PointerGlyph, /// The icon. icon: IconId, + /// A mark at the icon's lower right. + badge: Option, }, /// No cursor at all. Hidden, @@ -294,7 +296,12 @@ impl PaintedCursor { /// `pointer` with the tool's icon below and right of it. pub const fn pointer_tool(pointer: PointerGlyph, icon: IconId) -> Self { - PaintedCursor::PointerTool { pointer, icon } + PaintedCursor::PointerTool { pointer, icon, badge: None } + } + + /// `pointer` with the tool's icon below and right of it, and `badge` at the icon's lower right. + pub const fn pointer_tool_badged(pointer: PointerGlyph, icon: IconId, badge: Option) -> Self { + PaintedCursor::PointerTool { pointer, icon, badge } } /// A system cursor with a mark. diff --git a/crates/imaging/src/ui/select/lasso.rs b/crates/imaging/src/ui/select/lasso.rs index 25f9a8461..ec6037b6b 100644 --- a/crates/imaging/src/ui/select/lasso.rs +++ b/crates/imaging/src/ui/select/lasso.rs @@ -1,19 +1,16 @@ //! [`LassoTool`]: the freehand Lasso with Alt-latched straight segments, and the pieces the Polygonal Lasso shares. use craft_behavior::geometry::{ConstrainStyle, DraftEvent, DraftKind, DraftPoint, DraftReach, OutlineDraft, SelectionOperation}; -use craft_behavior::{CancelReason, Cursor, PaintedCursor, PointerButton}; +use craft_behavior::{CancelReason, Cursor, PaintedCursor, PointerButton, PointerGlyph}; use craft_keymap::{Key, Mods}; use craft_ui::canvas::{CanvasTool, ToolAccess, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer}; use craft_ui::primitives::{Draw, PaintShape, StrokeWidth, ToolIcon}; -use egui::{Pos2, Vec2}; +use egui::Pos2; use kurbo::Rect; use super::drag::{InsideDrag, PressRule, cursor_over, drag_kind, moved_selection_snap}; use super::{DragKind, Place, Report, SelectEvent, SelectPhase, SelectToolPass, SelectWords, SelectionProbe, SelectionShape}; -/// Where a lasso cursor's icon touches the document: the icon's own origin. -const ICON_HOTSPOT: Vec2 = Vec2::ZERO; - /// The reach of an outline's closing presses in this pass: a press within the slop of the first vertex or of the last /// closes. pub(super) fn reach(cx: &ToolContext<'_>) -> DraftReach { @@ -54,7 +51,8 @@ pub(super) struct LassoCursor<'a> { pub(super) rule: PressRule, } -/// The lasso icon with the operation's badge: the latched one while an outline is open, else the live modifiers'; +/// The arrow with its tip on the point the outline starts from, the lasso icon below and right of it and the +/// operation's badge beside the icon: the latched one while an outline is open, else the live modifiers'; /// Cmd is the Move tool's, so it shows none. Over the selection, the cursors of [`cursor_over`]. pub(super) fn cursor(shown: &LassoCursor<'_>, probe: &dyn SelectionProbe, cx: &ToolContext<'_>) -> Cursor { let LassoCursor { icon, draft, operation, bar, inside, rule } = shown; @@ -71,7 +69,7 @@ pub(super) fn cursor(shown: &LassoCursor<'_>, probe: &dyn SelectionProbe, cx: &T } else { SelectionOperation::resolve(*bar, cx.mods, probe.has_selection()).badge() }; - PaintedCursor::tool(icon.icon(), ICON_HOTSPOT, badge).into() + PaintedCursor::pointer_tool_badged(PointerGlyph::Arrow, icon.icon(), badge).into() } /// The outline as marching ants and, between straight segments, the rubber band: the one painter of an diff --git a/crates/imaging/src/ui/select/magnetic.rs b/crates/imaging/src/ui/select/magnetic.rs index 8528dfa5f..2f4964554 100644 --- a/crates/imaging/src/ui/select/magnetic.rs +++ b/crates/imaging/src/ui/select/magnetic.rs @@ -1,7 +1,7 @@ //! [`MagneticLassoTool`]: an outline that snaps to the edges the app's [`EdgeTracer`] finds. use craft_behavior::geometry::SelectionOperation; -use craft_behavior::{CancelReason, Cursor, PaintedCursor}; +use craft_behavior::{CancelReason, Cursor, PaintedCursor, PointerGlyph}; use craft_keymap::{Key, Mods}; use craft_ui::canvas::{CanvasTool, ToolAccess, ToolAction, ToolClaims, ToolContext, ToolKey, ToolPath, ToolPointer}; use craft_ui::primitives::{Draw, PaintShape, StrokeWidth, ToolIcon}; @@ -12,9 +12,6 @@ use serde::{Deserialize, Serialize}; use super::lasso::{DraftKey, draft_command, outline_access}; use super::{Place, Report, SelectEvent, SelectPhase, SelectToolPass, SelectionProbe, SelectionShape}; -/// Where the magnetic lasso cursor's icon touches the document: the icon's own origin. -const ICON_HOTSPOT: Vec2 = Vec2::ZERO; - /// The detection settings of one edge query. #[derive(Clone, Copy, Debug, PartialEq)] #[non_exhaustive] @@ -478,8 +475,8 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { if self.tool.outline.as_ref().is_some_and(|o| !o.down) { ToolClaims::NONE.keyboard().deletes() } else { ToolClaims::NONE } } - /// The width circle under the canvas's precise cursor (`width * zoom`, at least the slop); otherwise the lasso - /// icon with the operation's badge. + /// The width circle under the canvas's precise cursor (`width * zoom`, at least the slop); otherwise the arrow on + /// the pointer with the lasso icon beside it and the operation's badge. fn cursor(&self, cx: &ToolContext<'_>) -> Cursor { let tool = &*self.tool; if cx.precise() @@ -494,7 +491,7 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { None if cx.mods.cmd => None, None => SelectionOperation::resolve(tool.bar, cx.mods, self.probe.has_selection()).badge(), }; - PaintedCursor::tool(ToolIcon::MagneticLasso.icon(), ICON_HOTSPOT, badge).into() + PaintedCursor::pointer_tool_badged(PointerGlyph::Arrow, ToolIcon::MagneticLasso.icon(), badge).into() } /// The first click starts an outline; later ones close near the first point, add a straight segment with Alt (and diff --git a/crates/imaging/tests/it/raw_develop.rs b/crates/imaging/tests/it/raw_develop.rs index 782930247..213d5fb77 100644 --- a/crates/imaging/tests/it/raw_develop.rs +++ b/crates/imaging/tests/it/raw_develop.rs @@ -19,7 +19,7 @@ use craft_imaging::ui::wide_angle::PreviewDone; use craft_imaging::ui::{ChannelColor, HistogramSet, ScopeChannel}; use craft_ui::InstallSpec; use craft_ui::canvas::{PixelRect, RasterSource}; -use craft_ui::dialog::{DialogHost, DialogResult, FullWindowWorkspace as _, HostedWorkspace}; +use craft_ui::dialog::{DialogHost, DialogResult, FullWindowWorkspace as _, HostedWorkspace, OWN_WINDOW_MIN_SIZE}; use craft_ui::primitives::Revision; use craft_ui::runtime::access::Role; use craft_ui::runtime::pending::Job; @@ -251,6 +251,26 @@ fn raw_develop_window_keeps_its_size_when_the_saved_screen_is_gone() { assert!((0.0..=880.0).contains(&pos.x) && (0.0..=320.0).contains(&pos.y), "restored position is in reach: {pos:?}"); } +/// photocraft#16595: while the window shrank each frame, the placement store saved its size, 1 pt wide at 100 % +/// scaling. Restored, the window opens no smaller than a full-window dialog's own window may be, and the OS keeps it +/// there. +#[trial] +fn raw_develop_window_saved_while_shrinking_opens_at_its_minimum() { + let store = Arc::new(Mutex::new(Store::in_memory())); + store.lock().unwrap().set("craft_imaging.raw_develop.window", &Placement::new([1.0, 500.0], 1.0)); + let system = Arc::new(FakeSystem::new()); + system.set_monitors(vec![Monitor::new(MonitorKey::new("Attached", [1920, 1080]), [0, 0], [1920, 1080], 1.0)]); + let windows = Windows::with(InstallSpec::new(ShellInfo::default(), system).placement(store)); + let mut host = DialogHost::new(); + host.open(HostedWorkspace::new(RawDevelopWorkspace::new(open(RawTarget::OpenRaw)), Source::new())); + let output = windows.frame(vec![], vec![], |ui| { + host.run(ui); + }); + let (_, builder) = output.builders.iter().find(|(id, _)| *id != ViewportId::ROOT).expect("Raw Develop opens a child window"); + assert_eq!(builder.inner_size, Some(Vec2::new(OWN_WINDOW_MIN_SIZE.x, 500.0)), "the saved width is raised to the minimum"); + assert_eq!(builder.min_inner_size, Some(OWN_WINDOW_MIN_SIZE), "the OS keeps the window at least that big"); +} + #[trial] fn raw_develop_switches_raws_and_finishes_with_each_footer_button() { let host = Rc::new(RefCell::new(DialogHost::new())); diff --git a/crates/imaging/tests/it/select.rs b/crates/imaging/tests/it/select.rs index dfb6baf0e..c9ef917fa 100644 --- a/crates/imaging/tests/it/select.rs +++ b/crates/imaging/tests/it/select.rs @@ -951,6 +951,48 @@ fn the_magnetic_lasso_shows_the_width_circle_under_the_precise_cursor() { } } +/// The cursor `rig` shows over the middle of its canvas with `mods` held. +fn lasso_cursor(rig: &mut Rig, mods: Modifiers) -> Option +where + for<'a> SelectToolPass<'a, T>: CanvasTool, +{ + let ctx = rig.fixture().ctx().clone(); + let over = rig.canvas().center(); + rig.fixture().frame(vec![pointer::moved(over)]); + hold(rig, mods); + rig.fixture().frame(Vec::new()); + craft_ui::runtime::cursor::current(&ctx) +} + +// The lassos show an arrow with its tip where the outline starts and the tool's icon below right of it, as the reference +// application does; the operation's badge rides at the icon's lower right. With the icon alone on the pointer, its +// empty top-left corner was the hotspot, so the outline began beside the icon (photocraft#16671). +#[trial] +fn the_lassos_point_an_arrow_at_where_the_outline_starts() { + use craft_behavior::{Cursor, CursorBadge, PaintedCursor, PointerGlyph}; + use craft_ui::primitives::ToolIcon; + fn check(cursor: Option, icon: ToolIcon, badge: Option, what: &str) { + match cursor { + Some(Cursor::Painted(PaintedCursor::PointerTool { pointer, icon: shown, badge: b, .. })) => { + assert_eq!(pointer, PointerGlyph::Arrow, "{what}: an arrow"); + assert_eq!(shown, icon.icon(), "{what}: the tool's icon"); + assert_eq!(b, badge, "{what}: the badge"); + } + other => panic!("{what}: an arrow with the tool's icon, got {other:?}"), + } + } + let selected = Rect::new(20.0, 20.0, 60.0, 60.0); + let shift = Modifiers::SHIFT; + let mut lasso = rig("Lasso", LassoTool::new(), Fake::selected(selected)); + check(lasso_cursor(&mut lasso, Modifiers::NONE), ToolIcon::Lasso, None, "Lasso"); + check(lasso_cursor(&mut lasso, shift), ToolIcon::Lasso, Some(CursorBadge::Add), "Lasso with Shift"); + let mut polygon = rig("Polygonal Lasso", PolygonLassoTool::new(), Fake::selected(selected)); + check(lasso_cursor(&mut polygon, Modifiers::NONE), ToolIcon::PolygonalLasso, None, "Polygonal Lasso"); + check(lasso_cursor(&mut polygon, Modifiers::ALT), ToolIcon::PolygonalLasso, Some(CursorBadge::Subtract), "Polygonal Lasso with Alt"); + let (mut magnetic, _) = magnetic(); + check(lasso_cursor(&mut magnetic, Modifiers::NONE), ToolIcon::MagneticLasso, None, "Magnetic Lasso"); +} + #[trial] fn width_steps_by_one_and_shift_jumps_to_the_limits() { let mut settings = MagneticSettings::default(); diff --git a/crates/ui-canvas/src/canvas/full_window.rs b/crates/ui-canvas/src/canvas/full_window.rs index 6244a0f7e..8a8f4a594 100644 --- a/crates/ui-canvas/src/canvas/full_window.rs +++ b/crates/ui-canvas/src/canvas/full_window.rs @@ -16,7 +16,7 @@ use crate::runtime::windows::WindowSpec; use crate::sections::FooterButton; use crate::style::{ComponentStyle, StyleCx, SurfaceKind}; use craft_behavior::{Metrics, Sense}; -use egui::Ui; +use egui::{Ui, Vec2, vec2}; pub use hosted::{FullWindowWorkspace, HostedWorkspace, WorkspaceCx, WorkspacePass}; @@ -26,6 +26,11 @@ pub(crate) mod stories; #[cfg(feature = "suite")] pub(crate) mod trials; +/// The least a full-window dialog's own window may be, in points: the OS window's minimum, and the floor a restored +/// placement is fitted to. A placement saved while photocraft#16595 shrank the window could be 1 pt wide; without +/// a floor it opened that small and nothing grew it again. +pub const OWN_WINDOW_MIN_SIZE: Vec2 = vec2(640.0, 480.0); + /// The style of a full-window dialog: the surface comes from the container. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] #[non_exhaustive] @@ -121,13 +126,14 @@ impl<'a> FullWindowDialog<'a> { .label(title) } - /// Shows the dialog in its own OS window described by `spec`, resizable, opening at the saved placement; where - /// viewports are unavailable it fills the main window. The dialog's focus policy moves into the fallback overlay. + /// Shows the dialog in its own OS window described by `spec`, resizable down to [`OWN_WINDOW_MIN_SIZE`], opening at + /// the saved placement; where viewports are unavailable it fills the main window. The dialog's focus policy moves + /// into the fallback overlay. #[must_use] pub fn own_window(mut self, spec: WindowSpec) -> Self { // A viewport mount takes its scope from the fallback overlay and holds `props.focus` at none. let focus = std::mem::replace(self.focus_mut(), FocusPolicy::NONE); - self.props.mount = Mount::viewport_with(Overlay::full_window(focus), spec); + self.props.mount = Mount::viewport_with(Overlay::full_window(focus).min_size(OWN_WINDOW_MIN_SIZE), spec); self } diff --git a/crates/ui-canvas/src/lib.rs b/crates/ui-canvas/src/lib.rs index faeef0e77..639a1a938 100644 --- a/crates/ui-canvas/src/lib.rs +++ b/crates/ui-canvas/src/lib.rs @@ -31,7 +31,9 @@ pub mod canvas_controls; /// Dialog shells and prompts, with the full-window dialog family that shows a canvas. pub mod dialog { - pub use crate::canvas::full_window::{FullWindowDialog, FullWindowDialogStyle, FullWindowWorkspace, HostedWorkspace, WorkspaceCx, WorkspacePass}; + pub use crate::canvas::full_window::{ + FullWindowDialog, FullWindowDialogStyle, FullWindowWorkspace, HostedWorkspace, OWN_WINDOW_MIN_SIZE, WorkspaceCx, WorkspacePass, + }; pub use crate::canvas::full_window_parts::{ FullWindowCanvas, FullWindowCanvasOutput, FullWindowSide, FullWindowSideOutput, FullWindowSideStyle, FullWindowStatus, FullWindowStatusOutput, FullWindowTitle, FullWindowTitleOutput, FullWindowView, FullWindowZoomBar, FullWindowZoomBarOutput, RasterOverlay, diff --git a/crates/ui-contract/src/contract/body/presses.rs b/crates/ui-contract/src/contract/body/presses.rs index 98efd5059..492406636 100644 --- a/crates/ui-contract/src/contract/body/presses.rs +++ b/crates/ui-contract/src/contract/body/presses.rs @@ -40,9 +40,9 @@ impl BodyCx<'_> { } /// Whether the primary press of this pass went down on the container's own surface, for a root that senses - /// `Sense::SURFACE`: inside its rect, on its layer, where none of its children or parts takes the press. The - /// container decides what it means (a dock group focuses its panel, as Photoshop does); it is no click and moves - /// no focus by itself. + /// `Sense::SURFACE`: inside its rect, on its layer, where none of its children or parts and no app's own egui widget + /// in its body takes the press. The container decides what it means (a dock group focuses its panel, as Photoshop + /// does); it is no click and moves no focus by itself. pub fn surface_pressed(&self) -> bool { self.memory.recall::(sub(self.id, "surface_press")).pressed } @@ -76,8 +76,8 @@ impl BodyCx<'_> { impl BodyHooks<'_> { /// Records for the container's hooks whether this pass's primary press went down on its own surface /// (`BodyCx::surface_pressed`): no shape of last pass under the press takes it, nor a component's text widget - /// egui gives it to (a focused field's), and the press lies in the - /// container's rect on its layer; and whether that press is the second of a double click + /// egui gives it to (a focused field's), nor an app's own egui widget (a raw text field or canvas in the body), and + /// the press lies in the container's rect on its layer; and whether that press is the second of a double click /// (`BodyCx::surface_double_pressed`), read from the same press's click count; and whether this pass's primary /// release ends a press that went down there (`BodyCx::surface_clicked`). The press origin waits in the press slot /// until the release; Escape and a blur clear it, and so does any pass with no button held. @@ -95,6 +95,7 @@ impl BodyHooks<'_> { inside(press.origin) && pointer::press_winner(&ctx, press.origin, pass.press_targets).is_none() && !pointer::text_takes_press(&ctx, pass.press_targets) + && !pass.press_targets.click.is_some_and(|widget| pointer::foreign_target(&ctx, widget)) }) } else { None diff --git a/crates/ui-contract/src/contract/body/window.rs b/crates/ui-contract/src/contract/body/window.rs index dc5e45c13..257398bea 100644 --- a/crates/ui-contract/src/contract/body/window.rs +++ b/crates/ui-contract/src/contract/body/window.rs @@ -273,6 +273,31 @@ fn edge_of(dx: i8, dy: i8) -> ResizeEdge { } } +/// The move band and the resize grips the body step declared for a container this pass, for a host that names them +/// (an automation interface that drives a window by its grips). Each comes with the id of its accessibility node, the +/// id [`focused_node`](crate::runtime::access::focused_node) reports while it holds focus. +impl Cx<'_, C> { + /// The band the container is moved by, `None` when it has none this pass (no header, not movable). + pub fn move_band(&self) -> Option<(Rect, Id)> { + let band = self.core.results.get(&(MOVE_BAND, None))?; + Some((band.rect, crate::runtime::access::sub_node_id(self.core.id, MOVE_BAND.into()))) + } + + /// The edge and corner grips the container is resized by, each with the edge or corner it moves; none when it does + /// not resize this pass (minimized, maximized, or a window the platform resizes from its own frame). + pub fn resize_grips(&self) -> Vec<(ResizeEdge, Rect, Id)> { + GRIPS + .into_iter() + .enumerate() + .filter_map(|(index, (dx, dy, _))| { + let part = GRIP.at(index as u64); + let grip = self.core.results.get(&(GRIP, Some(index as u64)))?; + Some((edge_of(dx, dy), grip.rect, crate::runtime::access::sub_node_id(self.core.id, part))) + }) + .collect() + } +} + /// The arrow chords, with and without Shift, a window mode holds, with the direction each moves. const MODE_ARROWS: [(Key, [i8; 2]); 4] = [(Key::Left, [-1, 0]), (Key::Right, [1, 0]), (Key::Up, [0, -1]), (Key::Down, [0, 1])]; @@ -814,6 +839,7 @@ impl BodyHooks<'_> { let top = top_band(props, &ctx, pcx.id, pcx.tokens); let pinned = overlay_of(props).map_or(Pinned::NONE, |overlay| Pinned::of(overlay, &ctx, pcx.id, pcx.env.direction().is_rtl())); let caller_sizes = overlay_of(props).is_some_and(|overlay| overlay.resize.by_caller); + let grip_name = props.resize_name.as_ref().map(|name| pcx.env.resolve(name).as_str().to_owned()); for (index, (dx, dy, cursor)) in GRIPS.into_iter().enumerate() { if held != Some(index) && !grip_stands(edges, pinned, dx, dy) { continue; @@ -837,6 +863,10 @@ impl BodyHooks<'_> { .pointer_only(reason) .exact_hit() .over(); + let part = match &grip_name { + Some(name) => part.node(crate::runtime::access::Role::SPLITTER, name.as_str()), + None => part, + }; // The grips of a window its caller sizes are the app's (`window_resize`), never the platform's. if let Some(hit) = exclusive(WindowHit::Resize(edge_of(dx, dy))).filter(|_| !caller_sizes) { part.exclusive(hit); diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 502851b41..39148cc4f 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -812,6 +812,8 @@ pub struct ContainerProps { /// The help line the footer shows under the control column of a label-scoped container; its text joins the /// control's description. pub help: Option