From b93ae97d696b73f14407f2b8a959b435da697fb4 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 18:18:10 +0000 Subject: [PATCH] PresetPicker: a face thumbnail painter the host gives for the closed field; BrushPresetPicker's chip shows the app's current tip --- crates/draw/src/ui/brush_presets/picker.rs | 11 ++++++++- .../src/patterns/presets/picker.rs | 23 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/crates/draw/src/ui/brush_presets/picker.rs b/crates/draw/src/ui/brush_presets/picker.rs index a674ee444..711264ae7 100644 --- a/crates/draw/src/ui/brush_presets/picker.rs +++ b/crates/draw/src/ui/brush_presets/picker.rs @@ -14,7 +14,7 @@ use craft_ui::form::SliderField; use craft_ui::layout_components::{Row, Stack}; use craft_ui::menu::{Menu, MenuItem}; use craft_ui::patterns::presets::{ - CellShape, PickerField, PresetBrowser, PresetEvent, PresetFooterOptions, PresetPicker, PresetRow, PresetState, PresetView, + CellShape, PickerField, PresetBrowser, PresetEvent, PresetFooterOptions, PresetPicker, PresetRow, PresetState, PresetView, PreviewPaint, }; use craft_ui::primitives::IconSpec; use craft_ui::runtime::env::{Env, Label, UnitKind}; @@ -280,6 +280,10 @@ pub struct BrushPresetPicker<'a, K: Value + Eq + Hash> { /// App rows drawn under the head. #[prop(name = "rows", boxed = "FnOnce(&mut Ui) + 'a")] app_rows: Option>, + /// Paints the brush's current tip on the chip, as the app's engine draws it (its falloff, angle and roundness, a + /// sampled tip's shape); without it the chip shows the picked preset's tip. + #[prop] + tip: Option, } /// The app's own rows of the picker's gear menu. @@ -309,6 +313,7 @@ impl<'a, K: Value + Eq + Hash> BrushPresetPicker<'a, K> { compact: false, enabled: true, app_rows: None, + tip: None, } } @@ -335,6 +340,7 @@ impl<'a, K: Value + Eq + Hash> BrushPresetPicker<'a, K> { compact, enabled, mut app_rows, + tip: tip_paint, } = self; let env = Env::of(ui); let words = env.words::(); @@ -475,6 +481,9 @@ impl<'a, K: Value + Eq + Hash> BrushPresetPicker<'a, K> { if let Some(key) = resizable.clone() { picker = picker.resizable(key); } + if let Some(paint) = tip_paint.clone() { + picker = picker.face_thumb(paint); + } if let Some((at, open)) = opened_at.as_mut() { picker = picker.open_at(*at, open.reborrowed()); } diff --git a/crates/ui-patterns/src/patterns/presets/picker.rs b/crates/ui-patterns/src/patterns/presets/picker.rs index 9536f0324..bbc557008 100644 --- a/crates/ui-patterns/src/patterns/presets/picker.rs +++ b/crates/ui-patterns/src/patterns/presets/picker.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use super::browser::{BrowserTools, PresetBrowser, ThumbPainter}; use super::event::{PresetEvent, PresetOutput}; use super::footer::PresetFooterOptions; -use super::model::{CellShape, PresetRow, ThumbInfo}; +use super::model::{CellShape, PresetRow, PreviewPaint, ThumbInfo}; use super::state::{DefaultOpen, PresetState, PresetView}; use super::words::PresetWords; use crate::contract::{ @@ -221,6 +221,11 @@ pub struct PresetPicker<'a, K: Value + Eq + Hash + 'static> { /// Paints the popover's thumbnails (a swatch, a gradient ramp, a brush tip) in place of each row's own `preview`. #[prop(func = "Fn(&ContentPainterCx, Rect, ThumbInfo<'_, K>)")] preview: Option>, + /// Paints the thumbnail of the closed field in place of the picked preset's `preview`, whatever is picked: the + /// value the host holds when it is more than a preset (a brush's current tip). Without it the field shows the + /// picked preset's preview. + #[prop] + face_thumb: Option, /// The columns of the popover's grid: the popover is as wide as this many tiles, at least its field. #[prop] columns: u16, @@ -274,6 +279,7 @@ impl<'a, K: Value + Eq + Hash + 'static> PresetPicker<'a, K> { create_row: None, detach_row: None, preview: None, + face_thumb: None, columns: 6, resizable: None, opened_at: None, @@ -332,6 +338,7 @@ impl<'a, K: Value + Eq + Hash + 'static> PresetPicker<'a, K> { create_row, detach_row, preview, + face_thumb, columns, resizable, mut opened_at, @@ -354,6 +361,7 @@ impl<'a, K: Value + Eq + Hash + 'static> PresetPicker<'a, K> { placeholder: placeholder.clone(), display_name: display_name.clone(), caption: caption.clone(), + face_thumb: face_thumb.clone(), edit_face, open, toggle: false, @@ -526,6 +534,7 @@ struct PickerFace<'a, K: Value + Eq + Hash + 'static> { placeholder: Option