Add color inverting support

This commit is contained in:
Isaac Mills 2025-02-17 11:41:48 -07:00
parent 9707e9c6cf
commit 675f627c9c
Signed by: fnmain
GPG key ID: B67D7410F33A0F61
2 changed files with 10 additions and 4 deletions

View file

@ -121,6 +121,8 @@ pub struct TextArea<'a> {
pub default_color: Color,
/// The opacity of the text
pub opacity: f32,
/// The amount to invert the color
pub invert: f32,
/// Additional custom glyphs to render.
pub custom_glyphs: &'a [CustomGlyph],
}

View file

@ -247,10 +247,14 @@ impl TextRenderer {
None => text_area.default_color,
};
let color = Color::rgba(
(color.r() as f32 * text_area.opacity + 0.5) as u8,
(color.g() as f32 * text_area.opacity + 0.5) as u8,
(color.b() as f32 * text_area.opacity + 0.5) as u8,
(color.a() as f32 * text_area.opacity + 0.5) as u8,
((text_area.invert - color.r() as f32).abs() * text_area.opacity + 0.5)
as u8,
((text_area.invert - color.g() as f32).abs() * text_area.opacity + 0.5)
as u8,
((text_area.invert - color.b() as f32).abs() * text_area.opacity + 0.5)
as u8,
((text_area.invert - color.a() as f32).abs() * text_area.opacity + 0.5)
as u8,
);
if let Some(glyph_to_render) = prepare_glyph(