mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +08:00
* Rework Gradient into a newtype of List<Color> with optional position and midpoint attributes * Fix Vello stopless-gradient fallback coverage, empty legacy gradient tables, the node docs gradient swatch, NaN position elision, and wired setter input overwrites
31 lines
671 B
Rust
31 lines
671 B
Rust
use no_std_types::color::Color;
|
|
|
|
pub trait Adjust<P> {
|
|
fn adjust(&mut self, map_fn: impl Fn(&P) -> P);
|
|
}
|
|
impl Adjust<Color> for Color {
|
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
*self = map_fn(self);
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
mod adjust_std {
|
|
use super::*;
|
|
use raster_types::{CPU, Raster};
|
|
use vector_types::Gradient;
|
|
|
|
impl Adjust<Color> for Raster<CPU> {
|
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
for color in self.data_mut().data.iter_mut() {
|
|
*color = map_fn(color);
|
|
}
|
|
}
|
|
}
|
|
impl Adjust<Color> for Gradient {
|
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
*self = self.map_colors(map_fn);
|
|
}
|
|
}
|
|
}
|