diff --git a/crates/color/src/ui/paint_chip.rs b/crates/color/src/ui/paint_chip.rs index 1d5f77a5b..428fecf87 100644 --- a/crates/color/src/ui/paint_chip.rs +++ b/crates/color/src/ui/paint_chip.rs @@ -88,12 +88,21 @@ craft_ui::words! { pub struct GradientPreview { /// Stops as (position 0–1, colour), ascending by position. pub stops: Vec<(f32, Srgba)>, + /// Whether the host's gradient runs end to start. The ramp keeps the stops as given; the flag is part of the + /// preview's value so that a Reverse edit, which leaves the stops alone, still changes the paint the chip sets. + pub reverse: bool, } impl GradientPreview { - /// A preview through `stops`. + /// A preview through `stops`, not reversed. pub fn new(stops: Vec<(f32, Srgba)>) -> Self { - GradientPreview { stops } + GradientPreview { stops, reverse: false } + } + + /// The preview with the gradient reversed or not. + pub fn reversed(mut self, reverse: bool) -> Self { + self.reverse = reverse; + self } } diff --git a/crates/ui-contract/src/testing/frames.rs b/crates/ui-contract/src/testing/frames.rs index 7474aee89..8aab100f3 100644 --- a/crates/ui-contract/src/testing/frames.rs +++ b/crates/ui-contract/src/testing/frames.rs @@ -18,6 +18,8 @@ pub struct Frames { /// The context the frames run on. pub ctx: Context, time: f64, + /// Whether a frame leaves the clock where it is: only [`Frames::advance`] moves it on. + still: bool, /// The time of the last frame these frames ran, to tell when another driver of the context has run it since. given: f64, root: RootEnv, @@ -108,6 +110,7 @@ impl Frames { Frames { ctx, time: 0.0, + still: false, given: 0.0, root: RootEnv::default(), cursor: egui::CursorIcon::Default, @@ -228,6 +231,12 @@ impl Frames { self.files.dropped = names.iter().map(|name| (*name).to_owned()).collect(); } + /// Keeps the clock still: a frame no longer moves it on, so time passes only where a test calls + /// [`advance`](Self::advance). Held-pointer repeats, hover delays and animations then wait for the test. + pub fn still_clock(&mut self) { + self.still = true; + } + /// Moves the clock on by `seconds` before the next frame. pub fn advance(&mut self, seconds: f64) { self.time += seconds; @@ -248,7 +257,9 @@ impl Frames { if context > self.given { self.time = self.time.max(context); } - self.time += DT; + if !self.still { + self.time += DT; + } self.given = self.time; }