mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Better handle additive colors in plots (#3387)
This commit is contained in:
@@ -155,6 +155,12 @@ impl Color32 {
|
|||||||
Self([r, g, b, 0])
|
Self([r, g, b, 0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is the alpha=0 ?
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn is_additive(self) -> bool {
|
||||||
|
self.a() == 0
|
||||||
|
}
|
||||||
|
|
||||||
/// Premultiplied RGBA
|
/// Premultiplied RGBA
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub const fn to_array(&self) -> [u8; 4] {
|
pub const fn to_array(&self) -> [u8; 4] {
|
||||||
|
|||||||
@@ -122,6 +122,12 @@ impl Rgba {
|
|||||||
Self([r, g, b, 0.0])
|
Self([r, g, b, 0.0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Is the alpha=0 ?
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn is_additive(self) -> bool {
|
||||||
|
self.a() == 0.0
|
||||||
|
}
|
||||||
|
|
||||||
/// Multiply with e.g. 0.5 to make us half transparent
|
/// Multiply with e.g. 0.5 to make us half transparent
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn multiply(self, alpha: f32) -> Self {
|
pub fn multiply(self, alpha: f32) -> Self {
|
||||||
|
|||||||
@@ -58,8 +58,16 @@ pub(super) trait RectElement {
|
|||||||
|
|
||||||
pub(super) fn highlighted_color(mut stroke: Stroke, fill: Color32) -> (Stroke, Color32) {
|
pub(super) fn highlighted_color(mut stroke: Stroke, fill: Color32) -> (Stroke, Color32) {
|
||||||
stroke.width *= 2.0;
|
stroke.width *= 2.0;
|
||||||
let fill = Rgba::from(fill);
|
|
||||||
let fill_alpha = (2.0 * fill.a()).at_most(1.0);
|
let mut fill = Rgba::from(fill);
|
||||||
let fill = fill.to_opaque().multiply(fill_alpha);
|
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())
|
(stroke, fill.into())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user