From 9be8a1d11ce2579caea4ebd8afc30987b562abdd Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 14 Nov 2026 02:49:16 +0000 Subject: [PATCH] Contract stubs: craft-draw (part 4: transform, crop bar, slice, exports) --- crates/behavior/src/geometry/quad.rs | 12 +++- crates/draw/src/ui/crop/bar.rs | 10 ++- crates/draw/src/ui/crop/bar_words.rs | 8 +++ crates/draw/src/ui/crop/mod.rs | 2 +- crates/draw/src/ui/crop/perspective_tool.rs | 65 +++++++++++++++++++ crates/draw/src/ui/mod.rs | 19 +++++- crates/draw/src/ui/pen/bezier/tools.rs | 4 +- crates/draw/src/ui/pen/mod.rs | 4 +- crates/draw/src/ui/shape/mod.rs | 16 +++-- crates/draw/src/ui/shape/panel.rs | 4 +- crates/draw/src/ui/shape_presets.rs | 2 +- crates/draw/src/ui/slice/bar.rs | 12 +++- crates/draw/src/ui/slice/tool.rs | 10 +++ crates/draw/src/ui/stroke/mod.rs | 2 +- crates/draw/src/ui/transform/mod.rs | 4 +- crates/draw/src/ui/transform/session.rs | 4 +- .../draw/src/ui/transform/session/settings.rs | 25 ++++++- crates/draw/src/ui/transform/session_bar.rs | 10 +-- .../draw/src/ui/transform/session_overlay.rs | 33 ++++++++-- .../ui/transform/session_overlay/stories.rs | 6 +- crates/draw/src/ui/transform/transform_box.rs | 42 ++++++++++-- .../draw/src/ui/transform/transform_fields.rs | 44 ++++++++++--- crates/draw/tests/it/transform_box.rs | 2 +- crates/draw/tests/it/transform_fields.rs | 6 +- 24 files changed, 283 insertions(+), 63 deletions(-) diff --git a/crates/behavior/src/geometry/quad.rs b/crates/behavior/src/geometry/quad.rs index 3744830b7..5811f0908 100644 --- a/crates/behavior/src/geometry/quad.rs +++ b/crates/behavior/src/geometry/quad.rs @@ -114,18 +114,26 @@ pub struct BoxAllow { pub skew: bool, /// Distorting and perspective are allowed. pub distort: bool, + /// Warping is allowed. + pub warp: bool, } impl BoxAllow { /// What the content allows: turning, skewing and distorting. pub const fn new(rotate: bool, skew: bool, distort: bool) -> Self { - BoxAllow { rotate, skew, distort } + BoxAllow { rotate, skew, distort, warp: true } + } + + /// Whether the content allows warping. + pub const fn with_warp(mut self, warp: bool) -> Self { + self.warp = warp; + self } } impl Default for BoxAllow { fn default() -> Self { - BoxAllow { rotate: true, skew: true, distort: true } + BoxAllow { rotate: true, skew: true, distort: true, warp: true } } } diff --git a/crates/draw/src/ui/crop/bar.rs b/crates/draw/src/ui/crop/bar.rs index 42cd71bac..4f8ac15f4 100644 --- a/crates/draw/src/ui/crop/bar.rs +++ b/crates/draw/src/ui/crop/bar.rs @@ -121,13 +121,13 @@ impl<'a> CropBar<'a> { /// Shows the bar's children. pub fn show(self, ui: &mut Ui) -> CropBarOutput { let Self { settings, document, user_presets, straighten, angle, help, can_reset } = self; - let _ = (help, can_reset); // P3(tools-w14): pn.C20, pn.C21 the Reset and help buttons. let env = Env::of(ui); let words = env.words::(); let units = env.units(); let has_document = document.size.width > 0.0 && document.size.height > 0.0; let before = settings.clone(); let mut report = Report::default(); + let (mut help_pressed, mut reset_pressed) = (false, false); // The options are the bar's members, spaced as the bar spaces them. let shown = Row::new().gap(Gap::Item).show(ui, |ui, cx| { preset_list(ui, settings, &words, document, has_document, user_presets, &units, &mut report); @@ -162,6 +162,10 @@ impl<'a> CropBar<'a> { settings.fill = fill; } }); + if let Some(label) = help.clone() { + help_pressed = clicked(&IconButton::new(IconId::new("info")).label(label).show(ui)); + } + reset_pressed = clicked(&IconButton::new(IconId::new("undo_2")).label(words.reset_tip.clone()).enabled(can_reset).show(ui)); }); let changed = *settings != before; CropBarOutput { @@ -173,8 +177,8 @@ impl<'a> CropBar<'a> { delete_preset: report.delete_preset, pick_color: report.pick_color, settings_changed: changed, - help: false, - reset: false, + help: help_pressed, + reset: reset_pressed, selection: false, } } diff --git a/crates/draw/src/ui/crop/bar_words.rs b/crates/draw/src/ui/crop/bar_words.rs index a585f2be2..66c3b90cc 100644 --- a/crates/draw/src/ui/crop/bar_words.rs +++ b/crates/draw/src/ui/crop/bar_words.rs @@ -62,6 +62,14 @@ craft_ui::words! { fill_name: "cropBar.fillName" = "Fill"; fill_background: "cropBar.fillBackground" = "Background (Default)"; fill_content_aware: "cropBar.fillContentAware" = "Content-Aware Fill"; + /// The preset list's From Selection entry. + selection: "cropBar.selection" = "From Selection"; + /// The Fill select's first entry while Delete Cropped Pixels is off. + fill_transparent: "cropBar.fillTransparent" = "Transparent"; + /// The Reset button's name and tooltip. + reset_tip: "cropBar.resetTip" = "Reset crop box"; + /// The perspective bar's Show Grid check box. + show_grid: "cropBar.showGrid" = "Show Grid"; commit: "cropBar.commit" = "Commit current crop operation"; cancel: "cropBar.cancel" = "Cancel current crop operation"; } diff --git a/crates/draw/src/ui/crop/mod.rs b/crates/draw/src/ui/crop/mod.rs index 3467df2da..1d9b9db89 100644 --- a/crates/draw/src/ui/crop/mod.rs +++ b/crates/draw/src/ui/crop/mod.rs @@ -30,7 +30,7 @@ pub use perspective_bar::{PerspectiveCropBar, PerspectiveCropBarOutput}; pub use perspective_crop::{ PerspectiveCropOutput, PerspectiveCropQuad, PerspectiveCropStyle, PerspectiveQuad, grid_lines, grid_steps, is_valid, ordered, }; -pub use perspective_tool::{PerspectiveCropEvent, PerspectiveCropTool, perspective_to_form}; +pub use perspective_tool::{PerspectiveCropEvent, PerspectiveCropPass, PerspectiveCropTool, PerspectiveInput, perspective_to_form}; pub use preset_list::{CropPresetList, CropPresetListOutput}; pub use session::{CropDocKey, CropDocument, CropKept, CropSession, CropStep, LeaveFrame, StraightenState}; pub use size_cells::CropSizeTarget; diff --git a/crates/draw/src/ui/crop/perspective_tool.rs b/crates/draw/src/ui/crop/perspective_tool.rs index e140dc1ba..808849092 100644 --- a/crates/draw/src/ui/crop/perspective_tool.rs +++ b/crates/draw/src/ui/crop/perspective_tool.rs @@ -104,6 +104,71 @@ fn boxed(anchor: Point, to: Point) -> PerspectiveQuad { (x1 > x0 && y1 > y0).then_some([Point::new(x0, y0), Point::new(x1, y0), Point::new(x1, y1), Point::new(x0, y1)]) } +/// What the host hands the perspective crop pass each frame. +#[derive(Clone, Copy, Debug, Default)] +#[non_exhaustive] +pub struct PerspectiveInput<'a> { + /// Whether the quad's grid shows. + pub show_grid: bool, + /// Ties the input to the pass's lifetime until the shield (tl.T44, not in this checkout) joins it. + pub marker: std::marker::PhantomData<&'a ()>, +} + +/// This pass's perspective crop tool for the host, borrowing its input; it is the canvas tool while the pass lives. +pub struct PerspectiveCropPass<'a> { + tool: &'a mut PerspectiveCropTool, + input: PerspectiveInput<'a>, +} + +impl PerspectiveCropTool { + /// This pass's tool for the host, borrowing `input`'s data. + pub fn pass<'a>(&'a mut self, input: PerspectiveInput<'a>) -> PerspectiveCropPass<'a> { + PerspectiveCropPass { tool: self, input } + } +} + +impl PerspectiveCropPass<'_> { + /// Shows the quad over the canvas at `canvas_rect` and reports its edits. + pub fn show_quad(&mut self, ui: &mut egui::Ui, canvas_rect: egui::Rect) -> super::PerspectiveCropOutput { + let _ = (&self.tool, &self.input, ui, canvas_rect); + todo!("tl.T48") + } +} + +impl CanvasTool for PerspectiveCropPass<'_> { + fn press(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) -> ToolAction { + self.tool.press(pointer, cx) + } + + fn drag(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) { + self.tool.drag(pointer, cx); + } + + fn release(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) { + self.tool.release(pointer, cx); + } + + fn cancel(&mut self, reason: CancelReason, cx: &mut ToolContext<'_>) { + self.tool.cancel(reason, cx); + } + + fn key(&mut self, key: &ToolKey, cx: &mut ToolContext<'_>) -> bool { + self.tool.key(key, cx) + } + + fn paint(&self, draw: &Draw<'_>, cx: &ToolContext<'_>) { + self.tool.paint(draw, cx); + } + + fn cursor(&self, cx: &ToolContext<'_>) -> Cursor { + self.tool.cursor(cx) + } + + fn command_form(&self) -> ToolPath { + self.tool.command_form() + } +} + impl CanvasTool for PerspectiveCropTool { fn press(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) -> ToolAction { let Some(space) = cx.space() else { return ToolAction::Ignored }; diff --git a/crates/draw/src/ui/mod.rs b/crates/draw/src/ui/mod.rs index e2a96a69f..96ebfe7ce 100644 --- a/crates/draw/src/ui/mod.rs +++ b/crates/draw/src/ui/mod.rs @@ -40,19 +40,21 @@ pub mod pattern; pub mod pen; pub mod picture_fill; pub mod shape; -pub mod shape_presets; pub mod shape_drag; +pub mod shape_presets; pub mod slice; pub mod stroke; pub mod symmetry; pub mod transform; pub use add_beside::{AddBesideHandles, AddBesideOutput, AddBesideWords, AddSide, add_beside_places}; +pub use artboard::ArtboardBarTarget; pub use artboard::{ ArtboardBackground, ArtboardBar, ArtboardBarOutput, ArtboardEvent, ArtboardItem, ArtboardPreset, ArtboardProperties, ArtboardPropertiesOutput, ArtboardRules, ArtboardTool, }; pub use brush_presets::{BrushPick, BrushPickerSettings, BrushPickerState, BrushPickerValues, BrushPresetPicker, BrushPresetPickerOutput}; +pub use brush_presets::{BrushesPanel, BrushesPanelOutput}; pub use brush_settings::{ BrushPanelAction, BrushSection, BrushSectionEvent, BrushSectionKind, BrushSectionList, BrushSettingsPanel, BrushSettingsPanelOutput, BrushSizeField, BrushStrokeStrip, DynamicControl, TipEllipse, @@ -67,34 +69,45 @@ pub use crop::{ CropOverlayMenu, CropPresetChoice, CropRatio, CropRatioChange, CropSession, CropSettings, CropSizePreset, CropTarget, CropTool, CropToolPass, CropUserPreset, CropWords, PerspectiveCropOutput, PerspectiveCropTool, ResolutionUnit, }; +pub use crop::{ + CropPresetList, CropPresetListOutput, CropSizeTarget, PerspectiveCropBar, PerspectiveCropBarOutput, PerspectiveCropPass, PerspectiveInput, +}; pub use crop::{PerspectiveCropQuad, PerspectiveQuad}; pub use gradient::{ ColorStop, GradientEditor, GradientExtent, GradientGroup, GradientItem, GradientLine, GradientMap, GradientMapEditor, GradientMapOutput, GradientOverlay, GradientPalette, GradientRamp, GradientRef, GradientStops, GradientSwatch, LineGradient, LinePart, OpacityStop, Sampler as StopSampler, StopDrop, StopRef, StopRow, StopRows, StopRules, default_sampler, }; +pub use gradient::{GradientFill, GradientFillEditor, GradientFillEditorOutput, GradientFillWords, GradientStyle}; pub use measure::{MIN_LINE, RulerBar, RulerBarOutput, RulerLine, RulerOverlay, RulerPass, RulerTool, RulerWords, box_distances, ruler_line_form}; +pub use paint_bar::{ + EraserMode, MIXER_COMBINATIONS, MIXER_GROUP_STARTS, MixerValues, PaintBar, PaintBarOutput, PaintBarWords, PaintTool, PaintValues, Smoothing, +}; +pub use paths::{PathKind, PathRow, PathsCommands, PathsEvent, PathsFooterButton, PathsOutput, PathsPanel, PathsWords}; pub use pattern::{ PatternColors, PatternFillDialog, PatternFillEditor, PatternFillOptions, PatternFillOutput, PatternSwatch, PatternWords, SwatchPainter, }; +pub use pen::{AnchorDelete, PenEnd}; pub use pen::{AnchorsShown, HitMark, PATH_OPTIONS_COLOR_KEY, PathMode, PathOptionsPopover, PathOptionsSettings, PathTool, PenMode, SegmentMark}; pub use pen::{ BezierHit, BezierOverlay, BezierStyle, BezierTool, EditPath, EditSubpath, HandleSide, HandlesShown, Knot, KnotRef, MAX_ANCHORS, PathEdit, PathSelection, PenStyle, }; pub use picture_fill::{PictureFill, PictureFillEditor, PictureFillOutput, PictureMode}; +pub use shape::{Arrowheads, ArrowheadsOutput, ArrowheadsPopover, LINE_WEIGHT_RANGE, RADIUS_RANGE, StrokeCells, VectorMode, VectorModeSelect}; pub use shape::{ ChipSetup, LiveShape, ShapeAppearance, ShapeBar, ShapeBarOutput, ShapeChange, ShapePaint, ShapePanel, ShapePanelOutput, ShapeToolSettings, ShapeWords, }; pub use shape_drag::{CreateShapeDialog, CreateShapeOptions, CreatedShape, ShapeDragEvent, ShapeDragOptions, ShapeDragTool, ShapeKind}; +pub use shape_presets::{ShapeMenu, ShapePresetWords}; pub use slice::{ DivideBy, DivideSlices, DivideSlicesDialog, SliceBar, SliceBarOutput, SliceCommand, SliceEvent, SliceItem, SliceKind, SliceMode, SliceOptions, SliceOptionsDialog, SliceOverlay, SliceTool, SliceToolSettings, }; -pub use stroke::{DashUnit, LineCap, LineJoin, LineStyle, StrokeAlign, StrokeButton, StrokeEditor, StrokePreview, StrokeStyle}; +pub use stroke::{DashAlign, DashUnit, LineCap, LineJoin, LineStyle, StrokeAlign, StrokeButton, StrokeEditor, StrokePreview, StrokeStyle}; pub use symmetry::{Symmetry, SymmetryChoice, SymmetryCommand, SymmetryEvent, SymmetryMenu, SymmetryMode, SymmetryOverlay, SymmetryTransform}; -pub use transform::{BarGroups, RotateZone, SizeUnit, TransformBox, TransformField, TransformFields, TransformRow}; +pub use transform::{ApplyBy, RotateZone, SizeUnit, TransformBox, TransformField, TransformFields, TransformGroups, TransformRow}; pub use transform::{ Interpolation, TransformBar, TransformBarOutput, TransformChoice, TransformEdit, TransformOverlay, TransformPhase, TransformPreset, TransformRequest, TransformResult, TransformSession, TransformSettings, TransformWarp, diff --git a/crates/draw/src/ui/pen/bezier/tools.rs b/crates/draw/src/ui/pen/bezier/tools.rs index 48404d64e..7ce06a7b9 100644 --- a/crates/draw/src/ui/pen/bezier/tools.rs +++ b/crates/draw/src/ui/pen/bezier/tools.rs @@ -70,7 +70,9 @@ pub(super) fn anchor_click(tool: BezierTool, hit: BezierHit, mods: Mods, report: // pc: crates/ui-egui/src/tools/anchor_tools.rs:88-114 `pointer`, `click`; :130-150 `apply`. match (hit, tool.acting(mods)) { (BezierHit::Segment { path, segment, t }, BezierTool::AddAnchor | BezierTool::AutoAddDelete) => report.insert = Some((path, segment, t)), - (BezierHit::Anchor { path, knot }, BezierTool::DeleteAnchor | BezierTool::AutoAddDelete) => report.delete = Some(AnchorDelete::new(path, vec![knot], false)), // P3(tools-w9): tl.T32 + (BezierHit::Anchor { path, knot }, BezierTool::DeleteAnchor | BezierTool::AutoAddDelete) => { + report.delete = Some(AnchorDelete::new(path, vec![knot], false)) + } // P3(tools-w9): tl.T32 _ => {} } } diff --git a/crates/draw/src/ui/pen/mod.rs b/crates/draw/src/ui/pen/mod.rs index dd0fc4e3f..b97a1354e 100644 --- a/crates/draw/src/ui/pen/mod.rs +++ b/crates/draw/src/ui/pen/mod.rs @@ -13,8 +13,8 @@ mod tool; mod words; pub use bezier::{ - AnchorDelete, AnchorsShown, BezierHit, BezierOutput, BezierOverlay, BezierStyle, BezierTool, BezierWords, EditPath, EditSubpath, HandleSide, HandlesShown, - HitMark, Knot, KnotRef, MAX_ANCHORS, PathEdit, PathSelection, SegmentMark, + AnchorDelete, AnchorsShown, BezierHit, BezierOutput, BezierOverlay, BezierStyle, BezierTool, BezierWords, EditPath, EditSubpath, HandleSide, + HandlesShown, HitMark, Knot, KnotRef, MAX_ANCHORS, PathEdit, PathSelection, SegmentMark, }; pub use mode::{PathMode, PathTool, PenMode}; pub use options::{PATH_OPTIONS_COLOR_KEY, PathOptionsOutput, PathOptionsPopover, PathOptionsSettings, PathOptionsWords}; diff --git a/crates/draw/src/ui/shape/mod.rs b/crates/draw/src/ui/shape/mod.rs index b609c003d..6e12ad925 100644 --- a/crates/draw/src/ui/shape/mod.rs +++ b/crates/draw/src/ui/shape/mod.rs @@ -14,16 +14,16 @@ mod arrowheads; mod bar; mod mode_select; mod panel; -mod stroke_cells; #[cfg(feature = "screen-testing")] pub(crate) mod stories; +mod stroke_cells; mod words; pub use arrowheads::{ArrowheadsOutput, ArrowheadsPopover}; -pub use mode_select::VectorModeSelect; -pub use stroke_cells::StrokeCells; pub use bar::{ShapeBar, ShapeBarOutput}; +pub use mode_select::VectorModeSelect; pub use panel::{ChipSetup, ShapePaint, ShapePanel, ShapePanelOutput}; +pub use stroke_cells::StrokeCells; pub use words::ShapeWords; /// The drawing mode of the vector tools. @@ -278,7 +278,15 @@ impl Default for ShapeToolSettings { /// Fill on, square corners, 5 sides, a plain polygon, weight 3, no stroke (PhotoCraft's /// `ToolOptions::default`, `state/tool_options.rs:405-412`). fn default() -> Self { - ShapeToolSettings { fill_on: true, corner_radius: 0.0, sides: 5, star_ratio: 1.0, line_weight: 3.0, stroke_width: 0.0, arrowheads: Arrowheads::default() } + ShapeToolSettings { + fill_on: true, + corner_radius: 0.0, + sides: 5, + star_ratio: 1.0, + line_weight: 3.0, + stroke_width: 0.0, + arrowheads: Arrowheads::default(), + } } } diff --git a/crates/draw/src/ui/shape/panel.rs b/crates/draw/src/ui/shape/panel.rs index 90e45956e..d3a897651 100644 --- a/crates/draw/src/ui/shape/panel.rs +++ b/crates/draw/src/ui/shape/panel.rs @@ -3,7 +3,7 @@ use std::ops::RangeInclusive; -use super::{RADIUS_RANGE, LiveShape, ShapeAppearance, ShapeChange, ShapeWords}; +use super::{LiveShape, RADIUS_RANGE, ShapeAppearance, ShapeChange, ShapeWords}; use crate::ui::stroke::StrokeButton; use craft_behavior::{EditEvent, EditEvents, NumberCodec}; use craft_color::ui::{Paint, PaintChip, PaintChipOutput, ScreenPickGesture}; @@ -11,8 +11,8 @@ use craft_theme::Srgba; use craft_ui::contract::{Bind, GlyphLabel, LabelKind, LabelScheme, Props as _, Show as _, ShowContainer as _, SideLabel}; use craft_ui::form::{Field, FieldGroup}; use craft_ui::layout_components::Row; -use craft_ui::runtime::requests::ColorRequest; use craft_ui::runtime::env::{Env, Label, LengthUnits, UnitKind, Units, with_env}; +use craft_ui::runtime::requests::ColorRequest; use craft_ui::sections::Section; use craft_ui::text::NumberField; use egui::Ui; diff --git a/crates/draw/src/ui/shape_presets.rs b/crates/draw/src/ui/shape_presets.rs index 91fc1b7b5..63c2e1523 100644 --- a/crates/draw/src/ui/shape_presets.rs +++ b/crates/draw/src/ui/shape_presets.rs @@ -1,9 +1,9 @@ //! The shape menu: the preset glyphs, their words and [`ShapeMenu`]. use crate::geometry::presets::ShapePreset; -use craft_ui::style::UiTokens; use craft_ui::primitives::Glyph; use craft_ui::runtime::env::Label; +use craft_ui::style::UiTokens; use egui::{Color32, Painter, Rect, Ui}; craft_ui::words! { diff --git a/crates/draw/src/ui/slice/bar.rs b/crates/draw/src/ui/slice/bar.rs index fe03af79d..b82c6d501 100644 --- a/crates/draw/src/ui/slice/bar.rs +++ b/crates/draw/src/ui/slice/bar.rs @@ -53,12 +53,19 @@ pub struct SliceBar<'a> { mode: SliceMode, settings: &'a mut SliceToolSettings, size_units: Option>, + locked: bool, } impl<'a> SliceBar<'a> { /// The members of `mode` over `settings`, which the Style, Width, Height and Hide Auto Slices write through. pub fn new(mode: SliceMode, settings: &'a mut SliceToolSettings) -> Self { - SliceBar { mode, settings, size_units: None } + SliceBar { mode, settings, size_units: None, locked: false } + } + + /// Shows the muted "slices are locked" notice after the members in both modes. + pub fn locked(mut self, on: bool) -> Self { + self.locked = on; + self } /// Shows Fixed Size in `unit`, with `units` in the units menu (the app's ruler units), converting through the @@ -70,7 +77,8 @@ impl<'a> SliceBar<'a> { /// Adds the members to the bar's row. pub fn show(self, ui: &mut Ui) -> SliceBarOutput { - let SliceBar { mode, settings, size_units } = self; + let SliceBar { mode, settings, size_units, locked } = self; + let _ = locked; // P3(tools-w19): tl.T57 let words = Env::of(ui).words::(); let text = |commands: &[SliceCommand]| { BarItems::new(commands.iter().map(|&command| BarItem::new(command).display(ItemDisplay::Text)).collect()).label(words.commands.clone()) diff --git a/crates/draw/src/ui/slice/tool.rs b/crates/draw/src/ui/slice/tool.rs index 0cfdbbf53..b28d3312d 100644 --- a/crates/draw/src/ui/slice/tool.rs +++ b/crates/draw/src/ui/slice/tool.rs @@ -39,6 +39,16 @@ pub struct SliceTool { events: Vec, drag: Option, ids: GestureId, + #[allow(dead_code)] // P3(tools-w19): tl.T57 + color: Option, +} + +impl SliceTool { + /// The colour the slice lines draw in; `None` is the theme's. + pub fn color(&mut self, color: Option) -> &mut Self { + self.color = color; + self + } } /// A new slice between presses. diff --git a/crates/draw/src/ui/stroke/mod.rs b/crates/draw/src/ui/stroke/mod.rs index 159944071..7eb02bec6 100644 --- a/crates/draw/src/ui/stroke/mod.rs +++ b/crates/draw/src/ui/stroke/mod.rs @@ -19,7 +19,7 @@ use craft_ui::primitives::ContentPainterCx; use craft_ui::runtime::env::Label; use egui::Rect; -pub use crate::stroke::{DashUnit, LineCap, LineJoin, LineStyle, StrokeAlign, StrokeError, StrokeStyle}; +pub use crate::stroke::{DashAlign, DashUnit, LineCap, LineJoin, LineStyle, StrokeAlign, StrokeError, StrokeStyle}; pub use button::StrokeButton; pub use editor::{StrokeEditor, StrokeEditorOutput}; pub use preview::StrokePreview; diff --git a/crates/draw/src/ui/transform/mod.rs b/crates/draw/src/ui/transform/mod.rs index 1aa6807cb..4ce3f4a75 100644 --- a/crates/draw/src/ui/transform/mod.rs +++ b/crates/draw/src/ui/transform/mod.rs @@ -13,5 +13,5 @@ pub use session::{ }; pub use session_bar::{BarSlot, TransformBar, TransformBarOutput, TransformBarWords}; pub use session_overlay::{TransformOverlay, TransformOverlayOutput, TransformTool}; -pub use transform_box::{BOX, RotateZone, TransformBox, TransformBoxOutput, TransformBoxStyle, TransformBoxWords}; -pub use transform_fields::{BarGroups, SizeUnit, TransformField, TransformFieldWords, TransformFields, TransformFieldsOutput, TransformRow}; +pub use transform_box::{ApplyBy, BOX, RotateZone, TransformBox, TransformBoxOutput, TransformBoxStyle, TransformBoxWords}; +pub use transform_fields::{SizeUnit, TransformField, TransformFieldWords, TransformFields, TransformFieldsOutput, TransformGroups, TransformRow}; diff --git a/crates/draw/src/ui/transform/session.rs b/crates/draw/src/ui/transform/session.rs index 862cd78af..514239466 100644 --- a/crates/draw/src/ui/transform/session.rs +++ b/crates/draw/src/ui/transform/session.rs @@ -238,8 +238,8 @@ impl TransformSession { /// The persisted section the session opens with: its interpolation and whether the reference /// point shows. - pub fn settings(mut self, settings: &TransformSettings) -> Self { - self.interpolation = settings.interpolation; + pub fn settings(mut self, settings: &TransformSettings, default_interpolation: Interpolation) -> Self { + self.interpolation = settings.interpolation.unwrap_or(default_interpolation); self.reference_point = settings.show_reference_point; self } diff --git a/crates/draw/src/ui/transform/session/settings.rs b/crates/draw/src/ui/transform/session/settings.rs index 607a4e7b9..f16fcb765 100644 --- a/crates/draw/src/ui/transform/session/settings.rs +++ b/crates/draw/src/ui/transform/session/settings.rs @@ -94,11 +94,13 @@ pub enum TransformChoice { Warp, /// Apply as [`TransformEdit::Preset`]. Preset(TransformPreset), + /// The app's menu row at this index in [`TransformOverlay::menu_rows`](super::super::TransformOverlay::menu_rows). + Row(usize), } /// Free Transform's persisted section: the app keeps it with its preferences. Unknown fields are /// ignored, missing ones take their defaults. -#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(default, rename_all = "camelCase")] #[non_exhaustive] pub struct TransformSettings { @@ -111,12 +113,29 @@ pub struct TransformSettings { /// Show Reference Point: off by default (Photoshop CC 2019 and later, LC2). Hidden, the point /// is not drawn, hit or picked; its stored position still pivots ⌥ scaling and rotating. pub show_reference_point: bool, - /// The interpolation a new session starts with. - pub interpolation: Interpolation, + /// The interpolation a new session starts with; `None` follows the General preference until one is picked. + pub interpolation: Option, /// The W and H fields' unit; percent when unset. Saved preferences may spell it as the legacy names /// (`"Pixels"`, `"Percent"`, `"Inches"`, `"Centimetres"`, `"Millimetres"`, `"Points"`, `"Picas"`). #[serde(deserialize_with = "unit_or_legacy")] pub size_unit: Option, + /// X and Y show and move the reference point's offset from where it started. + pub relative_position: bool, +} + +impl Default for TransformSettings { + /// Free Transform's defaults: proportions linked, no legacy scaling, the reference point hidden, interpolation + /// from the General preference. + fn default() -> Self { + TransformSettings { + legacy: false, + aspect_linked: true, + show_reference_point: false, + interpolation: None, + size_unit: None, + relative_position: false, + } + } } /// Reads a unit by the spelling `UnitKind` serializes to or by the legacy spelling, whatever the case. diff --git a/crates/draw/src/ui/transform/session_bar.rs b/crates/draw/src/ui/transform/session_bar.rs index ad95007bb..e949eabc3 100644 --- a/crates/draw/src/ui/transform/session_bar.rs +++ b/crates/draw/src/ui/transform/session_bar.rs @@ -4,7 +4,7 @@ mod stories; use super::session::{TransformEdit, TransformPhase, TransformSession, TransformSettings, TransformWarp}; -use super::transform_fields::{BarGroups, TransformFields, TransformRow, size_unit_of}; +use super::transform_fields::{TransformFields, TransformGroups, TransformRow, size_unit_of}; use craft_behavior::{EditEvent, IconId, Mixed, RulerUnits}; use craft_ui::bars::{Bar, BarKind}; use craft_ui::buttons::IconButton; @@ -95,7 +95,7 @@ pub struct TransformBar<'a, W> { label: Label, session: &'a TransformSession, settings: Bind<'a, TransformSettings>, - groups: BarGroups, + groups: TransformGroups, mode_switch: bool, warp_fields: Option>, extra: Option>, @@ -111,7 +111,7 @@ impl<'a, W: TransformWarp> TransformBar<'a, W> { label: label.into(), session, settings, - groups: BarGroups::ALL, + groups: TransformGroups::ALL, mode_switch: true, warp_fields: None, extra: None, @@ -121,7 +121,7 @@ impl<'a, W: TransformWarp> TransformBar<'a, W> { } /// Which groups of the fields show; all by default. - pub fn groups(mut self, groups: BarGroups) -> Self { + pub fn groups(mut self, groups: TransformGroups) -> Self { self.groups = groups; self } @@ -249,7 +249,7 @@ impl<'a, W: TransformWarp> TransformBar<'a, W> { } if let Some(choice) = shown.interpolation { edits.push(TransformEdit::Interpolation(choice)); - settings.interpolation = choice; + settings.interpolation = Some(choice); } if let Some(unit) = shown.unit_picked { settings.size_unit = Some(unit); diff --git a/crates/draw/src/ui/transform/session_overlay.rs b/crates/draw/src/ui/transform/session_overlay.rs index 1dda827d2..4ff997e67 100644 --- a/crates/draw/src/ui/transform/session_overlay.rs +++ b/crates/draw/src/ui/transform/session_overlay.rs @@ -9,14 +9,16 @@ use craft_behavior::geometry::SnapTargets; use craft_behavior::geometry::quad::{BoxPart, BoxRules}; use craft_keymap::Mods; use craft_ui::canvas::{CanvasTool, ToolAction, ToolContext, ToolKey, ToolPath, ToolPointer}; -use craft_ui::contract::Bind; use craft_ui::contract::Show as _; +use craft_ui::contract::{Bind, Entry}; use craft_ui::menu::Menu; use craft_ui::primitives::Draw; use craft_ui::runtime::env::{Env, Label}; use egui::{Rect, Ui}; -use super::{TransformBox, TransformChoice, TransformEdit, TransformMenuWords, TransformPhase, TransformSession, TransformSettings, TransformWarp}; +use super::{ + ApplyBy, TransformBox, TransformChoice, TransformEdit, TransformMenuWords, TransformPhase, TransformSession, TransformSettings, TransformWarp, +}; /// What the overlay reported this pass. #[derive(Debug)] @@ -25,11 +27,15 @@ pub struct TransformOverlayOutput { /// The edits in the order they happened; the app applies each with [`TransformSession::apply`]. pub edits: Vec>, /// Enter, a click outside or a double click inside: the app calls [`TransformSession::commit`] after the edits. - pub apply: bool, + pub apply: Option, /// Escape with no drag running: the app calls [`TransformSession::discard`] after the edits. pub discard: bool, /// The keyboard's picked part while the box has focus. pub picked: Option, + /// The snap lines of the point being dragged, from the box. + pub snapped: Vec, + /// The value of the app's menu row that was picked. + pub menu_row: Option, } /// The open [`TransformSession`]'s box on the canvas. @@ -55,12 +61,28 @@ pub struct TransformOverlay<'a, W> { pixel_grid: bool, snap: Option<&'a SnapTargets>, mods: Option, + #[allow(dead_code)] // P3(tools-w2): cw.C38 + menu_rows: &'a [Entry], + #[allow(dead_code)] // P3(tools-w2): tl.T62 + move_reach: f32, } impl<'a, W: TransformWarp> TransformOverlay<'a, W> { /// The overlay of `session` named `label`, with the box rules `settings` give. pub fn new(label: impl Into