1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-28 07:23:13 -04:00

Better handle additive colors in plots (#3387)

This commit is contained in:
Emil Ernerfeldt
2023-09-25 15:45:32 +02:00
committed by GitHub
parent fdd493d48f
commit 8bf0055bda
3 changed files with 23 additions and 3 deletions

View File

@@ -58,8 +58,16 @@ pub(super) trait RectElement {
pub(super) fn highlighted_color(mut stroke: Stroke, fill: Color32) -> (Stroke, Color32) {
stroke.width *= 2.0;
let fill = Rgba::from(fill);
let fill_alpha = (2.0 * fill.a()).at_most(1.0);
let fill = fill.to_opaque().multiply(fill_alpha);
let mut fill = Rgba::from(fill);
if fill.is_additive() {
// Make slightly brighter
fill = 1.3 * fill;
} else {
// Make more opaque:
let fill_alpha = (2.0 * fill.a()).at_most(1.0);
fill = fill.to_opaque().multiply(fill_alpha);
}
(stroke, fill.into())
}