Skip to content

Commit

Permalink
Bug fix: ui opacity and gray-out not affecting strokes (#4581)
Browse files Browse the repository at this point in the history
Bug introduced in #4353
  • Loading branch information
emilk authored May 29, 2024
1 parent 16277eb commit 89968e6
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions crates/epaint/src/shape_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@ pub fn adjust_colors(
#![allow(clippy::match_same_arms)]
match shape {
Shape::Noop => {}

Shape::Vec(shapes) => {
for shape in shapes {
adjust_colors(shape, adjust_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::LineSegment { stroke, points: _ } => {
adjust_color_mode(&mut stroke.color, adjust_color);
}

Shape::Path(PathShape {
points: _,
Expand All @@ -46,17 +40,7 @@ pub fn adjust_colors(
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
})));
}
}
adjust_color_mode(&mut stroke.color, adjust_color);
}

Shape::Circle(CircleShape {
Expand Down Expand Up @@ -124,3 +108,20 @@ pub fn adjust_colors(
}
}
}

fn adjust_color_mode(
color_mode: &mut ColorMode,
adjust_color: impl Fn(&mut Color32) + Send + Sync + Copy + 'static,
) {
match color_mode {
color::ColorMode::Solid(color) => adjust_color(color),
color::ColorMode::UV(callback) => {
let callback = callback.clone();
*color_mode = color::ColorMode::UV(Arc::new(Box::new(move |rect, pos| {
let mut color = callback(rect, pos);
adjust_color(&mut color);
color
})));
}
}
}

0 comments on commit 89968e6

Please sign in to comment.