diff --git a/crates/color-ui/src/ui/swatches/library.rs b/crates/color-ui/src/ui/swatches/library.rs index 6305353b2..caa848c68 100644 --- a/crates/color-ui/src/ui/swatches/library.rs +++ b/crates/color-ui/src/ui/swatches/library.rs @@ -575,9 +575,12 @@ impl SwatchLibrary { pub(super) struct HostThumb<'a> { key: u128, #[memo_props(covered_by = "key", reason = "the painter runs the host's `fn` over the host's inputs, and `key` holds both")] - paint: Box, Rect, ThumbInfo<'_, SwatchKey>) + Send + 'a>, + paint: Box>, } +/// The painter a [`HostThumb`] holds: the host's `fn` over its inputs. +type PaintThumb<'a> = dyn Fn(&ContentPainterCx<'_>, Rect, ThumbInfo<'_, SwatchKey>) + Send + 'a; + impl<'a> HostThumb<'a> { /// `paint` over `inputs`. pub(super) fn new(inputs: I, paint: ThumbFn) -> Self { diff --git a/crates/color-ui/src/ui/swatches/panel.rs b/crates/color-ui/src/ui/swatches/panel.rs index 225b7942e..1c9996fde 100644 --- a/crates/color-ui/src/ui/swatches/panel.rs +++ b/crates/color-ui/src/ui/swatches/panel.rs @@ -130,7 +130,6 @@ impl<'a> SwatchesPanel<'a> { /// Paints each swatch's thumbnail with `paint` over the host's `inputs` in place of the panel's own swatch face /// (the host's gradient and pattern previews), as `PresetFns::thumb` does: the inputs are all the painter reads, so /// the swatch list keys on them. The painter draws the selected state from `ThumbInfo::selected`. - #[must_use] pub fn thumb(mut self, inputs: I, paint: ThumbFn) -> Self { self.thumb = Some(HostThumb::new(inputs, paint)); self diff --git a/crates/print/src/ui/dialog.rs b/crates/print/src/ui/dialog.rs index 585db2a24..4d8fdd0a2 100644 --- a/crates/print/src/ui/dialog.rs +++ b/crates/print/src/ui/dialog.rs @@ -19,7 +19,8 @@ use craft_ui::patterns::form_dialogs::{ DialogFields, FieldValue, FormDialog, HostRequests, Param, ParamRows, SectionList, set_color_field, set_param_field, }; use craft_ui::patterns::presets::{ - NameCheck, NamedPresetEvent, NamedPresetRow, Naming, PickerField, PresetError, PresetPicker, PresetRow, PresetSource, PresetState, PresetWords, + NameCheck, NameRefuses, NamedPresetEvent, NamedPresetRow, Naming, PickerField, PresetError, PresetPicker, PresetRow, PresetSource, PresetState, + PresetWords, }; use craft_ui::runtime::env::{Env, Label, Message}; use craft_ui::runtime::focus::{ActivateKeys, KeepKeys, KeyUse}; @@ -516,7 +517,7 @@ fn preset_row( ui: &mut Ui, words: &PrintDialogWords, presets: &PrintPresets<'_>, - check: Option<&dyn Fn(&str) -> Option>, + check: Option<&NameRefuses<'_>>, picker: &mut PresetState, events: &mut Vec>, ) { @@ -533,7 +534,7 @@ fn preset_row( } /// The preset editor's name field with the host's refusal under it. Returns whether the name can be saved. -fn name_row(ui: &mut Ui, words: &PrintDialogWords, check: Option<&dyn Fn(&str) -> Option>, name: &mut Bind<'_, String>) -> bool { +fn name_row(ui: &mut Ui, words: &PrintDialogWords, check: Option<&NameRefuses<'_>>, name: &mut Bind<'_, String>) -> bool { let preset_words = Env::of(ui).words::(); let current = read(name).unwrap_or_default(); let host = check.map(NameCheck::of_host); @@ -618,8 +619,8 @@ pub struct PrintDialog<'a> { #[prop] preset_name: Option>, /// Whether a typed preset name may be used, in the preset editor. - #[prop(boxed)] - check_name: Option Option + 'a>>, + #[prop(boxed = "Fn(&str) -> Option + 'a")] + check_name: Option>>, /// The driver's Setup… button is shown, with [`PrintLayout::Sections`]. #[prop] driver: bool, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs index 09aabb958..eabf5c48d 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs @@ -25,8 +25,8 @@ use crate::form::{Field, FieldGroup}; use crate::list::ListRow; use crate::notices::{Notice, NoticeLayout}; use crate::patterns::presets::{ - NameCheck, NamedPresetEvent, NamedPresetRow, Naming, PickerField, PresetError, PresetFns, PresetPicker, PresetRow, PresetSource, PresetState, - PresetWords, + NameCheck, NameRefuses, NamedPresetEvent, NamedPresetRow, Naming, PickerField, PresetError, PresetFns, PresetPicker, PresetRow, PresetSource, + PresetState, PresetWords, }; use crate::pickers::Select; use crate::runtime::env::{Env, Label, Message, UnitKind}; @@ -342,8 +342,8 @@ pub struct PdfExportDialog<'a> { #[prop] preset_draft: Option>, /// Whether a typed preset name may be used, in the preset editor. - #[prop(boxed)] - check_name: Option Option + 'a>>, + #[prop(boxed = "Fn(&str) -> Option + 'a")] + check_name: Option>>, /// Binds the shown section. #[prop] section: Option>, diff --git a/crates/ui-patterns/src/patterns/presets/mod.rs b/crates/ui-patterns/src/patterns/presets/mod.rs index 2ad84ff48..ce5063511 100644 --- a/crates/ui-patterns/src/patterns/presets/mod.rs +++ b/crates/ui-patterns/src/patterns/presets/mod.rs @@ -30,7 +30,7 @@ pub use model::{ CellShape, GroupPath, PresetChange, PresetError, PresetGroup, PresetId, PresetItem, PresetKey, PresetKind, PresetLibrary, PresetNames, PresetRow, PresetRowMenu, PresetTiles, Preview, ThumbInfo, children_end, has_captions, nest_allowed, }; -pub use named::{NameCheck, NamedPresetCommands, NamedPresetEvent, NamedPresetOutput, NamedPresetRow, NamedPresetStyle, Naming}; +pub use named::{NameCheck, NameRefuses, NamedPresetCommands, NamedPresetEvent, NamedPresetOutput, NamedPresetRow, NamedPresetStyle, Naming}; pub use panel_menu::{PresetCommands, PresetMenuAction, PresetPanelMenu}; pub use picker::{PickerField, PickerHead, PresetPicker, PresetPickerOutput, PresetPickerStyle}; pub use source::{AcceptsFn, PresetFns, PresetSource, ThumbFn}; diff --git a/crates/ui-patterns/src/patterns/presets/named.rs b/crates/ui-patterns/src/patterns/presets/named.rs index 382393c31..38f37ba5c 100644 --- a/crates/ui-patterns/src/patterns/presets/named.rs +++ b/crates/ui-patterns/src/patterns/presets/named.rs @@ -61,6 +61,9 @@ pub enum NamedPresetStyle { Menu, } +/// A host's check of a typed preset name, as a closure: why it refuses the name, `None` when it accepts it. +pub type NameRefuses<'a> = dyn Fn(&str) -> Option + 'a; + /// Whether a name may be used: the host's answer for a typed name. pub struct NameCheck<'a>(Box); @@ -74,7 +77,7 @@ impl<'a> NameCheck<'a> { /// The host's `check`, a closure: a memoized view that holds it runs every pass, as no key can follow what the /// closure reads. - pub fn of_host(check: &'a dyn Fn(&str) -> Option) -> Self { + pub fn of_host(check: &'a NameRefuses<'a>) -> Self { NameCheck::new(HostCheck(check), |host, name| (host.0)(name)) } @@ -95,7 +98,7 @@ impl MemoProps for NameCheck<'_> { /// The inputs of [`NameCheck::of_host`]. #[derive(MemoProps)] #[memo_props(every_pass = "the host's name check is a closure, whose answers no key can follow")] -struct HostCheck<'a>(&'a dyn Fn(&str) -> Option); +struct HostCheck<'a>(&'a NameRefuses<'a>); /// A name check: its answer, and the key of its inputs and `fn`. trait NameChecker {