From 3e59ee12086ddb4eaa64e4ec1a4526093abf1960 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 23:01:57 +0000 Subject: [PATCH] Pattern fill: a swatch carries the host's picture of its tile, which the editor paints; the painter fn and both thumbnails methods go --- crates/draw/src/ui/mod.rs | 4 +-- crates/draw/src/ui/pattern/dialog.rs | 19 ++---------- crates/draw/src/ui/pattern/editor.rs | 43 ++++++++------------------- crates/draw/src/ui/pattern/mod.rs | 18 ++++++++--- crates/draw/src/ui/pattern/stories.rs | 33 ++++++++++---------- 5 files changed, 49 insertions(+), 68 deletions(-) diff --git a/crates/draw/src/ui/mod.rs b/crates/draw/src/ui/mod.rs index 3b392dd2f..cff0a6c14 100644 --- a/crates/draw/src/ui/mod.rs +++ b/crates/draw/src/ui/mod.rs @@ -89,9 +89,7 @@ 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 pattern::{PatternColors, PatternFillDialog, PatternFillEditor, PatternFillOptions, PatternFillOutput, PatternSwatch, PatternWords}; pub use pen::{AnchorDelete, AnchorTool, PenEnd}; pub use pen::{AnchorsShown, HitMark, PATH_OPTIONS_COLOR_KEY, PathMode, PathOptionsPopover, PathOptionsSettings, PathTool, PenMode, SegmentMark}; pub use pen::{ diff --git a/crates/draw/src/ui/pattern/dialog.rs b/crates/draw/src/ui/pattern/dialog.rs index 5fe71528b..a24d21107 100644 --- a/crates/draw/src/ui/pattern/dialog.rs +++ b/crates/draw/src/ui/pattern/dialog.rs @@ -1,6 +1,6 @@ //! [`PatternFillDialog`]. -use super::editor::{ANGLE_RANGE, SwatchPainter}; +use super::editor::ANGLE_RANGE; use super::{PatternColors, PatternFillEditor, PatternFillOptions, PatternSwatch, PatternWords}; use craft_theme::Srgba; use craft_ui::contract::{Bind, CanvasGesture, Sampler as _, ShowContainer as _}; @@ -24,7 +24,6 @@ pub struct PatternFillDialog { initial: PatternFillOptions, current: PatternFillOptions, swatches: Vec, - thumbnails: Option, changed: bool, canvas: Option, /// Whether the dialog is open: bound to the form's open state, so the host's dialog closes with it. @@ -39,20 +38,12 @@ impl PatternFillDialog { initial: options.clone(), current: options, swatches, - thumbnails: None, changed: false, canvas: None, open: true, } } - /// Paints a swatch's tile (see [`PatternFillEditor::thumbnails`]). - #[must_use] - pub fn thumbnails(mut self, paint: SwatchPainter) -> Self { - self.thumbnails = Some(paint); - self - } - /// The canvas whose primary drag moves the pattern while Link with Layer is on: the body passes /// that gesture to it each pass. #[must_use] @@ -147,7 +138,7 @@ impl StackDialog for PatternFillDialog { fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { let words = Env::of(ui).words::(); - let PatternFillDialog { current, swatches, thumbnails, changed, canvas, open, .. } = self; + let PatternFillDialog { current, swatches, changed, canvas, open, .. } = self; let before = current.clone(); let form = FormDialog::new(words.title.clone(), Bind::bound(&mut *current)).opened(Bind::bound(open)); let shown = form.show(ui, |ui, _, value| { @@ -158,11 +149,7 @@ impl StackDialog for PatternFillDialog { if let (Some(canvas), true) = (*canvas, link) { cx.pass_canvas_gesture(canvas, CanvasGesture::PRIMARY); } - let mut editor = PatternFillEditor::new(words.pattern.clone(), Bind::bound(&mut *value), swatches); - if let Some(paint) = *thumbnails { - editor = editor.thumbnails(paint); - } - editor.show(ui); + PatternFillEditor::new(words.pattern.clone(), Bind::bound(&mut *value), swatches).show(ui); }); true }); diff --git a/crates/draw/src/ui/pattern/editor.rs b/crates/draw/src/ui/pattern/editor.rs index e9e7f29fa..7a0cc7612 100644 --- a/crates/draw/src/ui/pattern/editor.rs +++ b/crates/draw/src/ui/pattern/editor.rs @@ -21,18 +21,6 @@ use egui::{Rect, Response, Ui}; /// The angle of the dial runs over half a turn each way. pub(super) const ANGLE_RANGE: std::ops::RangeInclusive = -180.0..=180.0; -/// The host's painter of a swatch's tile. A `fn`, which captures nothing, so the presets that paint it key it by its -/// address. -pub type SwatchPainter = fn(&ContentPainterCx<'_>, Rect, &PatternSwatch); - -/// What the editor's presets are built from. -#[derive(craft_ui::contract::MemoProps)] -struct TileInputs<'a> { - swatches: &'a [PatternSwatch], - #[memo_props(hash = "a fn pointer: its address names the code, which captures nothing")] - thumbnails: Option, -} - /// What [`PatternFillEditor`] reports. #[derive(Debug)] #[non_exhaustive] @@ -63,7 +51,7 @@ impl Outcome for PatternFillOutput { /// Preset mode (`colors` set, PowerPoint's Pattern fill): a grid of the swatches, then Foreground and Background /// colour chips. /// -/// The tiles come from [`thumbnails`](Self::thumbnails); without it a tile shows the swatch's name. Keyboard: Tab +/// A tile shows its swatch's [`picture`](PatternSwatch::picture); without one, the swatch's name. Keyboard: Tab /// through the fields; the grid takes arrows. Right to left the rows mirror. The editor is the body a host passes to /// a paint chip's pattern editor. #[must_use = "show the editor with `show`"] @@ -72,29 +60,22 @@ pub struct PatternFillEditor<'a> { label: Label, options: Bind<'a, PatternFillOptions>, swatches: &'a [PatternSwatch], - thumbnails: Option, } impl<'a> PatternFillEditor<'a> { /// The editor named `label` over `options`, offering `swatches`. pub fn new(label: impl Into