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
This commit is contained in:
parent
9dbfb8ce4e
commit
e44f54f81f
|
|
@ -458,6 +458,8 @@ impl Painter {
|
||||||
|
|
||||||
fn tint_shape_towards(shape: &mut Shape, target: Color32) {
|
fn tint_shape_towards(shape: &mut Shape, target: Color32) {
|
||||||
epaint::shape_transform::adjust_colors(shape, &|color| {
|
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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::*;
|
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)) {
|
||||||
#![allow(clippy::match_same_arms)]
|
#![allow(clippy::match_same_arms)]
|
||||||
match shape {
|
match shape {
|
||||||
|
|
@ -9,28 +10,62 @@ pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) {
|
||||||
adjust_colors(shape, adjust_color);
|
adjust_colors(shape, adjust_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Shape::Circle(circle_shape) => {
|
Shape::LineSegment { stroke, points: _ } => {
|
||||||
adjust_color(&mut circle_shape.fill);
|
|
||||||
adjust_color(&mut circle_shape.stroke.color);
|
|
||||||
}
|
|
||||||
Shape::LineSegment { stroke, .. } => {
|
|
||||||
adjust_color(&mut stroke.color);
|
adjust_color(&mut stroke.color);
|
||||||
}
|
}
|
||||||
Shape::Path(path_shape) => {
|
|
||||||
adjust_color(&mut path_shape.fill);
|
Shape::Circle(CircleShape {
|
||||||
adjust_color(&mut path_shape.stroke.color);
|
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::Rect(rect_shape) => {
|
|
||||||
adjust_color(&mut rect_shape.fill);
|
Shape::Text(TextShape {
|
||||||
adjust_color(&mut rect_shape.stroke.color);
|
pos: _,
|
||||||
}
|
galley,
|
||||||
Shape::Text(text_shape) => {
|
underline,
|
||||||
if let Some(override_text_color) = &mut text_shape.override_text_color {
|
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);
|
adjust_color(override_text_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !text_shape.galley.is_empty() {
|
if !galley.is_empty() {
|
||||||
let galley = std::sync::Arc::make_mut(&mut text_shape.galley);
|
let galley = std::sync::Arc::make_mut(galley);
|
||||||
for row in &mut galley.rows {
|
for row in &mut galley.rows {
|
||||||
for vertex in &mut row.visuals.mesh.vertices {
|
for vertex in &mut row.visuals.mesh.vertices {
|
||||||
adjust_color(&mut vertex.color);
|
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);
|
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(_) => {
|
Shape::Callback(_) => {
|
||||||
// Can't tint user callback code
|
// Can't tint user callback code
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue