Skip to content

Commit

Permalink
Fix text color of disabled widgets (#3744)
Browse files Browse the repository at this point in the history
* Introduced recently in #3727
* Closes #3732
  • Loading branch information
emilk authored Dec 28, 2023
1 parent 9dbfb8c commit e44f54f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 27 deletions.
4 changes: 3 additions & 1 deletion crates/egui/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
85 changes: 59 additions & 26 deletions crates/epaint/src/shape_transform.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -9,48 +10,80 @@ 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);
}
}
}
}
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
}
Expand Down

0 comments on commit e44f54f

Please sign in to comment.