mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Added ability to define colors at UV coordinates along a path (#4353)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo cranky`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> I had to make a couple types not Copy because closures, but it should'nt be a massive deal. I tried my best to make the API change as non breaking as possible. Anywhere a PathStroke is used, you can just use a normal Stroke instead. As mentioned above, the bezier paths couldn't be copy anymore, but IMO that's a minor caveat. --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// Remember to handle [`Color32::PLACEHOLDER`] specially!
|
||||
pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) {
|
||||
pub fn adjust_colors(
|
||||
shape: &mut Shape,
|
||||
adjust_color: impl Fn(&mut Color32) + Send + Sync + Copy + 'static,
|
||||
) {
|
||||
#![allow(clippy::match_same_arms)]
|
||||
match shape {
|
||||
Shape::Noop => {}
|
||||
@@ -10,8 +15,48 @@ pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) {
|
||||
adjust_colors(shape, adjust_color);
|
||||
}
|
||||
}
|
||||
Shape::LineSegment { stroke, points: _ } => {
|
||||
adjust_color(&mut stroke.color);
|
||||
Shape::LineSegment { stroke, points: _ } => match &stroke.color {
|
||||
color::ColorMode::Solid(mut col) => adjust_color(&mut col),
|
||||
color::ColorMode::UV(callback) => {
|
||||
let callback = callback.clone();
|
||||
stroke.color = color::ColorMode::UV(Arc::new(Box::new(move |rect, pos| {
|
||||
let mut col = callback(rect, pos);
|
||||
adjust_color(&mut col);
|
||||
col
|
||||
})));
|
||||
}
|
||||
},
|
||||
|
||||
Shape::Path(PathShape {
|
||||
points: _,
|
||||
closed: _,
|
||||
fill,
|
||||
stroke,
|
||||
})
|
||||
| Shape::QuadraticBezier(QuadraticBezierShape {
|
||||
points: _,
|
||||
closed: _,
|
||||
fill,
|
||||
stroke,
|
||||
})
|
||||
| Shape::CubicBezier(CubicBezierShape {
|
||||
points: _,
|
||||
closed: _,
|
||||
fill,
|
||||
stroke,
|
||||
}) => {
|
||||
adjust_color(fill);
|
||||
match &stroke.color {
|
||||
color::ColorMode::Solid(mut col) => adjust_color(&mut col),
|
||||
color::ColorMode::UV(callback) => {
|
||||
let callback = callback.clone();
|
||||
stroke.color = color::ColorMode::UV(Arc::new(Box::new(move |rect, pos| {
|
||||
let mut col = callback(rect, pos);
|
||||
adjust_color(&mut col);
|
||||
col
|
||||
})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Shape::Circle(CircleShape {
|
||||
@@ -26,12 +71,6 @@ pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) {
|
||||
fill,
|
||||
stroke,
|
||||
})
|
||||
| Shape::Path(PathShape {
|
||||
points: _,
|
||||
closed: _,
|
||||
fill,
|
||||
stroke,
|
||||
})
|
||||
| Shape::Rect(RectShape {
|
||||
rect: _,
|
||||
rounding: _,
|
||||
@@ -40,18 +79,6 @@ pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) {
|
||||
blur_width: _,
|
||||
fill_texture_id: _,
|
||||
uv: _,
|
||||
})
|
||||
| Shape::QuadraticBezier(QuadraticBezierShape {
|
||||
points: _,
|
||||
closed: _,
|
||||
fill,
|
||||
stroke,
|
||||
})
|
||||
| Shape::CubicBezier(CubicBezierShape {
|
||||
points: _,
|
||||
closed: _,
|
||||
fill,
|
||||
stroke,
|
||||
}) => {
|
||||
adjust_color(fill);
|
||||
adjust_color(&mut stroke.color);
|
||||
|
||||
Reference in New Issue
Block a user