From 01ab64704b123d1ae61a5022b2b8ea2a7a4573e8 Mon Sep 17 00:00:00 2001 From: Isaac Mills Date: Mon, 18 Mar 2024 18:30:28 -0400 Subject: [PATCH] Add opacity --- Cargo.toml | 2 +- src/lib.rs | 4 +++- src/text_render.rs | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 222c2be..8b158ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ license = "MIT OR Apache-2.0 OR Zlib" [dependencies] wgpu = "0.19" etagere = "0.2.10" -cosmic-text = "0.10" lru = "0.12.1" +cosmic-text = "0.11.2" [dev-dependencies] winit = { version = "0.29.10", features = ["rwh_05"] } diff --git a/src/lib.rs b/src/lib.rs index b9194c5..5b4dc51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,6 +111,8 @@ pub struct TextArea<'a> { /// The visible bounds of the text area. This is used to clip the text and doesn't have to /// match the `left` and `top` values. pub bounds: TextBounds, - // The default color of the text area. + /// The default color of the text area. pub default_color: Color, + /// The opacity to set the text area to (in gamma space) + pub opacity: f32, } diff --git a/src/text_render.rs b/src/text_render.rs index 9818bd1..8a1a595 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -268,6 +268,13 @@ impl TextRenderer { None => text_area.default_color, }; + let color = cosmic_text::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, + ); + let depth = metadata_to_depth(glyph.metadata); glyph_vertices.extend(