mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 07:03:14 -04:00
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo cranky`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> This PR simply allows you to override the opacity of a Galley when you draw it on screen. Last year I opened #3548 and some changes were requested to the PR, but unfortunately school got really busy and I wasn't able to apply them. This PR supersedes #3548 and applys the changes requested in that PR Closes #3548
93 lines
2.4 KiB
Rust
93 lines
2.4 KiB
Rust
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 {
|
|
Shape::Noop => {}
|
|
Shape::Vec(shapes) => {
|
|
for shape in shapes {
|
|
adjust_colors(shape, adjust_color);
|
|
}
|
|
}
|
|
Shape::LineSegment { stroke, points: _ } => {
|
|
adjust_color(&mut 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(TextShape {
|
|
pos: _,
|
|
galley,
|
|
underline,
|
|
fallback_color,
|
|
override_text_color,
|
|
opacity_factor: _,
|
|
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 !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 {
|
|
indices: _,
|
|
vertices,
|
|
texture_id: _,
|
|
}) => {
|
|
for v in vertices {
|
|
adjust_color(&mut v.color);
|
|
}
|
|
}
|
|
|
|
Shape::Callback(_) => {
|
|
// Can't tint user callback code
|
|
}
|
|
}
|
|
}
|