From f1028ec951efafbadb9d603029116c375ff83573 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 15 Nov 2026 11:54:39 +0000 Subject: [PATCH] fwb2-fix: ChipSetup shows the chip (cherry picked from commit 5e990c5c39922d19691fadd6c2e93965d578b39e) --- crates/draw/src/ui/shape/bar.rs | 8 +++++--- crates/draw/src/ui/shape/panel.rs | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/draw/src/ui/shape/bar.rs b/crates/draw/src/ui/shape/bar.rs index 70dce75b0..443498b90 100644 --- a/crates/draw/src/ui/shape/bar.rs +++ b/crates/draw/src/ui/shape/bar.rs @@ -4,7 +4,7 @@ use super::panel::{Cells, ChipSetup, NumberCell, SIDES_RANGE, sides_change}; use super::{LINE_WEIGHT_RANGE, RADIUS_RANGE, ShapeAppearance, ShapeChange, ShapePaint, ShapeToolSettings, ShapeWords, StrokeCells}; use crate::ui::shape_drag::ShapeKind; use craft_behavior::EditEvent; -use craft_color::ui::{PaintChip, ScreenPickGesture}; +use craft_color::ui::{PaintChip, PaintChipOutput, ScreenPickGesture}; use craft_theme::Srgba; use craft_ui::choice::Checkbox; use craft_ui::contract::{Bind, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing}; @@ -86,8 +86,10 @@ impl<'a> ShapeBar<'a> { self } - /// Decorates each paint chip before it shows (its Gradient, Pattern and Picture editors). - pub fn chips(mut self, setup: impl for<'b> FnMut(ShapePaint, PaintChip<'b>) -> PaintChip<'b> + 'a) -> Self { + /// Decorates and shows each paint chip (its Gradient, Pattern and Picture editors): `setup` gets the chip the + /// bar built and the `Ui` to show it in, and returns the chip's output. Inside the call the chip may borrow the + /// app's own state. + pub fn chips(mut self, setup: impl for<'b> FnMut(ShapePaint, PaintChip<'b>, &mut Ui) -> PaintChipOutput + 'a) -> Self { self.chips = Some(ChipSetup::new(setup)); self } diff --git a/crates/draw/src/ui/shape/panel.rs b/crates/draw/src/ui/shape/panel.rs index 212e65e42..136b9215c 100644 --- a/crates/draw/src/ui/shape/panel.rs +++ b/crates/draw/src/ui/shape/panel.rs @@ -29,11 +29,12 @@ pub enum ShapePaint { Stroke, } -/// The app's decoration of a paint chip before it shows: the Gradient, Pattern and Picture editors. -pub struct ChipSetup<'a>(Box FnMut(ShapePaint, PaintChip<'b>) -> PaintChip<'b> + 'a>); +/// The app's decoration of a paint chip (the Gradient, Pattern and Picture editors), which also shows it, so the +/// decoration's borrows of app state last only for the call. +pub struct ChipSetup<'a>(Box FnMut(ShapePaint, PaintChip<'b>, &mut Ui) -> PaintChipOutput + 'a>); impl<'a> ChipSetup<'a> { - pub(super) fn new(setup: impl for<'b> FnMut(ShapePaint, PaintChip<'b>) -> PaintChip<'b> + 'a) -> Self { + pub(super) fn new(setup: impl for<'b> FnMut(ShapePaint, PaintChip<'b>, &mut Ui) -> PaintChipOutput + 'a) -> Self { ChipSetup(Box::new(setup)) } } @@ -113,8 +114,10 @@ impl<'a> ShapePanel<'a> { self } - /// Decorates each paint chip before it shows (its Gradient, Pattern and Picture editors). - pub fn chips(mut self, setup: impl for<'b> FnMut(ShapePaint, PaintChip<'b>) -> PaintChip<'b> + 'a) -> Self { + /// Decorates and shows each paint chip (its Gradient, Pattern and Picture editors): `setup` gets the chip the + /// bar built and the `Ui` to show it in, and returns the chip's output. Inside the call the chip may borrow the + /// app's own state. + pub fn chips(mut self, setup: impl for<'b> FnMut(ShapePaint, PaintChip<'b>, &mut Ui) -> PaintChipOutput + 'a) -> Self { self.chips = Some(ChipSetup::new(setup)); self } @@ -317,10 +320,10 @@ impl<'p, 'a> Cells<'p, 'a> { if let Some((_, color)) = self.sampled.filter(|(target, _)| *target == which) { chip = chip.sampled(color); } - if let Some(setup) = self.chips.as_mut() { - chip = (setup.0)(which, chip); + match self.chips.as_mut() { + Some(setup) => (setup.0)(which, chip, ui), + None => chip.show(ui), } - chip.show(ui) } /// Takes a chip's output: its edit as a change, its eyedropper press and its full colour picker request.