diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index dfae0a92cfe0..8d6e3e6a8d61 100644 --- a/crates/egui/src/painter.rs +++ b/crates/egui/src/painter.rs @@ -458,6 +458,8 @@ impl Painter { fn tint_shape_towards(shape: &mut Shape, target: Color32) { epaint::shape_transform::adjust_colors(shape, &|color| { - *color = crate::ecolor::tint_color_towards(*color, target); + if *color != Color32::PLACEHOLDER { + *color = crate::ecolor::tint_color_towards(*color, target); + } }); } diff --git a/crates/epaint/src/shape_transform.rs b/crates/epaint/src/shape_transform.rs index 1b0e9c73e872..1dcbc89b6060 100644 --- a/crates/epaint/src/shape_transform.rs +++ b/crates/epaint/src/shape_transform.rs @@ -1,5 +1,6 @@ use crate::*; +/// Remmeber to handle [`Color32::PLACEHOLDER`] specially! pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) { #![allow(clippy::match_same_arms)] match shape { @@ -9,28 +10,62 @@ pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) { adjust_colors(shape, adjust_color); } } - Shape::Circle(circle_shape) => { - adjust_color(&mut circle_shape.fill); - adjust_color(&mut circle_shape.stroke.color); - } - Shape::LineSegment { stroke, .. } => { + Shape::LineSegment { stroke, points: _ } => { adjust_color(&mut stroke.color); } - Shape::Path(path_shape) => { - adjust_color(&mut path_shape.fill); - adjust_color(&mut path_shape.stroke.color); - } - Shape::Rect(rect_shape) => { - adjust_color(&mut rect_shape.fill); - adjust_color(&mut rect_shape.stroke.color); + + Shape::Circle(CircleShape { + center: _, + radius: _, + fill, + stroke, + }) + | Shape::Path(PathShape { + points: _, + closed: _, + fill, + stroke, + }) + | Shape::Rect(RectShape { + rect: _, + rounding: _, + fill, + stroke, + 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); } - Shape::Text(text_shape) => { - if let Some(override_text_color) = &mut text_shape.override_text_color { + + Shape::Text(TextShape { + pos: _, + galley, + underline, + fallback_color, + override_text_color, + angle: _, + }) => { + adjust_color(&mut underline.color); + adjust_color(fallback_color); + if let Some(override_text_color) = override_text_color { adjust_color(override_text_color); } - if !text_shape.galley.is_empty() { - let galley = std::sync::Arc::make_mut(&mut text_shape.galley); + if !galley.is_empty() { + let galley = std::sync::Arc::make_mut(galley); for row in &mut galley.rows { for vertex in &mut row.visuals.mesh.vertices { adjust_color(&mut vertex.color); @@ -38,19 +73,17 @@ pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) { } } } - Shape::Mesh(mesh) => { - for v in &mut mesh.vertices { + + Shape::Mesh(Mesh { + indices: _, + vertices, + texture_id: _, + }) => { + for v in vertices { adjust_color(&mut v.color); } } - Shape::QuadraticBezier(quadratic) => { - adjust_color(&mut quadratic.fill); - adjust_color(&mut quadratic.stroke.color); - } - Shape::CubicBezier(bezier) => { - adjust_color(&mut bezier.fill); - adjust_color(&mut bezier.stroke.color); - } + Shape::Callback(_) => { // Can't tint user callback code }