From 1f31586c55ce36c70bea58161221d07b3c6d9f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 27 Feb 2023 03:31:34 +0100 Subject: [PATCH] Set `default_color` per `TextArea` --- examples/hello-world.rs | 2 +- src/lib.rs | 2 ++ src/text_render.rs | 9 +++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/hello-world.rs b/examples/hello-world.rs index cea61c0..5eb569c 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -117,8 +117,8 @@ async fn run() { right: 600, bottom: 160, }, + default_color: Color::rgb(255, 255, 255), }], - Color::rgb(255, 255, 255), &mut cache, ) .unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 13baf4b..1e235da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,4 +100,6 @@ pub struct TextArea<'a, 'b: '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. + pub default_color: Color, } diff --git a/src/text_render.rs b/src/text_render.rs index aab8b4e..aa9b583 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -1,6 +1,6 @@ use crate::{ - CacheKey, Color, GlyphDetails, GlyphToRender, GpuCacheStatus, Params, PrepareError, - RenderError, Resolution, SwashCache, SwashContent, TextArea, TextAtlas, + CacheKey, GlyphDetails, GlyphToRender, GpuCacheStatus, Params, PrepareError, RenderError, + Resolution, SwashCache, SwashContent, TextArea, TextAtlas, }; use std::{collections::HashSet, iter, mem::size_of, num::NonZeroU32, slice, sync::Arc}; use wgpu::{ @@ -70,7 +70,6 @@ impl TextRenderer { atlas: &mut TextAtlas, screen_resolution: Resolution, text_areas: &[TextArea<'a, 'b>], - default_color: Color, cache: &mut SwashCache, mut metadata_to_depth: impl FnMut(usize) -> f32, ) -> Result<(), PrepareError> { @@ -319,7 +318,7 @@ impl TextRenderer { let color = match glyph.color_opt { Some(some) => some, - None => default_color, + None => text_area.default_color, }; let depth = metadata_to_depth(glyph.metadata); @@ -417,7 +416,6 @@ impl TextRenderer { atlas: &mut TextAtlas, screen_resolution: Resolution, text_areas: &[TextArea<'a, 'b>], - default_color: Color, cache: &mut SwashCache, ) -> Result<(), PrepareError> { self.prepare_with_depth( @@ -426,7 +424,6 @@ impl TextRenderer { atlas, screen_resolution, text_areas, - default_color, cache, zero_depth, )