From 0228bb25699819afd443cc32aacd44d2ee8ca810 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 23:00:58 -0500 Subject: [PATCH] fw-canvas: resolve the origin/next sync conflicts (canvas autoscroll, wheel schemes, rulers, editor part, crop scope, task bar kinds, transform box handles; trials and stories) --- crates/draw/src/ui/transform/transform_box.rs | 100 ++--- .../src/ui/transform/transform_box/stories.rs | 36 +- crates/draw/tests/it/transform_box.rs | 18 +- crates/ui-canvas/src/canvas/crop/gesture.rs | 13 +- crates/ui-canvas/src/canvas/crop/mod.rs | 36 +- crates/ui-canvas/src/canvas/crop/stories.rs | 14 +- crates/ui-canvas/src/canvas/mod.rs | 365 ++++-------------- crates/ui-canvas/src/canvas/navigate/mod.rs | 4 - .../ui-canvas/src/canvas/navigate/options.rs | 37 +- .../ui-canvas/src/canvas/navigator/preview.rs | 6 +- crates/ui-canvas/src/canvas/space.rs | 14 +- crates/ui-canvas/src/canvas/split/stories.rs | 70 +--- crates/ui-canvas/src/canvas/tool_host.rs | 6 +- crates/ui-canvas/src/canvas/zoom_motion.rs | 11 +- crates/ui-canvas/src/canvas_controls/mod.rs | 4 - .../ui-canvas/src/canvas_controls/task_bar.rs | 179 +++------ .../src/canvas_controls/task_bar/stories.rs | 6 +- crates/ui-canvas/tests/it/canvas/crop.rs | 6 +- crates/ui-canvas/tests/it/canvas/mod.rs | 8 +- crates/ui-canvas/tests/it/canvas/navigate.rs | 16 +- crates/ui-canvas/tests/it/canvas/split.rs | 5 - .../tests/it/canvas_controls/task_bar.rs | 33 +- 22 files changed, 244 insertions(+), 743 deletions(-) diff --git a/crates/draw/src/ui/transform/transform_box.rs b/crates/draw/src/ui/transform/transform_box.rs index 0f27ee4c95..d0a2da2d4b 100644 --- a/crates/draw/src/ui/transform/transform_box.rs +++ b/crates/draw/src/ui/transform/transform_box.rs @@ -145,13 +145,9 @@ impl RotateZone { fn rotates_at(self, quad: &[Point; 4], pointer: Pos2) -> bool { match self { RotateZone::Border { points } => border_distance(quad, pointer) <= points, -<<<<<<< HEAD RotateZone::Outside | RotateZone::Band | RotateZone::Knob => true, -======= - RotateZone::Outside | RotateZone::Band => true, // The handle is the zone's only outside part, so a press that reaches the outside is on it. RotateZone::Handle => true, ->>>>>>> origin/next } } } @@ -380,8 +376,6 @@ struct Grip { follows: bool, /// An Alt press away from the handles: a click there moves the reference point. moves_pivot: bool, - /// The press is on the rotate knob: a click there is not a click outside, so it applies nothing. - knob: bool, /// The box at the press. pressed: BoxState, /// The box the drag last produced. @@ -391,17 +385,7 @@ struct Grip { impl Default for Grip { fn default() -> Self { let none = BoxState::from_rect(DocRect::ZERO); - Grip { - part: BoxPart::Inside, - start: none, - from: Point::ZERO, - began: false, - follows: false, - moves_pivot: false, - knob: false, - pressed: none, - last: none, - } + Grip { part: BoxPart::Inside, start: none, from: Point::ZERO, began: false, follows: false, moves_pivot: false, pressed: none, last: none } } } @@ -694,15 +678,13 @@ impl<'a> TransformBox<'a> { let turn = || Cursor::from(PaintedCursor::turn(quad::bisector(screen, corner))); let along = |from: usize| vec2_of(screen.quad[(from + 1) % 4] - screen.quad[from % 4]); match (kind, part) { -<<<<<<< HEAD // The knob is a handle the pointer takes hold of and swings, not a stretch of the outside. (BoxDrag::Rotate, BoxPart::Outside) if self.rotate_zone == RotateZone::Knob => { if dragging { CursorIcon::Grabbing } else { CursorIcon::Grab }.into() -======= + } // The rotate handle turns the cursor with the box: it points in across the side the handle stands on. (BoxDrag::Rotate, BoxPart::Outside) if self.rotate_zone == RotateZone::Handle => { Cursor::from(PaintedCursor::turn(-outward_normals(&screen.quad.map(pos))[0])) ->>>>>>> origin/next } (BoxDrag::Rotate, BoxPart::Outside) if !dragging && !self.rotate_zone.rotates_at(&screen.quad, pointer) => CursorIcon::Default.into(), (BoxDrag::Rotate, BoxPart::Outside) => { @@ -772,13 +754,8 @@ impl<'a> TransformBox<'a> { } /// The parts that take a press, with the box part each stands for. Mirrors what [`parts`](Component::parts) -<<<<<<< HEAD - /// declares: the keyboard parts, a segment per allowed edge, the centre where declared, and the outside (the knob in - /// [`RotateZone::Knob`]); or only the move strips. -======= - /// declares: the keyboard parts, a segment per allowed edge, the centre where declared, and the outside or the - /// rotate handle; or only the move strips. ->>>>>>> origin/next + /// declares: the keyboard parts, a segment per allowed edge, the centre where declared, and the outside, the knob in + /// [`RotateZone::Knob`] or the rotate handle; or only the move strips. fn pointer_parts(&self) -> Vec<(PartRef, BoxPart)> { if self.move_only().is_some() { let parts = if self.ring_reach().is_some() { 0..8 } else { 0..0 }; @@ -797,18 +774,14 @@ impl<'a> TransformBox<'a> { if self.declares_centre() { parts.push((CENTRE.at(0), BoxPart::Inside)); } -<<<<<<< HEAD if matches!(self.rotate_zone, RotateZone::Knob) { if self.has_knob() { parts.push((KNOB.at(0), BoxPart::Outside)); } - } else if self.rules.allows(BoxPart::Outside) { + } else { parts.extend((0..4).map(|corner| (OUTSIDE.at(corner), BoxPart::Outside))); + parts.push((ROTATE_HANDLE.at(0), BoxPart::Outside)); } -======= - parts.extend((0..4).map(|corner| (OUTSIDE.at(corner), BoxPart::Outside))); - parts.push((ROTATE_HANDLE.at(0), BoxPart::Outside)); ->>>>>>> origin/next parts } @@ -836,20 +809,14 @@ impl<'a> TransformBox<'a> { PressPhase::Down { start, .. } if part == BoxPart::Outside && !self.rotate_zone.rotates_at(&screen.quad, start.origin) => {} PressPhase::Down { start, .. } if start.button == PointerButton::Primary => { let from = space.view.to_doc(start.origin); -<<<<<<< HEAD + // The move reach only moves: an Alt press there is a move too. The knob and the rotate handle are + // handles, so an Alt press on one turns the box rather than moving the reference point onto it. let knob = reference.key == KNOB; - // The move reach only moves: an Alt press there is a move too. The knob is a handle, so an Alt - // press on it turns the box rather than moving the reference point onto it. - let moves_pivot = mods.alt && self.move_only().is_none() && !knob && matches!(part, BoxPart::Inside | BoxPart::Outside); -======= - // The move reach only moves: an Alt press there is a move too. The rotate handle is a handle, so - // an Alt press on it rotates. - let away_from_handles = part == BoxPart::Inside || (part == BoxPart::Outside && self.rotate_zone != RotateZone::Handle); + let away_from_handles = part == BoxPart::Inside || (part == BoxPart::Outside && self.rotate_zone != RotateZone::Handle && !knob); let moves_pivot = acting.alt && self.move_only().is_none() && away_from_handles; ->>>>>>> origin/next let follows = follows_in_slop(part); let (part, begin) = if moves_pivot { (BoxPart::Pivot, BoxState::new(shown.quad, from)) } else { (part, *shown) }; - held = Some(Grip { part, start: begin, from, began: false, follows, moves_pivot, knob, pressed: *shown, last: *shown }); + held = Some(Grip { part, start: begin, from, began: false, follows, moves_pivot, pressed: *shown, last: *shown }); } // Inside the slop a part that follows there moves the box from the first move; the outside starts at // the drag. @@ -899,11 +866,7 @@ impl<'a> TransformBox<'a> { cx.cancel(CancelReason::Unchanged); } else if grip.began { cx.commit(); -<<<<<<< HEAD - } else if grip.part == BoxPart::Outside && !grip.knob && click && start.clicks <= 1 { -======= } else if grip.part == BoxPart::Outside && reference.key == OUTSIDE && click && start.clicks <= 1 { ->>>>>>> origin/next self.report.apply = Some(ApplyBy::ClickOutside { at: space.view.to_doc(start.origin) }); } else if grip.moves_pivot && click { cx.set(grip.start); @@ -1025,7 +988,11 @@ impl<'a> TransformBox<'a> { impl TransformBox<'_> { /// The shape of a handle of `side` at `at`: a square, or a circle of that diameter with round handles. fn handle_shape(&self, at: Pos2, side: f32) -> PaintShape { - if self.round_handles { PaintShape::Circle(at, side / 2.0) } else { PaintShape::Rect(Rect::from_center_size(at, Vec2::splat(side)), CornerRadius::ZERO) } + if self.round_handles { + PaintShape::Circle(at, side / 2.0) + } else { + PaintShape::Rect(Rect::from_center_size(at, Vec2::splat(side)), CornerRadius::ZERO) + } } /// The square of handle `part` at `at` on the screen, filled as the part's state shows when the rules let it take a @@ -1033,14 +1000,7 @@ impl TransformBox<'_> { fn paint_handle(&self, draw: &Draw<'_>, cx: &Cx<'_, Self>, part: BoxPart, at: Pos2, enlarged: bool) { let look = &cx.style.handle; let side = if enlarged { look.side * OVERFLOW_IN_HANDLES } else { look.side }; -<<<<<<< HEAD - let square = self.handle_shape(at, side); - let fill = if self.rules.allows(part) { cx.resolve_part(BOX.at(part.index()), &look.fill) } else { cx.resolve(&look.fill) }; - draw.fill(&square, fill); - draw.stroke(&square, StrokeWidth::Thin, look.stroke); -======= - paint_square(draw, cx, at, side, self.rules.allows(part).then(|| BOX.at(part.index()))); ->>>>>>> origin/next + paint_handle_shape(draw, cx, self.handle_shape(at, side), self.rules.allows(part).then(|| BOX.at(part.index()))); if enlarged { Handle::plus(draw, look, at, side); } @@ -1054,30 +1014,23 @@ impl TransformBox<'_> { let corners = outline.map(|corner| view.to_screen(corner)); paint_frame(draw, style, corners); for k in 0..4 { -<<<<<<< HEAD let middle = corners[k].lerp(corners[(k + 1) % 4], 0.5); - let square = self.handle_shape(middle, look.side); - draw.fill(&square, cx.resolve(&look.fill)); - draw.stroke(&square, StrokeWidth::Thin, look.stroke); -======= - paint_square(draw, cx, corners[k].lerp(corners[(k + 1) % 4], 0.5), style.handle.side, None); ->>>>>>> origin/next + paint_handle_shape(draw, cx, self.handle_shape(middle, style.handle.side), None); } } for (part, end) in line.end_parts() { self.paint_handle(draw, cx, part, view.to_screen(end), false); } for (end, at) in line.free_ends() { - paint_square(draw, cx, view.to_screen(at), style.handle.side, Some(LINE_END.at(end.index()))); + paint_handle_shape(draw, cx, self.handle_shape(view.to_screen(at), style.handle.side), Some(LINE_END.at(end.index()))); } paint_widget(draw, view.to_screen(line.from.midpoint(line.to)), &style.widget); } } -/// A handle square of `side` centred on `at`, filled as the state of `part` shows, or at rest without one. -fn paint_square(draw: &Draw<'_>, cx: &Cx<'_, TransformBox<'_>>, at: Pos2, side: f32, part: Option) { +/// A handle's `square` (a circle with round handles), filled as the state of `part` shows, or at rest without one. +fn paint_handle_shape(draw: &Draw<'_>, cx: &Cx<'_, TransformBox<'_>>, square: PaintShape, part: Option) { let look = &cx.style.handle; - let square = PaintShape::Rect(Rect::from_center_size(at, Vec2::splat(side)), CornerRadius::ZERO); let fill = match part { Some(part) => cx.resolve_part(part, &look.fill), None => cx.resolve(&look.fill), @@ -1357,7 +1310,6 @@ impl Component for TransformBox<'_> { .pointer_only(ROTATE_BY_KEY); } } -<<<<<<< HEAD RotateZone::Outside | RotateZone::Border { .. } | RotateZone::Band => {} // The knob alone turns the box; the rest of the outside is the tool's. RotateZone::Knob => { @@ -1369,8 +1321,6 @@ impl Component for TransformBox<'_> { .pointer_only(ROTATE_BY_KEY); } } -======= - RotateZone::Band => {} RotateZone::Handle if self.rules.allows(BoxPart::Outside) => { let (_, knob) = rotate_handle(&quad, style.rotate_stem); cx.part(ROTATE_HANDLE.at(0), HitShape::circle(knob, style.handle_reach)) @@ -1379,7 +1329,6 @@ impl Component for TransformBox<'_> { .pointer_only(ROTATE_BY_KEY); } RotateZone::Handle => {} ->>>>>>> origin/next } } @@ -1462,13 +1411,8 @@ impl Component for TransformBox<'_> { } fn finish(self, cx: Cx<'_, Self>) -> TransformBoxOutput { -<<<<<<< HEAD - let Report { apply, clicked, discard, hovered, picked, held, snapped } = self.report; - TransformBoxOutput { edit: cx.edit_response(), apply, discard, picked, hovered, held, snapped, clicked } -======= - let Report { apply, discard, hovered, picked, held, snapped, line_end } = self.report; - TransformBoxOutput { edit: cx.edit_response(), apply, discard, picked, hovered, held, snapped, line_end } ->>>>>>> origin/next + let Report { apply, clicked, discard, hovered, picked, held, snapped, line_end } = self.report; + TransformBoxOutput { edit: cx.edit_response(), apply, discard, picked, hovered, held, snapped, clicked, line_end } } } diff --git a/crates/draw/src/ui/transform/transform_box/stories.rs b/crates/draw/src/ui/transform/transform_box/stories.rs index d11f03b95b..19cbd3b31c 100644 --- a/crates/draw/src/ui/transform/transform_box/stories.rs +++ b/crates/draw/src/ui/transform/transform_box/stories.rs @@ -1,19 +1,11 @@ //! Stories of the transform box: Free Transform with its reference point, the Move tool's controls, Distort, the -<<<<<<< HEAD -//! Ellipse tool's centre mark, the Line tool's live-line controls, the corner-only and side-only handle sets, sides -//! grabbed along an edge band, and the rotate knob. +//! Ellipse tool's centre mark, the rotate handle and the Line tool's live-line controls, with box or free ends, the +//! corner-only and side-only handle sets, sides grabbed along an edge band, and the rotate knob. -use super::{BOX, EDGE, LineLook, RotateZone, TransformBox}; +use super::{BOX, EDGE, LINE_END, LineEnd, LineEnds, LineLook, ROTATE_HANDLE, RotateZone, TransformBox, TransformBoxOutput}; +use craft_behavior::GesturePhase; use craft_behavior::geometry::quad::{BoxHandles, BoxPart, BoxRules, BoxState, ScaleRule, TransformMode}; use craft_behavior::kurbo::{Point, Rect as DocRect, Vec2 as DocVec}; -======= -//! Ellipse tool's centre mark, the rotate handle and the Line tool's live-line controls, with box or free ends. - -use super::{BOX, LINE_END, LineEnd, LineEnds, LineLook, ROTATE_HANDLE, RotateZone, TransformBox, TransformBoxOutput}; -use craft_behavior::GesturePhase; -use craft_behavior::geometry::quad::{BoxPart, BoxRules, BoxState, TransformMode}; -use craft_behavior::kurbo::{Point, Rect as DocRect}; ->>>>>>> origin/next use craft_ui::canvas::Canvas; use craft_ui::contract::{Bind, Show as _, ShowContainer as _}; use craft_ui::testing::canvas_story::{OUTLINE, StoryDocument, StoryPicture, StoryShape, paint_shapes, show_document, show_quad}; @@ -37,22 +29,23 @@ fn free_box(state: Bind<'_, BoxState>) -> TransformBox<'_> { /// Shows the box `make` builds over the story's box as the only canvas control of a canvas. fn on_canvas(ui: &mut Ui, data: &mut StoryData, make: impl for<'a> Fn(Bind<'a, BoxState>) -> TransformBox<'a>) -> StoryOutput { -<<<<<<< HEAD show_on_canvas(ui, data, false, make) } /// [`on_canvas`], the view centred on the picture; `at_top` scrolls it so the picture's top side lies on the /// canvas's top edge. fn show_on_canvas(ui: &mut Ui, data: &mut StoryData, at_top: bool, make: impl for<'a> Fn(Bind<'a, BoxState>) -> TransformBox<'a>) -> StoryOutput { - let state = data.value("box", BoxState::from_rect(PICTURE)); -======= - shown_on_canvas(ui, data, make).map(|output| StoryOutput::from(output.edit)).unwrap_or_default() + shown_on_canvas(ui, data, at_top, make).map(|output| StoryOutput::from(output.edit)).unwrap_or_default() } -/// [`on_canvas`] with the box's whole output. -fn shown_on_canvas(ui: &mut Ui, data: &mut StoryData, make: impl for<'a> Fn(Bind<'a, BoxState>) -> TransformBox<'a>) -> Option { +/// [`show_on_canvas`] with the box's whole output. +fn shown_on_canvas( + ui: &mut Ui, + data: &mut StoryData, + at_top: bool, + make: impl for<'a> Fn(Bind<'a, BoxState>) -> TransformBox<'a>, +) -> Option { let (state, state_at) = data.value_at("box", BoxState::from_rect(PICTURE)); ->>>>>>> origin/next let room = craft_ui::testing::stage(ui); let ppp = ui.pixels_per_point(); let mut view = craft_ui::testing::canvas_story::story_view(room, ppp, PICTURE.center(), 100.0); @@ -163,8 +156,9 @@ fn line_free_ends(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let quad = BoxState::from_rect(PICTURE).quad; let ends = *data.value("ends", [quad[3], quad[1]]); let line = LineLook::new(ends[0], ends[1]).ends(LineEnds::Free); - let shown = - shown_on_canvas(ui, data, move |state| free_box(state).rotate_zone(RotateZone::Band).inside_moves(false).reference_point(false).line(line)); + let shown = shown_on_canvas(ui, data, false, move |state| { + free_box(state).rotate_zone(RotateZone::Band).inside_moves(false).reference_point(false).line(line) + }); let Some(output) = shown else { return StoryOutput::default() }; if let Some(drag) = output.line_end { let index = usize::from(drag.end == LineEnd::To); diff --git a/crates/draw/tests/it/transform_box.rs b/crates/draw/tests/it/transform_box.rs index dbe74bbcfc..17d4aae554 100644 --- a/crates/draw/tests/it/transform_box.rs +++ b/crates/draw/tests/it/transform_box.rs @@ -1,17 +1,10 @@ //! `TransformBox`, `TransformOverlay` and `TransformTool`: the parts the pointer takes, what each drag does, the //! keys, the readout and the overlay's edits. -<<<<<<< HEAD use craft_behavior::geometry::quad::{BoxAllow, BoxHandles, BoxPart, BoxRules, BoxState, ScaleRule, TransformMode}; -use craft_behavior::geometry::{SnapKind, SnapOptions, SnapTarget, SnapTargets}; -use craft_behavior::kurbo::{Point, Rect}; -use craft_behavior::{CanvasView, EditEvent, RulerUnits, Ticks}; -======= -use craft_behavior::geometry::quad::{BoxAllow, BoxPart, BoxRules, BoxState, ScaleRule, TransformMode}; use craft_behavior::geometry::{SnapKind, SnapOptions, SnapSuspend, SnapTarget, SnapTargets}; use craft_behavior::kurbo::{Affine, Point, Rect}; use craft_behavior::{CanvasView, EditEvent, GesturePhase, RulerUnits, Ticks}; ->>>>>>> origin/next use craft_draw::ui::transform::{ LineEnd, LineEndDrag, LineEnds, LineLook, RotateZone, TransformBox, TransformEdit, TransformOverlay, TransformReach, TransformSession, TransformSettings, @@ -220,14 +213,10 @@ fn harness(state: BoxState, setup: impl FnOnce(&mut Config)) -> Harness { } Some((control.show_at(ui, body.rect), guide_edits)) }); -<<<<<<< HEAD - if let Some(Some((output, guide_edits))) = canvas.inner { -======= if config.twice && ui.ctx().current_pass_index() == 0 { ui.ctx().request_discard("the frame runs twice"); } - if let Some((output, guide_edits)) = canvas.inner { ->>>>>>> origin/next + if let Some(Some((output, guide_edits))) = canvas.inner { let mut host = shown_host.borrow_mut(); host.shown = output.edit.shown.as_ref().and_then(|value| value.same()).map(|value| **value); host.guide_events += guide_edits; @@ -535,7 +524,6 @@ fn a_text_frame_fed_back_through_an_f32_host_follows_every_move_to_the_commit() assert!((h.state().quad[2].y - 280.0).abs() < 0.01 && events.last() == Some(&Seen::Commit), "the commit holds the last move"); } -<<<<<<< HEAD /// A hover-revealed frame remains declared through release after its drag leaves the original box. #[trial] fn a_hover_frame_commits_a_drag_released_outside() { @@ -568,7 +556,8 @@ fn transform_box_shows_each_drag_proposal_in_the_same_frame() { assert_eq!(host.shown, Some(host.state), "the reported preview follows this frame's edit"); previous = host.state; } -======= +} + /// A frame egui runs twice reports each move of a drag once: its second pass proposes the box the first did, and an /// equal proposal reports no `Update` again, so a host that applies each `Update` (a text layer's box) applies it once /// per move. @@ -588,7 +577,6 @@ fn a_frame_run_twice_reports_each_move_of_a_drag_once() { let updates = events.iter().filter(|seen| **seen == Seen::Update).count(); assert_eq!(updates, 2, "two moves report two updates, a held frame none: {events:?}"); assert!((h.state().quad[2].y - 280.0).abs() < 0.01, "the last move reached the host"); ->>>>>>> origin/next } #[trial] diff --git a/crates/ui-canvas/src/canvas/crop/gesture.rs b/crates/ui-canvas/src/canvas/crop/gesture.rs index 235abcf23b..10dcdca10d 100644 --- a/crates/ui-canvas/src/canvas/crop/gesture.rs +++ b/crates/ui-canvas/src/canvas/crop/gesture.rs @@ -70,16 +70,13 @@ pub(super) struct Rules { pub image: bool, pub auto_center: bool, pub fills_uncovered: bool, -<<<<<<< HEAD /// The smallest side a resize may leave, in document units: a step that would go under it keeps the last frame. pub min_side: f64, /// The quad the frame is bounded to: a step that would leave the frame outside it keeps the last frame. pub area: Option<[Point; 4]>, -======= /// An edge or corner drag, and a move, may take the frame past `bounds`, turned or not: the crop grows the canvas /// there, as in the reference application (a document crop, not one bounded by a placed picture's source). pub resize_grows: bool, ->>>>>>> origin/next /// The canvas's snapping, with this pass's tolerance. pub snap: Option, pub os: Platform, @@ -131,15 +128,12 @@ impl Rules { } else { at.resized(*part, by, hold, mods.alt) }; -<<<<<<< HEAD // A step that would leave a side under the minimum keeps the last frame, as a step the bounds refuse // does: the resize stops there instead of crossing it. if !next.size_ok(self.min_side) { return Some(drag.last); } -======= grows = self.resize_grows; ->>>>>>> origin/next (next, true, self.ratio.is_some() || mods.shift) } Kind::Turn { grab } => { @@ -162,13 +156,8 @@ impl Rules { if !next.is_finite() { return None; } -<<<<<<< HEAD - let kept = match self.bounds { + let kept = match self.bounds.filter(|_| !grows) { Some(bounds) => next.within(bounds, resizing, held), -======= - match self.bounds.filter(|_| !grows) { - Some(bounds) => next.within(bounds, resizing, held).or(Some(drag.last)), ->>>>>>> origin/next None => Some(next), }; kept.filter(|kept| self.area.is_none_or(|area| inside_quad(kept, &area))).or(Some(drag.last)) diff --git a/crates/ui-canvas/src/canvas/crop/mod.rs b/crates/ui-canvas/src/canvas/crop/mod.rs index cd61b9b644..46e739c0a0 100644 --- a/crates/ui-canvas/src/canvas/crop/mod.rs +++ b/crates/ui-canvas/src/canvas/crop/mod.rs @@ -185,7 +185,6 @@ pub struct CropOverlay<'a> { /// Nothing is painted and a press anywhere on the canvas draws a new frame. #[prop(flag)] hidden: bool, -<<<<<<< HEAD /// What a press outside the frame does: turns it, applies the crop, or draws a new frame. #[prop] outside: CropOutside, @@ -198,6 +197,9 @@ pub struct CropOverlay<'a> { /// unit (`MIN_FRAME`) always applies. #[prop(quantity = "document units")] min_side: f64, + /// What the crop is bounded by: the document, or one placed picture's source. + #[prop] + scope: CropScope, report: Report, } @@ -212,11 +214,6 @@ pub enum CropOutside { Apply, /// The press draws a new frame. NewFrame, -======= - /// What the crop is bounded by: the document, or one placed picture's source. - #[prop] - scope: CropScope, - report: Report, } /// What a crop is of. @@ -239,7 +236,6 @@ impl CropScope { pub const fn object(source: DocRect) -> Self { CropScope::Object { source } } ->>>>>>> origin/next } impl<'a> CropOverlay<'a> { @@ -260,13 +256,10 @@ impl<'a> CropOverlay<'a> { auto_center: false, fills_uncovered: false, hidden: false, -<<<<<<< HEAD outside: CropOutside::default(), area: None, min_side: MIN_SIDE, -======= scope: CropScope::default(), ->>>>>>> origin/next report: Report::default(), } .label(label) @@ -281,12 +274,9 @@ impl<'a> CropOverlay<'a> { image: self.image_mode, auto_center: self.auto_center, fills_uncovered: self.fills_uncovered, -<<<<<<< HEAD min_side: self.min_side, area: self.area, -======= resize_grows: matches!(self.scope, CropScope::Document), ->>>>>>> origin/next snap: canvas_snap(env), os: env.shell().os, } @@ -705,14 +695,16 @@ impl Component for CropOverlay<'_> { } let _ = declared; } -<<<<<<< HEAD let outside = HitPriority::new(HitLevel::Background, u8::MAX); match self.outside { + // Outside a picture's frame there is no turn part, so a press there reaches the picture beneath. CropOutside::Turn => { - cx.part(TURN, HitShape::Rect(rect)) - .sense(Sense::DRAG | Sense::CONTEXT_CLICK) - .priority(outside) - .pointer_only("the options bar's angle field sets the frame's angle"); + if self.turns() { + cx.part(TURN, HitShape::Rect(rect)) + .sense(Sense::DRAG | Sense::CONTEXT_CLICK) + .priority(outside) + .pointer_only("the options bar's angle field sets the frame's angle"); + } } CropOutside::Apply => { cx.part(OUTSIDE, HitShape::Rect(rect)) @@ -735,14 +727,6 @@ impl Component for CropOverlay<'_> { .cursor(CursorIcon::Crosshair) .pointer_only("the options bar's size fields set the frame"); } -======= - // Outside a picture's frame there is no turn part, so a press there reaches the picture beneath. - if self.turns() { - cx.part(TURN, HitShape::Rect(rect)) - .sense(Sense::DRAG | Sense::CONTEXT_CLICK) - .priority(HitPriority::new(HitLevel::Background, u8::MAX)) - .pointer_only("the options bar's angle field sets the frame's angle"); ->>>>>>> origin/next } cx.roving(Roving::new(NavShape::Flat).page(Some(1))); } diff --git a/crates/ui-canvas/src/canvas/crop/stories.rs b/crates/ui-canvas/src/canvas/crop/stories.rs index 11093e3f4b..8fe6d51d34 100644 --- a/crates/ui-canvas/src/canvas/crop/stories.rs +++ b/crates/ui-canvas/src/canvas/crop/stories.rs @@ -1,10 +1,6 @@ //! Stories of the crop overlay. -<<<<<<< HEAD -use super::{CropOutside, CropOverlay, CropOverlayOutput, FRAME}; -======= -use super::{CropOverlay, CropOverlayOutput, CropScope, FRAME}; ->>>>>>> origin/next +use super::{CropOutside, CropOverlay, CropOverlayOutput, CropScope, FRAME}; use crate::canvas::RasterSource as _; use crate::canvas::testing::canvas_story::{self, StoryDocument, StoryPicture, StoryShape, paint_shapes}; use crate::contract::{Show as _, Validity}; @@ -159,19 +155,19 @@ fn untouched(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { /// frame; a click away from the picture applies, and a press between the frame and the outline does nothing. #[story(CropOverlay<'static>, covers = [Default])] fn placed_picture(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - let rect = data.value("crop", crop()); + let (rect, rect_at) = data.value_at("crop", crop()); let area = CropBox::new(DocRect::new(200.0, 110.0, 440.0, 290.0), PLACED_TURN).corners(); on_landscape(ui, 0.0, |ui, at| { - CropOverlay::new("Crop", Bind::bound(&mut *rect)).outside(CropOutside::Apply).area(area).min_side(PLACED_MIN_SIDE).show_at(ui, at) + CropOverlay::new("Crop", rect_at.bind(&mut *rect)).outside(CropOutside::Apply).area(area).min_side(PLACED_MIN_SIDE).show_at(ui, at) }) } /// A scanned photo's crop: no turn, and a press outside the frame draws a new frame inside the page. #[story(CropOverlay<'static>, covers = [Default])] fn scan_photo(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - let rect = data.value("crop", crop()); + let (rect, rect_at) = data.value_at("crop", crop()); on_landscape(ui, 0.0, |ui, at| { - CropOverlay::new("Crop", Bind::bound(&mut *rect)).outside(CropOutside::NewFrame).bounds(StoryDocument::STANDARD.rect()).show_at(ui, at) + CropOverlay::new("Crop", rect_at.bind(&mut *rect)).outside(CropOutside::NewFrame).bounds(StoryDocument::STANDARD.rect()).show_at(ui, at) }) } diff --git a/crates/ui-canvas/src/canvas/mod.rs b/crates/ui-canvas/src/canvas/mod.rs index cf9e6fcef0..e2af554354 100644 --- a/crates/ui-canvas/src/canvas/mod.rs +++ b/crates/ui-canvas/src/canvas/mod.rs @@ -8,12 +8,7 @@ //! ([`ViewCommands`]), keeps the document in view with Overscroll off, eases a zoom under Animated Zoom, publishes the //! view it shows as a [`CanvasSpace`] to its body, and reports the view the app copies. -<<<<<<< HEAD -mod crop; -======= pub(crate) mod crop; -mod frame_step; ->>>>>>> origin/next // The full-window dialog family; `dialog` re-exports it. pub(crate) mod full_window; pub(crate) mod full_window_parts; @@ -31,19 +26,11 @@ mod tool_groups; mod tool_host; pub use crate::canvas_data::{Guide, GuideColor, GuideDrag, GuideKey, GuideLine, NavigatorOptions, NavigatorSettings, ProxyColor}; -<<<<<<< HEAD pub use craft_behavior::{FRAME_STEP_MAX, frame_step}; -pub use crop::{CropApply, CropOutside, CropOverlay, CropOverlayOutput, CropShield, CropStyle, ShieldColor, paint_outside}; +pub use crop::{CropApply, CropOutside, CropOverlay, CropOverlayOutput, CropScope, CropShield, CropStyle, ShieldColor, paint_outside}; pub(crate) use march::{MARCH_SECONDS, MARCH_TICK, march_shift}; pub use readout::{ShowReadouts, hud, readout}; -pub use space::{CanvasSpace, RulerText, canvas_space, pixel_aligned, with_canvas_space}; -======= -pub use crop::{CropOverlay, CropOverlayOutput, CropScope, CropShield, CropStyle, ShieldColor, paint_outside}; -pub use frame_step::{FRAME_STEP_MAX, frame_step}; -pub(crate) use march::{MARCH_SECONDS, MARCH_TICK, march_shift}; -pub use readout::{ShowReadouts, hud, readout}; -pub use space::{CanvasSpace, RulerText, canvas_space, pixel_aligned, ruler_guide}; ->>>>>>> origin/next +pub use space::{CanvasSpace, RulerText, canvas_space, pixel_aligned, ruler_guide, with_canvas_space}; pub use words::CanvasWords; #[doc(hidden)] @@ -85,12 +72,8 @@ mod zoom_motion; pub use momentary::{Momentary, MomentaryCommands, MomentaryTool}; pub use navigate::{ -<<<<<<< HEAD - Autoscroll, FlickPan, NavigateBar, NavigateBarOutput, NavigationOptions, PageKey, WheelAction, WheelInput, WheelNavigation, WheelScheme, pan, -======= - Autoscroll, FlickPan, MiddleButton, NavigateBar, NavigateBarOutput, NavigationOptions, PageKey, TouchpadGlide, WheelAction, WheelInput, - WheelNavigation, WheelScheme, pan, ->>>>>>> origin/next + Autoscroll, FlickPan, MiddleButton, NavigateBar, NavigateBarOutput, NavigationOptions, PageKey, WheelAction, WheelInput, WheelNavigation, + WheelScheme, pan, }; pub use rotate::{RotateView, RotateViewOutput, RotateViewStyle, ViewTurn}; pub use tools::{HandTool, LayerBounds, RotateViewTool, ViewCommands, ViewRequest, ViewTarget, ZoomTool}; @@ -124,38 +107,21 @@ use crate::contract::{ use crate::primitives::{EditorPurpose, ImeStamp}; use crate::runtime::commands::{CommandSet as _, CommandState, Commands as _}; use crate::runtime::env::Label; -<<<<<<< HEAD -use crate::runtime::focus::{KeyUse, NudgeMods}; +use crate::runtime::focus::{EditSet, KeyUse, NudgeMods}; use crate::runtime::frame; use crate::runtime::lock_keys; use crate::runtime::measure; use crate::runtime::motion::{Animate as _, spec}; -use crate::style::AutoScrollMarkLook; -use crate::style::{ComponentStyle, Stateful, StyleCx, SurfaceKind, SurfaceLook}; -use craft_behavior::geometry::crop::normalized_angle; -use craft_behavior::kurbo::{Point, Rect as DocRect, Size}; -use craft_behavior::{ - CanvasTransform, CanvasView, CursorIcon, CursorPriority, EditEvent, HitLevel, HitPriority, HitShape, Intent, Metrics, MiddleButton, Mixed, - PartKey, PointerButton, PressPhase, PressState, Sense, Wheel, WheelNotch, WheelUnit, -}; -use craft_keymap::{Chord, Key}; -use egui::{Pos2, Rect, Response, Vec2}; -======= -use crate::runtime::focus::{EditSet, KeyUse}; -use crate::runtime::lock_keys; -use crate::runtime::measure; -use crate::runtime::motion::{Animate as _, spec}; use crate::style::{ComponentStyle, Stateful, StyleColor, StyleCx, SurfaceKind, SurfaceLook}; use craft_behavior::geometry::crop::normalized_angle; use craft_behavior::kurbo::{Point, Rect as DocRect, Size}; use craft_behavior::{ - CanvasTransform, CanvasView, CursorPriority, EditEvent, EditorInput, HitLevel, HitPriority, HitShape, Input, Intent, Metrics, Mixed, PartKey, - PointerButton, PressPhase, PressState, Sense, WheelNotch, + CanvasTransform, CanvasView, CursorIcon, CursorPriority, EditEvent, EditorInput, HitLevel, HitPriority, HitShape, Input, Intent, Metrics, Mixed, + PartKey, PointerButton, PressPhase, PressState, Sense, Wheel, WheelNotch, WheelUnit, }; use egui::{Context, Pos2, Rect, Response, Vec2}; use navigate::MiddleAutoscroll; use std::sync::Arc; ->>>>>>> origin/next use zoom_motion::{Steer, ViewMotion}; pub(crate) const BACKGROUND: PartKey = PartKey::new("background"); @@ -173,10 +139,6 @@ const TOOL_REGION: PartKey = PartKey::new("toolRegion"); /// ([`CanvasTool::command_form`]), the one owner of that fact. const TOOL_PATH: &str = "the running tool's command form"; -/// The key that ends a latched middle scroll. The canvas claims it only while a latch runs, so otherwise Escape reaches -/// the tool and the dialog around the canvas. -const LATCH_ESCAPE: Chord = Chord::plain(Key::Escape); - /// How a tool is reached without a pointer (8.3, owner question 15). #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] @@ -201,13 +163,8 @@ pub struct CanvasStyle { metrics: Metrics, /// How far the rulers' strips push the view's rect in from the canvas's top-left corner, while they show. rulers: Vec2, -<<<<<<< HEAD - /// The mark a latched middle scroll shows at its anchor. - mark: Option, -======= /// The middle-button autoscroll mark's fill and ink: the overlay handle colours, so it reads on any page. mark: Option<(StyleColor, StyleColor)>, ->>>>>>> origin/next } /// A canvas: a pasteboard the caller's canvas controls and the active tool share. @@ -244,10 +201,13 @@ pub struct Canvas<'a> { /// eases (Animated Zoom) and whether the view may leave the document (Overscroll). #[prop] navigation: NavigationOptions, -<<<<<<< HEAD - /// Whether the rulers show along the top and left edges (View > Rulers): the view lies inside them. - #[prop] - show_rulers: bool, + /// The rulers along the top and left edges (View > Rulers), which the canvas shows itself: the view lies inside + /// them ([`with_rulers`](Self::with_rulers)). + strips: Option>, + /// Whether the strips show; the rulers' own output of this pass is [`CanvasOutput::rulers`]. + strips_shown: bool, + /// What the rulers reported in this pass, from the paint step. + ruler_output: Option, /// Whether the canvas leaves Page Up, Page Down, Home, End and the arrows to its body: it applies no page keys, /// which its body reads in [`CanvasSpace::keys`], and the arrows reach the body's tool host and session controls /// first, then the body with [`CanvasSpace::take_nudge`], in the same pass. For a body that pages its document @@ -260,19 +220,6 @@ pub struct Canvas<'a> { /// arrows that turn its pages. #[prop] body_nudges: NudgeMods, -======= - /// The rulers along the top and left edges (View > Rulers), which the canvas shows itself: the view lies inside - /// them ([`with_rulers`](Self::with_rulers)). - strips: Option>, - /// Whether the strips show; the rulers' own output of this pass is [`CanvasOutput::rulers`]. - strips_shown: bool, - /// What the rulers reported in this pass, from the paint step. - ruler_output: Option, - /// Whether the canvas leaves Page Up, Page Down, Home, End and the arrows to its body: it applies no page keys - /// and gives no tool or session control the arrows, and its body reads them in [`CanvasSpace::keys`]. For a - /// body that pages its document itself (a page view). - #[prop] - keys_to_body: bool, /// The canvas registers one editor part of this purpose: the part's widget is the component's focus holder and the /// input-method owner, and keys arrive as editor input ([`ToolPass::editor_input`]); [`keys_to_body`](Self::keys_to_body) /// does not apply. The body reports its editor state through [`ToolPass::editor`]. @@ -286,7 +233,6 @@ pub struct Canvas<'a> { inactive_edits: EditSet, /// The editor part's inputs of this pass, taken once in `update`: `tool_pass` is built from a shared `Cx`. editor_input: Arc<[EditorInput]>, ->>>>>>> origin/next /// The rulers' units and zero point, published to the body in its [`CanvasSpace`]. rulers: Option, /// The zero point of the rulers given to `with_rulers`, which the space publishes in `rulers`. @@ -349,23 +295,16 @@ struct Settled { easing: bool, /// The keys the canvas leaves to its body. keys: BodyKeys, -<<<<<<< HEAD /// The wheel share the canvas took this pass, handed on to its body. wheel: Option, - /// A latched or held middle scroll runs. + /// A middle-button autoscroll or a held middle pan runs. auto_scrolling: bool, - /// Where a latched middle scroll is anchored. - mark: Option, - /// The press on the background is the one that ended a latch: it reaches no tool through its release. - swallowed: bool, -======= /// The mark of a running middle-button autoscroll, in screen points. mark: Option, /// A press that stopped an autoscroll is down: it reaches no tool. swallowing: bool, /// The screen point a wheel or pinch zoom of this pass kept still ([`CanvasSpace::zoom_anchor`]). zoom_anchor: Option, ->>>>>>> origin/next } impl<'a> Canvas<'a> { @@ -386,13 +325,10 @@ impl<'a> Canvas<'a> { strips_shown: false, ruler_output: None, keys_to_body: false, -<<<<<<< HEAD body_nudges: NudgeMods::NONE, -======= editor: None, inactive_edits: EditSet::NONE, editor_input: Arc::from([]), ->>>>>>> origin/next pasteboard: PasteboardColor::Default, precise_cursors: false, rulers: None, @@ -499,19 +435,9 @@ impl<'a> Canvas<'a> { self.document.map(|target| target.document) } -<<<<<<< HEAD - /// The rect the view lies in: the canvas's own, inside the rulers while they show. - fn view_rect(&self, rect: Rect, style: &CanvasStyle) -> Rect { - if self.show_rulers { Rect::from_min_max(rect.min + style.rulers, rect.max) } else { rect } - } - /// The view of this pass from the app's `given` view: this pass's rect, the first fit, the wheel with its ease and - /// the touchpad glide, a middle-button pan or latched scroll, the view commands, the Overscroll clamp, and the zoom + /// the touchpad glide, a middle-button pan or autoscroll, the view commands, the Overscroll clamp, and the zoom /// ease. -======= - /// The view of this pass from the app's `given` view: this pass's rect, the first fit, the wheel, a middle-button - /// pan, the view commands, the Overscroll clamp, and the zoom ease. ->>>>>>> origin/next fn settle(&self, cx: &mut Cx<'_, Self>, given: CanvasView) -> Settled { let ctx = cx.core.ctx.clone(); let id = cx.core.id; @@ -528,18 +454,18 @@ impl<'a> Canvas<'a> { } } let at_start = view; - // The pass clock. A later pass of the same frame reads the same time and no elapsed time, so the glide and the - // latched scroll move the view only in the pass that receives the frame's time. - + // The pass clock. A later pass of the same frame reads the same time, so the glide and the autoscroll move the + // view only in the pass that receives the frame's time. let now = frame::clock(&ctx); - let elapsed = frame::running(&ctx).map_or(0.0, |facts| facts.elapsed); let (press, on_region) = self.pressed(cx); // A press, a zoom, a key move and a view command end the touchpad glide and the eased wheel's owed motion. let mut halt = matches!(press.phase, PressPhase::Down { .. }); let mut jumped = false; -<<<<<<< HEAD let mut line_pan = Vec2::ZERO; + // The screen point a wheel or pinch zoom of this pass kept still, before the clamp below can move the centre. + let mut zoom_anchor = None; let wheel = cx.take_wheel(); + let wheeled = wheel.is_some(); if let Some(wheel) = wheel { let (line, os) = (self.navigation.wheel_line, cx.env.shell().os); let mut zoomed = false; @@ -552,24 +478,12 @@ impl<'a> Canvas<'a> { // The pointer the wheel came at: the canvas's own widget is not hovered where an app widget in // its body covers it. let at = wheel.at.unwrap_or_else(|| view.rect.center()); + let (anchor, zoom) = (WheelNavigation::zoom_anchor(&view, action, at, size), view.zoom); jumped |= WheelNavigation::apply(&mut view, action, at, size, pixels_per_point); + if view.zoom != zoom { + zoom_anchor = anchor; + } } -======= - // The screen point a wheel or pinch zoom of this pass kept still, before the clamp below can move the centre. - let mut zoom_anchor = None; - let wheel = cx.take_wheel(); - let wheeled = wheel.is_some(); - if let Some(wheel) = wheel { - let os = cx.env.shell().os; - if let Some(action) = motion.wheel.read(&wheel, WheelNavigation::LINE, os, &self.navigation) { - // The pointer the wheel came at: the canvas's own widget is not hovered where an app widget in its body - // covers it. - let at = wheel.at.unwrap_or_else(|| view.rect.center()); - let (anchor, zoom) = (WheelNavigation::zoom_anchor(&view, action, at, size), view.zoom); - jumped |= WheelNavigation::apply(&mut view, action, at, size, pixels_per_point); - if view.zoom != zoom { - zoom_anchor = anchor; ->>>>>>> origin/next } } // A trackpad rotation or a twist of two fingers turns the view; a mirrored view turns the other way. @@ -580,12 +494,7 @@ impl<'a> Canvas<'a> { } halt |= zoomed; motion.glide.read(&wheel, now, !zoomed && self.navigation.touchpad_glide); - // The wheel ends a latched middle scroll. - if motion.middle.active() { - motion.middle.cancel(); - } } -<<<<<<< HEAD // Every pass feeds the ease, the line pan or nothing, so owed motion keeps paying; the service takes the time // from its own clock, so a later pass of the same frame pays nothing. if self.navigation.eased_wheel && !halt { @@ -595,7 +504,7 @@ impl<'a> Canvas<'a> { jumped = true; } if step != Vec2::ZERO || line_pan != Vec2::ZERO { - frame::request_own_repaint(&ctx); + frame::request_repaint(&ctx); } } let before_glide = view; @@ -605,84 +514,31 @@ impl<'a> Canvas<'a> { jumped = true; } if motion.glide.gliding() { - frame::request_own_repaint(&ctx); + frame::request_repaint(&ctx); } - // The middle button latches a scroll over the background (no tool region holds the press): a click latches it, - // a second press ends it, and a release after a drag past the dead zone ends it. + // Under Autoscroll the middle button's press on the background (no tool region holds it) is the autoscroll's; + // elsewhere a middle drag pans the view 1:1. let middle = press.phase.start().is_some_and(|start| start.button == PointerButton::Middle); - let latching = middle && !on_region && self.navigation.middle_button == MiddleButton::AutoScroll; - let held = latching && press.phase.button_down(); - // Any press that begins while a latch runs ends it and reaches nothing else, so it is asked before the press - // that latches: asked after, the latching press would end its own latch. - let swallowed = motion.middle.swallows(press.phase); - match press.phase { - _ if swallowed => {} - // The latch lives while the canvas holds the focus, and the focus service moves focus on primary presses - // only: the middle press that latches it takes the focus itself. - PressPhase::Down { start, .. } if latching => { - motion.middle.press(start.origin, area.contains(start.origin)); - cx.focus_own(); - } - PressPhase::Release { .. } if latching => motion.middle.release(), - PressPhase::Cancel { .. } if latching => motion.middle.cancel(), - _ => {} - } - // A latch ends when the window loses focus or the pointer leaves it, and when the canvas missed a frame, so it - // never comes back with the window or the canvas. - let frame_nr = frame::running(&ctx).map_or(0, |pass| pass.frame_nr); - let left = crate::runtime::pointer::with_pass_pointer(&ctx, |pass| { - pass.focus_lost || pass.events.iter().any(|event| matches!(event, craft_behavior::PointerEvent::Gone)) - }); - let away = motion.latched_in.is_some_and(|last| frame_nr > last.saturating_add(1)); - if motion.middle.active() && (left || away || !crate::runtime::egui::viewports::current(&ctx).focused) { - motion.middle.cancel(); - } - // A latch with the button up ends on Escape, claimed only while it runs, and when the canvas loses focus. - if motion.middle.active() && !held { - if cx.take_claimed(LATCH_ESCAPE) || !cx.is_focused() { - motion.middle.cancel(); - } else { - cx.claim(LATCH_ESCAPE); - } - } - if motion.middle.active() { - // The pointer is read where it is over the background: the press while the button is held, the hover after. - let pointer = match press.phase { - PressPhase::Held { pos, .. } | PressPhase::DragStart { pos, .. } | PressPhase::Drag { pos, .. } if held => Some(pos), - _ => cx.hover_pos(BACKGROUND), - }; - if let Some(pointer) = pointer { - let step = motion.middle.step(pointer, held, elapsed, self.navigation.invert_middle); - if step != Vec2::ZERO { - pan(&mut view, step); - jumped = true; - } - } - cx.cursor(CursorIcon::ResizeVertical, CursorPriority::Part); - frame::request_own_repaint(&ctx); - } - // Under a latch the held press scrolls by its distance from the anchor; only the Pan mode drags the view 1:1. - let held_pan = middle && !latching && press.phase.is_drag(); + let held_pan = middle && self.middle_pans(on_region) && press.phase.is_drag(); if held_pan { cx.cursor(CursorIcon::Grabbing, CursorPriority::Drag); } - motion.latched_in = motion.middle.active().then_some(frame_nr); - let auto_scrolling = motion.middle.active() || held_pan; - let mark = motion.middle.anchor(); - if let Some(delta) = self.background_press(cx, swallowed).1 { -======= let (_, drag) = self.background_press(cx); if let Some(delta) = drag { ->>>>>>> origin/next pan(&mut view, delta); jumped = true; } let mut swallowing = false; if !measure::active(&ctx) { - let (moved, swallowed) = self.autoscroll(cx, &mut motion.autoscroll, &mut view, size, wheeled); + // An autoscroll whose canvas missed a frame (another tab showed) ends, so it never comes back with the canvas. + let frame_nr = frame::running(&ctx).map_or(0, |pass| pass.frame_nr); + let away = motion.scrolled_in.is_some_and(|last| frame_nr > last.saturating_add(1)); + let (moved, swallowed) = self.autoscroll(cx, &mut motion.autoscroll, &mut view, size, wheeled || away); jumped |= moved; swallowing = swallowed; + motion.scrolled_in = motion.autoscroll.mark().map(|_| frame_nr); } + let auto_scrolling = motion.autoscroll.mark().is_some() || held_pan; // As its body's scroll owner the canvas shows a control focus arrives at, and applies the page keys a focused // control leaves as its own. if let Some(by) = cx.take_reveal(area) { @@ -690,14 +546,10 @@ impl<'a> Canvas<'a> { jumped = true; } // Page Up and Down, Home and End scroll the view as in Photoshop; the arrows are the tool's nudges. A canvas -<<<<<<< HEAD // that leaves its keys to its body hands it the page keys; the arrows stay routed, for the body's tool host - // first and then the body (`CanvasSpace::take_nudge`). -======= - // that leaves its keys to its body hands both to it. With an editor part the keys are its input: they reached - // the body as editor input before this step, so nothing is left to hand over. + // first and then the body (`CanvasSpace::take_nudge`). With an editor part the keys are its input: they + // reached the body as editor input before this step, so nothing is left to hand over. let to_body = self.keys_to_body && self.editor.is_none(); ->>>>>>> origin/next let mut keys = BodyKeys::default(); let mut moves = Vec::new(); while let Some(mv) = cx.intents().take_move() { @@ -712,12 +564,6 @@ impl<'a> Canvas<'a> { jumped |= key.apply(&mut view, document); } } -<<<<<<< HEAD -======= - if to_body { - keys.nudge = cx.intents().take_nudge(); - } ->>>>>>> origin/next // A pan or a scroll takes over from an ease, here or in a tool. let mut steer = motion.steer.take(); if let Some(ease) = self.ease { @@ -773,28 +619,26 @@ impl<'a> Canvas<'a> { let easing = motion.animation.running(); let mark = motion.autoscroll.mark(); motion.restore(&ctx, id); -<<<<<<< HEAD - Settled { target, shown, easing, keys, wheel, auto_scrolling, mark, swallowed } -======= - Settled { target, shown, easing, keys, mark, swallowing, zoom_anchor } ->>>>>>> origin/next + Settled { target, shown, easing, keys, wheel, auto_scrolling, mark, swallowing, zoom_anchor } } /// One pass of the middle button's autoscroll over `view`: a middle press on the background starts it under - /// [`MiddleButton::Autoscroll`]; while it runs each pass scrolls toward the pointer and asks for the next pass; any - /// input ends it, and the pass that ends it applies no step. A drag while the button is held scrolls the same way, - /// and its release ends the run; a click leaves it running. `wheeled` is whether a wheel or a zoom reached the - /// canvas this pass. Returns whether the view moved, and whether a press that stopped the run is down (it and its + /// [`MiddleButton::AutoScroll`] (away from the tool regions, and the press focuses the canvas); while it runs each + /// pass scrolls toward the pointer (the other way under Invert Middle) and asks for the next pass; any input ends + /// it, and the pass that ends it applies no step. A drag while the button is held scrolls the same way, and its + /// release ends the run; a click leaves it running. `ended` is whether a wheel or a zoom reached the canvas this + /// pass, or the canvas missed a frame. Returns whether the view moved, and whether a press that stopped the run is down (it and its /// release belong to the autoscroll, not to the tool). /// /// Every end signal is read in the pass that gets the input (a rerun pass of a frame reads no key and no press, /// and shares the frame's clock, so it steps zero): `keyed` for any key (`runtime/keys/input.rs`), the background /// press or the frame's press for a press, egui's window focus (winit `Focused`, the web's blur) and a pointer /// position of `None` (winit `CursorLeft`, egui `PointerGone`) for leaving the window. - fn autoscroll(&self, cx: &mut Cx<'_, Self>, run: &mut MiddleAutoscroll, view: &mut CanvasView, size: Size, wheeled: bool) -> (bool, bool) { + fn autoscroll(&self, cx: &mut Cx<'_, Self>, run: &mut MiddleAutoscroll, view: &mut CanvasView, size: Size, ended: bool) -> (bool, bool) { let ctx = cx.core.ctx.clone(); let input = crate::runtime::pointer::frame(&ctx); - let phase = self.raw_press(cx).phase; + let (press, on_region) = self.pressed(cx); + let phase = press.phase; let down = matches!(phase, PressPhase::Down { .. }); let swallowing = run.swallowing(); if swallowing && matches!(phase, PressPhase::Release { .. } | PressPhase::Cancel { .. }) { @@ -804,8 +648,8 @@ impl<'a> Canvas<'a> { if run.mark().is_some() { let keyed = crate::runtime::keys::keyed(&ctx); let unfocused = !ctx.input(|i| i.focused); - let off = self.navigation.middle_button != MiddleButton::Autoscroll; - if keyed || wheeled || down || input.press.is_some() || unfocused || input.pos.is_none() || off { + let off = self.navigation.middle_button != MiddleButton::AutoScroll; + if keyed || ended || down || input.press.is_some() || unfocused || input.pos.is_none() || off { // Escape only stops the scroll; any other key also does its own job. if keyed { let _ = cx.intents().take(Intent::Cancel); @@ -823,16 +667,20 @@ impl<'a> Canvas<'a> { _ => {} } } - } else if self.navigation.middle_button == MiddleButton::Autoscroll + } else if !self.middle_pans(on_region) && let PressPhase::Down { start, .. } = phase && start.button == PointerButton::Middle { run.press(start.origin); + // The autoscroll lives while the canvas holds the focus, and the focus service moves focus on primary + // presses only: the middle press that starts it takes the focus itself. + cx.focus_own(); } let Some(pointer) = input.pos.filter(|_| run.mark().is_some()) else { break 'pass false }; - let step = run.step(pointer, crate::runtime::frame::clock(&ctx)); + let step = run.step(pointer, frame::clock(&ctx)); + let step = if self.navigation.invert_middle { -step } else { step }; crate::runtime::cursor::request(&ctx, run.cursor(Some(pointer)).into(), CursorPriority::Drag); - crate::runtime::frame::request_repaint(&ctx); + frame::request_repaint(&ctx); Autoscroll::scroll(view, step, size).is_some() }; (moved, swallowing || run.swallowing()) @@ -862,14 +710,9 @@ impl<'a> Canvas<'a> { /// The space the body and the tool see in this pass; `caps_lock` is whether Caps Lock is on in it. fn space(&self, id: egui::Id, pixels_per_point: f32, background: BackgroundPress, caps_lock: bool) -> Option { -<<<<<<< HEAD - let (shown, target, easing, keys, wheel) = match self.settled { - Some(settled) => (settled.shown, settled.target, settled.easing, settled.keys, settled.wheel), -======= - let (shown, target, easing, keys, zoom_anchor) = match self.settled { - Some(settled) => (settled.shown, settled.target, settled.easing, settled.keys, settled.zoom_anchor), ->>>>>>> origin/next - None => (self.given?, self.given?, false, BodyKeys::default(), None), + let (shown, target, easing, keys, wheel, zoom_anchor) = match self.settled { + Some(settled) => (settled.shown, settled.target, settled.easing, settled.keys, settled.wheel, settled.zoom_anchor), + None => (self.given?, self.given?, false, BodyKeys::default(), None, None), }; let mut space = CanvasSpace::new(target, pixels_per_point).with_follows_pointer(self.follows_pointer).with_zoom_anchor(zoom_anchor); space.set_view(target); @@ -897,55 +740,35 @@ impl<'a> Canvas<'a> { self.snap.clone().map(|snap| snap.at(&view, os)) } -<<<<<<< HEAD /// The press on the background part, or on the tool region that holds it, and whether a tool region holds it. fn pressed(&self, cx: &Cx<'_, Self>) -> (PressState, bool) { -======= - /// The press on the background part, or on the tool region that holds it, with every button. - fn raw_press(&self, cx: &Cx<'_, Self>) -> PressState { ->>>>>>> origin/next let region = (0..self.tool_regions.len() as u64) .filter_map(|i| cx.part_if_declared(TOOL_REGION.at(i))) .map(|result| result.press) .find(|press| !matches!(press.phase, PressPhase::Idle)); -<<<<<<< HEAD match region { Some(press) => (press, true), None => (cx.part(BACKGROUND).press, false), } } - /// The press on the background part, or on the tool region that holds it, as the canvas reports it, and the pan - /// of a middle-button drag: a middle press pans the view and is never a tool press. Under Invert Middle the drag - /// pans the other way, as the latched scroll does. Where the middle button latches (`MiddleButton::AutoScroll`, no - /// tool region under the press) the drag does not pan: the latch's step scrolls. A `swallowed` press (the one that - /// ended a latch) is idle. - fn background_press(&self, cx: &Cx<'_, Self>, swallowed: bool) -> (PressState, Option) { + /// Whether a middle drag of a press on the background, or on a tool region when `on_region`, pans the view: under + /// [`MiddleButton::AutoScroll`] a press away from the tool regions belongs to the autoscroll instead. + fn middle_pans(&self, on_region: bool) -> bool { + on_region || self.navigation.middle_button != MiddleButton::AutoScroll + } + + /// The press on the background part, or on the tool region that holds it, as the canvas reports it, and the pan of a + /// middle-button drag: a middle press pans the view ([`middle_pans`](Self::middle_pans)), or belongs to the + /// autoscroll, and is never a tool press. Under Invert Middle the drag pans the other way, as the autoscroll does. + fn background_press(&self, cx: &Cx<'_, Self>) -> (PressState, Option) { let (press, on_region) = self.pressed(cx); - if swallowed { - return (PressState::IDLE, None); - } - let pans = !(self.navigation.middle_button == MiddleButton::AutoScroll && !on_region); let middle = press.phase.start().is_some_and(|start| start.button == PointerButton::Middle); + let pans = self.middle_pans(on_region); let sign = if self.navigation.invert_middle { -1.0 } else { 1.0 }; match press.phase { PressPhase::DragStart { start, pos, .. } if middle && pans => (PressState::IDLE, Some((pos - start.origin) * sign)), PressPhase::Drag { delta, .. } if middle && pans => (PressState::IDLE, Some(delta * sign)), -======= - region.unwrap_or(cx.part(BACKGROUND).press) - } - - /// The press on the background part, or on the tool region that holds it, as the canvas reports it, and the pan of a - /// middle-button drag: a middle press pans the view, or under [`MiddleButton::Autoscroll`] belongs to the - /// autoscroll, and is never a tool press. - fn background_press(&self, cx: &Cx<'_, Self>) -> (PressState, Option) { - let press = self.raw_press(cx); - let middle = press.phase.start().is_some_and(|start| start.button == PointerButton::Middle); - let pans = self.navigation.middle_button != MiddleButton::Autoscroll; - match press.phase { - PressPhase::DragStart { start, pos, .. } if middle && pans => (PressState::IDLE, Some(pos - start.origin)), - PressPhase::Drag { delta, .. } if middle && pans => (PressState::IDLE, Some(delta)), ->>>>>>> origin/next _ if middle => (PressState::IDLE, None), _ => (press, None), } @@ -953,12 +776,8 @@ impl<'a> Canvas<'a> { /// The tool host's input of this pass: settled in `update`, so the body and `finish` read the same. fn tool_pass(&self, cx: &Cx<'_, Self>) -> ToolPass { -<<<<<<< HEAD - let press = self.background_press(cx, self.settled.is_some_and(|settled| settled.swallowed)).0; -======= // A press that stopped an autoscroll is the autoscroll's until its release. let press = if self.settled.is_some_and(|settled| settled.swallowing) { PressState::IDLE } else { self.background_press(cx).0 }; ->>>>>>> origin/next let caps_lock = lock_keys::caps_lock(&cx.response.ctx); let space = self.space(cx.response.id, cx.env.scale().0, BackgroundPress::of(&press, self.context_key), caps_lock); ToolPass { @@ -999,15 +818,12 @@ pub struct CanvasOutput { /// target; the canvas shows the way there itself. [`ToolHost::run`] carries it in [`ToolHostResponse::view`] /// when no tool set a view, so an app with a tool host copies that one view. pub view: Option, -<<<<<<< HEAD - /// True while a latched or held middle scroll runs this pass. + /// True while a middle-button autoscroll or a held middle pan runs this pass. pub auto_scrolling: bool, -======= /// The mark of a running middle-button autoscroll, for captures. pub autoscroll: Option, /// What the rulers given to [`Canvas::with_rulers`] reported in this pass. pub rulers: Option, ->>>>>>> origin/next } impl CanvasOutput { @@ -1105,21 +921,8 @@ impl Component for Canvas<'_> { type Style = CanvasStyle; type Output = CanvasOutput; - fn keys(&self) -> KeyUse { - Self::KEYS.with_nudge_mods(NudgeMods::STEPS.union(self.body_nudges)) - } - fn style(cx: &StyleCx<'_>, _: CanvasStyleKey) -> CanvasStyle { let surface = SurfaceLook::new(Stateful::new(cx.color(cx.tokens.color.surface.canvas))).kind(SurfaceKind::Canvas); -<<<<<<< HEAD - // The rulers' own layout says where the view lies inside them. - CanvasStyle { - surface: Some(surface), - rulers: Rulers::content_rect(cx, Rect::ZERO).min.to_vec2(), - mark: Some(cx.auto_scroll_mark()), - ..CanvasStyle::default() - } -======= // The rulers' own layout says where the view lies inside them. The autoscroll mark takes the overlay handle // colours, not the window fill and text ink: the canvas has no window fill, and the overlay pair is the one // that reads on any page. @@ -1138,9 +941,8 @@ impl Component for Canvas<'_> { fn keys(&self) -> KeyUse { match self.editor { Some(_) => KeyUse::of(Input::Editor).with_chrome_key(true).with_moves().with_inactive(self.inactive_edits), - None => Self::KEYS, + None => Self::KEYS.with_nudge_mods(NudgeMods::STEPS.union(self.body_nudges)), } ->>>>>>> origin/next } fn sense(&self) -> Sense { @@ -1172,13 +974,6 @@ impl Component for Canvas<'_> { ui.clipped(cx.content_rect, |ui| navigate::paint_mark(&ui.draw(), at, fill, ink)); } - /// The mark of a latched middle scroll, at its anchor above the body. - fn paint_over(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) { - if let (Some(anchor), Some(look)) = (self.settled.and_then(|settled| settled.mark), cx.style.mark) { - ui.draw().auto_scroll_mark(&look, anchor); - } - } - /// The view of this pass, kept for the body and `finish`. fn update(&mut self, cx: &mut Cx<'_, Self>) { // Taken once: `Cx::editor_input` empties the pass's inputs, and the body reads them from the `ToolPass`. @@ -1249,13 +1044,17 @@ impl Component for Canvas<'_> { fn finish(self, cx: Cx<'_, Self>) -> CanvasOutput { let pass = self.tool_pass(&cx); -<<<<<<< HEAD - let auto_scrolling = self.settled.is_some_and(|settled| settled.auto_scrolling); - CanvasOutput { response: cx.response.clone(), press: pass.press, space: pass.space, view: pass.view, auto_scrolling } -======= let autoscroll = self.settled.and_then(|settled| settled.mark); - CanvasOutput { response: cx.response.clone(), press: pass.press, space: pass.space, view: pass.view, autoscroll, rulers: self.ruler_output } ->>>>>>> origin/next + let auto_scrolling = self.settled.is_some_and(|settled| settled.auto_scrolling); + CanvasOutput { + response: cx.response.clone(), + press: pass.press, + space: pass.space, + view: pass.view, + auto_scrolling, + autoscroll, + rulers: self.ruler_output, + } } } diff --git a/crates/ui-canvas/src/canvas/navigate/mod.rs b/crates/ui-canvas/src/canvas/navigate/mod.rs index cb38f63c42..1b8435801a 100644 --- a/crates/ui-canvas/src/canvas/navigate/mod.rs +++ b/crates/ui-canvas/src/canvas/navigate/mod.rs @@ -17,11 +17,7 @@ mod wheel; pub(crate) use autoscroll::{MiddleAutoscroll, paint_mark}; pub use bar::{NavigateBar, NavigateBarOutput}; pub use keys::PageKey; -<<<<<<< HEAD -pub use options::{NavigationOptions, WheelScheme}; -======= pub use options::{MiddleButton, NavigationOptions, WheelScheme}; ->>>>>>> origin/next pub use wheel::{WheelAction, WheelInput, WheelNavigation}; use super::frame_step; diff --git a/crates/ui-canvas/src/canvas/navigate/options.rs b/crates/ui-canvas/src/canvas/navigate/options.rs index 992e5309f6..233dcff350 100644 --- a/crates/ui-canvas/src/canvas/navigate/options.rs +++ b/crates/ui-canvas/src/canvas/navigate/options.rs @@ -1,31 +1,9 @@ //! `NavigationOptions`: the user's navigation choices (Photoshop's Preferences, General, Tools and Enhanced Controls //! rows), which the app owns and hands to the navigation pieces and the view tools. -<<<<<<< HEAD use super::PageKey; -======= -/// How the wheel navigates. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -#[non_exhaustive] -pub enum WheelScheme { - /// Photoshop's: the wheel scrolls, and Zoom with Scroll Wheel decides what zooms. - #[default] - Photoshop, - /// A document's: Ctrl/Cmd+wheel zooms by zoom ladder rungs and Shift+wheel scrolls sideways. - Document, -} -/// What the middle button does on the canvas. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -#[non_exhaustive] -pub enum MiddleButton { - /// A middle drag pans. - #[default] - Pan, - /// A middle click starts autoscroll and a middle drag pans. - Autoscroll, -} ->>>>>>> origin/next +pub use craft_behavior::MiddleButton; /// The navigation choices, with Photoshop's defaults. #[derive(Clone, Copy, Debug, PartialEq)] @@ -52,7 +30,6 @@ pub struct NavigationOptions { pub trackpad_rotate: bool, /// Enhanced Controls, Enable Gestures: a touch screen's two-finger pinch and twist. On. pub touch_gestures: bool, -<<<<<<< HEAD /// What a plain and a modified wheel do. `Scroll`. pub wheel: WheelScheme, /// How many points a wheel line moves the view. 16. @@ -80,17 +57,13 @@ pub enum WheelScheme { Zoom, /// Cmd or Ctrl zooms about the pointer by [`ACROBAT_NOTCH`](Self::ACROBAT_NOTCH) per line; Shift scrolls sideways. Acrobat, + /// A document's: Ctrl/Cmd+wheel zooms by zoom ladder rungs and Shift+wheel scrolls sideways. + Document, } impl WheelScheme { /// The zoom factor of one wheel line under [`Acrobat`](Self::Acrobat). pub const ACROBAT_NOTCH: f64 = 1.221_402_758; -======= - /// How the wheel navigates. Photoshop's. - pub wheel: WheelScheme, - /// What the middle button does. A pan. - pub middle_button: MiddleButton, ->>>>>>> origin/next } impl Default for NavigationOptions { @@ -107,16 +80,12 @@ impl Default for NavigationOptions { trackpad_rotate: false, touch_gestures: true, wheel: WheelScheme::default(), -<<<<<<< HEAD wheel_line: 16.0, key_line: PageKey::SMALL_STEP, eased_wheel: false, touchpad_glide: false, middle_button: craft_behavior::MiddleButton::default(), invert_middle: false, -======= - middle_button: MiddleButton::default(), ->>>>>>> origin/next } } } diff --git a/crates/ui-canvas/src/canvas/navigator/preview.rs b/crates/ui-canvas/src/canvas/navigator/preview.rs index fce664afb4..8156f5f7fa 100644 --- a/crates/ui-canvas/src/canvas/navigator/preview.rs +++ b/crates/ui-canvas/src/canvas/navigator/preview.rs @@ -411,12 +411,8 @@ impl Component for Navigator<'_> { if let Some(wheel) = cx.take_wheel() && !running { -<<<<<<< HEAD + // The preview's plain wheel zooms under every scheme: the Document and Acrobat schemes zoom only with Ctrl or Cmd. let options = NavigationOptions { wheel: WheelScheme::Zoom, ..self.navigation }; -======= - // The preview's plain wheel zooms under every scheme: the Document scheme zooms only with Ctrl or Cmd. - let options = NavigationOptions { zoom_with_wheel: true, wheel: WheelScheme::Photoshop, ..self.navigation }; ->>>>>>> origin/next let (line, os) = (craft_behavior::WheelNotch::DEFAULT.points(0.0), cx.env.shell().os); let action = cx.memory::().read(&wheel, line, os, &options); if let Some(action @ (WheelAction::Zoom(_) | WheelAction::SnapZoom(_))) = action { diff --git a/crates/ui-canvas/src/canvas/space.rs b/crates/ui-canvas/src/canvas/space.rs index 605128e5c0..c8f886214d 100644 --- a/crates/ui-canvas/src/canvas/space.rs +++ b/crates/ui-canvas/src/canvas/space.rs @@ -40,11 +40,8 @@ pub struct CanvasSpace { /// The canvas's picture slot for this pass, which [`paint_picture`](Self::paint_picture) appends to; `None` in a /// measuring pass. picture: Option, -<<<<<<< HEAD wheel: Option, -======= zoom_anchor: Option, ->>>>>>> origin/next } impl CanvasSpace { @@ -65,11 +62,8 @@ impl CanvasSpace { pasteboard: PasteboardColor::Default, precise: false, picture: None, -<<<<<<< HEAD wheel: None, -======= zoom_anchor: None, ->>>>>>> origin/next } } @@ -233,9 +227,6 @@ impl CanvasSpace { self.easing } -<<<<<<< HEAD - /// The page keys the canvas left to its body in this pass ([`Canvas::keys_to_body`](super::Canvas)). -======= /// The screen point the wheel or a pinch zoomed about in this pass, in the canvas root's screen space; `None` when /// neither zoomed (a view command zooms about the centre). A body that keeps its own view state anchors its zoom /// here: the canvas clamps the zoomed view to the document after, which can move the centre (a document no wider @@ -251,8 +242,7 @@ impl CanvasSpace { self } - /// The page and arrow keys the canvas left to its body in this pass ([`Canvas::keys_to_body`](super::Canvas)). ->>>>>>> origin/next + /// The page keys the canvas left to its body in this pass ([`Canvas::keys_to_body`](super::Canvas)). pub fn keys(&self) -> BodyKeys { self.keys } @@ -270,7 +260,7 @@ impl CanvasSpace { return Some(nudge); } let mut nudge = None; - crate::runtime::keys::with_window_intents(ctx, false, |window| { + crate::runtime::keys::with_canvas_window_intents(ctx, false, |window| { nudge = window.take_nudge(); nudge.is_some() }); diff --git a/crates/ui-canvas/src/canvas/split/stories.rs b/crates/ui-canvas/src/canvas/split/stories.rs index 74e944ed41..a7179dc85c 100644 --- a/crates/ui-canvas/src/canvas/split/stories.rs +++ b/crates/ui-canvas/src/canvas/split/stories.rs @@ -82,80 +82,49 @@ fn click_inactive_pane(fixture: &mut Fixture) { #[story(SplitViews<'static>, covers = [Default], drive = Drive::Custom(drag_divider))] fn two_views(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { -<<<<<<< HEAD - let at = data.value("split", SplitAt::default()); - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, Bind::bound(at)) -======= let (at, at_at) = data.value_at("split", SplitAt::default()); - let shown = at.clone(); - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind(at), shown) ->>>>>>> origin/next + split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind(at)) } #[story(SplitViews<'static>, covers = [Default], drive = Drive::Custom(drag_divider))] fn four_views(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { -<<<<<<< HEAD - let at = data.value("split", SplitAt::default()); - split(ui, SplitLayout::FourUp, 4, MAIN_OF_FOUR, Bind::bound(at)) -======= let (at, at_at) = data.value_at("split", SplitAt::default()); - let shown = at.clone(); - split(ui, SplitLayout::FourUp, 4, MAIN_OF_FOUR, at_at.bind(at), shown) ->>>>>>> origin/next + split(ui, SplitLayout::FourUp, 4, MAIN_OF_FOUR, at_at.bind(at)) } #[story(SplitViews<'static>, covers = [Default], drive = Drive::Custom(drag_divider))] fn grid_views(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { -<<<<<<< HEAD - let at = data.value("split", SplitAt::default()); - split(ui, SplitLayout::Tile, 5, 0, Bind::bound(at)) -======= let (at, at_at) = data.value_at("split", SplitAt::default()); - let shown = at.clone(); - split(ui, SplitLayout::Tile, 5, 0, at_at.bind(at), shown) ->>>>>>> origin/next + split(ui, SplitLayout::Tile, 5, 0, at_at.bind(at)) } #[story(SplitViews<'static>, covers = [Default], drive = Drive::Custom(drag_row_divider))] fn stacked_views(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { -<<<<<<< HEAD - let at = data.value("split", SplitAt::default()); - split(ui, SplitLayout::ThreeUpStacked, 3, 0, Bind::bound(at)) -======= let (at, at_at) = data.value_at("split", SplitAt::default()); - let shown = at.clone(); - split(ui, SplitLayout::ThreeUpStacked, 3, 0, at_at.bind(at), shown) ->>>>>>> origin/next + split(ui, SplitLayout::ThreeUpStacked, 3, 0, at_at.bind(at)) } #[story(SplitViews<'static>, covers = [Default], drive = Drive::Custom(click_inactive_pane))] fn another_view_clicked(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { -<<<<<<< HEAD - let at = data.value("split", SplitAt::default()); - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, Bind::bound(at)) + let (at, at_at) = data.value_at("split", SplitAt::default()); + split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind(at)) } #[story(SplitViews<'static>, covers = [Default], drive = Drive::Custom(click_inactive_pane))] fn interactive_panes(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - let at = data.value("split", SplitAt::default()); - SplitViews::new("Views", SplitLayout::TwoUpVertical, Bind::bound(at)) + let (at, at_at) = data.value_at("split", SplitAt::default()); + SplitViews::new("Views", SplitLayout::TwoUpVertical, at_at.bind(at)) .active(MAIN_OF_TWO) .pane_press(PanePress::Interact) .show_panes(ui, |ui, _, pane| show_pane(ui, pane)) .output .into() -======= - let (at, at_at) = data.value_at("split", SplitAt::default()); - let shown = at.clone(); - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind(at), shown) ->>>>>>> origin/next } #[story(SplitViews<'static>, covers = [Mixed], drive = Drive::Custom(drag_divider))] fn splits_that_differ(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { -<<<<<<< HEAD - let at = data.value("split", Mixed::::Mixed); - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, Bind::bound_mixed(at)) + let (at, at_at) = data.value_at("split", Mixed::::Mixed); + split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind_mixed(at)) } /// The documents the tab story opens with. @@ -175,32 +144,19 @@ fn drop_a_tab_to_split(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { _ => {} } } - let at = data.value("split", SplitAt::default()); - let views = SplitViews::new("Views", SplitLayout::Tile, Bind::bound(at)) + let (at, at_at) = data.value_at("split", SplitAt::default()); + let views = SplitViews::new("Views", SplitLayout::Tile, at_at.bind(at)) .count(1) .takes_tabs(|_: &[usize], _| true) .show_panes(ui, |ui, _, pane| show_pane(ui, pane)); views.output.into() -======= - let (at, at_at) = data.value_at("split", Mixed::::Mixed); - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind_mixed(at), SplitAt::default()) ->>>>>>> origin/next } #[story(SplitViews<'static>, covers = [Invalid], drive = Drive::Custom(drag_divider))] fn views_too_far_left(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { -<<<<<<< HEAD - let at = data.value("split", SplitAt::new(MOST_LEFT + 0.1, 0.5)); - let too_wide = |at: &SplitAt| { - if at.columns.first().is_some_and(|&x| x > MOST_LEFT) { Validity::Refuse(Message::new("The left view is too wide")) } else { Validity::Ok } - }; - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, Bind::bound(at).check(too_wide)) -======= let (at, at_at) = data.value_at("split", SplitAt::new(MOST_LEFT + 0.1, 0.5)); - let shown = at.clone(); let too_wide = |at: &SplitAt| { if at.columns.first().is_some_and(|&x| x > MOST_LEFT) { Validity::Refuse(Message::new("The left view is too wide")) } else { Validity::Ok } }; - split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind(at).check(too_wide), shown) ->>>>>>> origin/next + split(ui, SplitLayout::TwoUpVertical, 2, MAIN_OF_TWO, at_at.bind(at).check(too_wide)) } diff --git a/crates/ui-canvas/src/canvas/tool_host.rs b/crates/ui-canvas/src/canvas/tool_host.rs index 9dd8c1bd62..e6249b39c3 100644 --- a/crates/ui-canvas/src/canvas/tool_host.rs +++ b/crates/ui-canvas/src/canvas/tool_host.rs @@ -1257,14 +1257,12 @@ impl<'a, 't: 'a> Run<'a, 't> { /// The canvas background's press phase of this pass. A pass carries one phase, so a press that moved or /// released in the pass it began in starts here. fn phase(&mut self, press: &PressState, frame: &PointerFrame) { -<<<<<<< HEAD // A right-click during the gesture asks for the menu where it came up; the gesture goes on. if let Some(at) = press.context { - self.response.context = Some(ContextRequest { at, mods: press.mods, momentary: self.momentary }); -======= + self.response.context = Some(ContextRequest { at, mods: press.mods, momentary: self.momentary, source: ContextSource::Pointer }); + } if press.phase.is_press() { self.state.rehover = true; ->>>>>>> origin/next } match press.phase { PressPhase::Idle => self.state.spent = false, diff --git a/crates/ui-canvas/src/canvas/zoom_motion.rs b/crates/ui-canvas/src/canvas/zoom_motion.rs index b17dfae4d4..49721d9bd6 100644 --- a/crates/ui-canvas/src/canvas/zoom_motion.rs +++ b/crates/ui-canvas/src/canvas/zoom_motion.rs @@ -11,7 +11,7 @@ use crate::runtime::frame; use crate::runtime::memory::{global, with_session}; use craft_behavior::canvas::zoom; use craft_behavior::kurbo::{Point, Size}; -use craft_behavior::{CanvasView, MiddleScroll, ZoomLadder}; +use craft_behavior::{CanvasView, ZoomLadder}; use egui::{Context, Id, Pos2, Rect}; /// How far the app's view may differ from the zoom anchor, in document units, before the anchor is dropped. @@ -130,17 +130,12 @@ pub(crate) struct ViewMotion { pub(crate) animation: ZoomAnimation, /// What the tool host or the Navigator asked of the ease since the canvas's last pass. pub(crate) steer: Option, -<<<<<<< HEAD /// The touchpad's glide after the fingers lift. pub(crate) glide: TouchpadGlide, - /// The middle button's latched scroll. - pub(crate) middle: MiddleScroll, - /// The frame of the latch's last pass: a latch whose canvas missed a frame (another tab showed) ends. - pub(crate) latched_in: Option, -======= /// The middle button's autoscroll, with the pass clock of its last step: gesture state, as the ease is. pub(crate) autoscroll: super::navigate::MiddleAutoscroll, ->>>>>>> origin/next + /// The frame of the autoscroll's last pass: an autoscroll whose canvas missed a frame (another tab showed) ends. + pub(crate) scrolled_in: Option, } impl ViewMotion { diff --git a/crates/ui-canvas/src/canvas_controls/mod.rs b/crates/ui-canvas/src/canvas_controls/mod.rs index 8095d2f622..58d1094cb5 100644 --- a/crates/ui-canvas/src/canvas_controls/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/mod.rs @@ -27,11 +27,7 @@ pub use line_preview::{LineGuideStyle, StraightLinePreview}; pub use marquee::{Marquee, MarqueeLook, MarqueeShape, MarqueeStyle, Run}; pub use outline::{HoverMask, HoverOutline, HoverShape, OutlineStyle, SelectionOutline, SelectionOutlineLook, path_runs}; pub use pixel_grid::{GridSegment, PixelGrid, PixelGridStyle}; -<<<<<<< HEAD -pub use task_bar::{TaskBar, TaskBarCx, TaskBarKind, TaskBarOutput, TaskBarPlace}; -======= pub use task_bar::{TaskBar, TaskBarCx, TaskBarDismiss, TaskBarKind, TaskBarOutput, TaskBarPlace}; ->>>>>>> origin/next // End of canvas-controls-b. // Brush overlays. diff --git a/crates/ui-canvas/src/canvas_controls/task_bar.rs b/crates/ui-canvas/src/canvas_controls/task_bar.rs index 6410651959..008fc46ebe 100644 --- a/crates/ui-canvas/src/canvas_controls/task_bar.rs +++ b/crates/ui-canvas/src/canvas_controls/task_bar.rs @@ -1,5 +1,5 @@ -//! `TaskBar`: the contextual task bar over a canvas: hung below its anchor until the user moves it, fixed beside its -//! anchor, or fixed at the canvas view's top edge. +//! `TaskBar`: the contextual task bar over a canvas: hung below its anchor until the user moves it, over a selection, +//! fixed beside its anchor, or fixed at the canvas view's top edge. #[cfg(feature = "suite")] pub(crate) mod stories; @@ -21,13 +21,8 @@ use crate::runtime::overlay::CloseReason; use crate::style::{ComponentStyle, StyleCx, SurfaceKind}; use craft_behavior::kurbo::Point; use craft_behavior::overlay::{Align, Side}; -<<<<<<< HEAD -use craft_behavior::{EditEvent, IconId, Metrics, Mixed, Sense}; -use egui::{Pos2, Rect, Response, Ui, Vec2}; -======= use craft_behavior::{EditEvent, GesturePhase, IconId, Metrics, Mixed, Sense}; -use egui::{Pos2, Rect, Response, Ui}; ->>>>>>> origin/next +use egui::{Pos2, Rect, Response, Ui, Vec2}; use std::sync::Arc; /// Where the task bar sits: pinned or following its anchor, and where the user moved it. The one owner of the bar's @@ -57,10 +52,9 @@ impl TaskBarPlace { } } -/// The contextual task bar: a modeless layer with a body of members. -/// -/// A movable bar ([`TaskBar::new`]) hangs below the screen bounds of its anchor while its place is unset, with a More -/// menu (Hide, Reset, Pin). One place, pin and Hide setting for Crop and Frame. +/// The contextual task bar: a movable modeless layer hung below the screen bounds of `anchor` while its place is +/// unset, with a body of members and a More menu (Hide, Reset, Pin). One place, pin and Hide setting for Crop and +/// Frame. /// /// - Place: centred under the anchor's bounds on screen, a section gap below them, following the anchor each pass. /// Dragged by its grip (any free point of the bar), it stays where it is dropped and keeps its left edge while the @@ -72,9 +66,10 @@ impl TaskBarPlace { /// - `place` is the caller's value (`Bind::bound`): the bar reads it before it shows and writes the pass's change /// after. /// -/// A fixed bar ([`TaskBar::fixed`]) hangs centred a section gap below its anchor's bounds, above them when there is no -/// room below, and follows the anchor. An edge bar ([`TaskBar::at_edge`]) hangs at the top edge of `area`, the canvas -/// view's rect, and takes no anchor. Neither has a grip, a move or a More menu, and neither reports `hide`. +/// A selection bar ([`TaskBar::selection`]) hangs above a selection, flipped and kept inside `area`. A fixed bar +/// ([`TaskBar::fixed`]) hangs centred a section gap below its anchor's bounds, above them when there is no room below, +/// and follows the anchor. An edge bar ([`TaskBar::at_edge`]) hangs at the top edge of `area`, the canvas view's rect, +/// and takes no anchor. None of them has a grip, a move or a More menu, and none reports `hide`. /// /// Nothing shows outside a canvas, while `area` is not finite or has no size, or, for an anchored bar, while the /// anchor's bounds are not finite. @@ -84,29 +79,7 @@ pub struct TaskBar<'a> { label: Label, hang: Hang<'a>, place: Bind<'a, TaskBarPlace>, -<<<<<<< HEAD - kind: TaskBarKind, -} - -/// What a bar hangs from: the screen bounds of document points, or the canvas view's top edge, aligned in reading -/// direction. -#[derive(Clone, Copy)] -enum Hang<'a> { - Points(&'a [Point]), - Edge(Align), -} - -/// Whether a task bar follows its anchor and moves, or stays where it hangs. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -#[non_exhaustive] -pub enum TaskBarKind { - /// The bar follows its anchor and the user moves it. - #[default] - Movable, - /// The bar hangs where it is placed: no grip, no move band and no More menu. - Fixed, -======= - /// Which bar this is: the task bar, or a bar over a selection. + /// Which bar this is: the task bar, a bar over a selection, or a fixed bar. #[prop] kind: TaskBarKind, /// The side of the anchor the bar hangs on; `None` gives the kind's side: above for `Selection`, below for `Task`. @@ -117,6 +90,14 @@ pub enum TaskBarKind { dismiss: TaskBarDismiss, } +/// What a bar hangs from: the screen bounds of document points, or the canvas view's top edge, aligned in reading +/// direction. +#[derive(Clone, Copy)] +enum Hang<'a> { + Points(&'a [Point]), + Edge(Align), +} + /// Which bar a [`TaskBar`] is. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] @@ -126,6 +107,9 @@ pub enum TaskBarKind { Task, /// A bar anchored above a selection. Selection, + /// A bar that hangs where it is placed, below its anchor or at the view's top edge: no grip, no move band and no + /// More menu. + Fixed, } /// What an outside press does to a [`TaskBar`]. @@ -137,7 +121,6 @@ pub enum TaskBarDismiss { Close, /// The bar survives outside presses while its graphic is selected. Keep, ->>>>>>> origin/next } /// What the task bar reports. @@ -169,7 +152,8 @@ pub struct TaskBarCx<'a> { impl TaskBarCx<'_> { /// Places the More menu button here, before the members that follow it (the Crop bar puts Cancel and Done after - /// it); without the call the button comes after the body. A fixed bar has no More menu: the call places nothing. + /// it); without the call the button comes after the body. A selection or fixed bar has no More menu: the call places + /// nothing. pub fn more_menu(&mut self, ui: &mut Ui) { self.menu.place(ui); } @@ -186,18 +170,14 @@ enum MenuPick { /// The More button and its menu, placed once per run of the bar's body. struct MoreMenu { words: Arc, -<<<<<<< HEAD - /// The bar offers the menu: a movable bar does, a fixed one does not. -======= - /// Whether the bar has a More menu: a selection bar has none. ->>>>>>> origin/next + /// Whether the bar has a More menu: only the task bar has one. offered: bool, placed: bool, pick: Option, } impl MoreMenu { - /// Shows the button and its menu here unless the bar offers none or this run of the body showed them already. + /// Shows the button and its menu here unless this run of the body showed them already. fn place(&mut self, ui: &mut Ui) { if !self.offered || std::mem::replace(&mut self.placed, true) { return; @@ -224,55 +204,47 @@ impl MoreMenu { impl<'a> TaskBar<'a> { /// A bar named `label` hung below the screen bounds of `anchor` (document points) until `place` moves it. pub fn new(label: impl Into