From 675f627c9c7f62e77c4063eac5ae7d2e2d4dc6cc Mon Sep 17 00:00:00 2001 From: Isaac Mills Date: Mon, 17 Feb 2025 11:41:48 -0700 Subject: [PATCH] Add color inverting support --- src/lib.rs | 2 ++ src/text_render.rs | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 02b5167..efbfa60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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], } diff --git a/src/text_render.rs b/src/text_render.rs index afc502d..99ba6b2 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -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(