mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
33 lines
708 B
Rust
33 lines
708 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) {
|
|
for color in self.color.iter_mut() {
|
|
*color = map_fn(color);
|
|
}
|
|
}
|
|
}
|
|
}
|