From e44f54f81f65a224c6cbd110f0defa94503d205d Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 28 Dec 2023 11:16:39 +0100 Subject: [PATCH] Fix text color of disabled widgets (#3744) * Introduced recently in https://github.com/emilk/egui/pull/3727 * Closes https://github.com/emilk/egui/issues/3732 --- crates/egui/src/painter.rs | 4 +- crates/epaint/src/shape_transform.rs | 85 +++++++++++++++++++--------- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index dfae0a92cfe..8d6e3e6a8d6 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 1b0e9c73e87..b36accb5a3f 100644 --- a/crates/epaint/src/shape_transform.rs +++ b/crates/epaint/src/shape_transform.rs @@ -1,5 +1,6 @@ use crate::*; +/// Remember 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 }