mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 15:28:04 +08:00
* Rename the "Table" type to "List" everywhere * Fix a few missed ones * Re-save demo artwork
50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
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 core_types::list::List;
|
|
use raster_types::{CPU, Raster};
|
|
use vector_types::GradientStops;
|
|
|
|
impl Adjust<Color> for List<Raster<CPU>> {
|
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
for element in self.iter_element_values_mut() {
|
|
for color in element.data_mut().data.iter_mut() {
|
|
*color = map_fn(color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
impl Adjust<Color> for List<Color> {
|
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
for element in self.iter_element_values_mut() {
|
|
*element = map_fn(element);
|
|
}
|
|
}
|
|
}
|
|
impl Adjust<Color> for List<GradientStops> {
|
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
for element in self.iter_element_values_mut() {
|
|
element.adjust(&map_fn);
|
|
}
|
|
}
|
|
}
|
|
impl Adjust<Color> for GradientStops {
|
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
|
for color in self.color.iter_mut() {
|
|
*color = map_fn(color);
|
|
}
|
|
}
|
|
}
|
|
}
|