Set default_color per TextArea

This commit is contained in:
Héctor Ramón Jiménez 2023-02-27 03:31:34 +01:00 committed by Josh Groves
parent 1dcb1735b4
commit 1f31586c55
3 changed files with 6 additions and 7 deletions

View file

@ -117,8 +117,8 @@ async fn run() {
right: 600, right: 600,
bottom: 160, bottom: 160,
}, },
default_color: Color::rgb(255, 255, 255),
}], }],
Color::rgb(255, 255, 255),
&mut cache, &mut cache,
) )
.unwrap(); .unwrap();

View file

@ -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 /// 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. /// match the `left` and `top` values.
pub bounds: TextBounds, pub bounds: TextBounds,
// The default color of the text area.
pub default_color: Color,
} }

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
CacheKey, Color, GlyphDetails, GlyphToRender, GpuCacheStatus, Params, PrepareError, CacheKey, GlyphDetails, GlyphToRender, GpuCacheStatus, Params, PrepareError, RenderError,
RenderError, Resolution, SwashCache, SwashContent, TextArea, TextAtlas, Resolution, SwashCache, SwashContent, TextArea, TextAtlas,
}; };
use std::{collections::HashSet, iter, mem::size_of, num::NonZeroU32, slice, sync::Arc}; use std::{collections::HashSet, iter, mem::size_of, num::NonZeroU32, slice, sync::Arc};
use wgpu::{ use wgpu::{
@ -70,7 +70,6 @@ impl TextRenderer {
atlas: &mut TextAtlas, atlas: &mut TextAtlas,
screen_resolution: Resolution, screen_resolution: Resolution,
text_areas: &[TextArea<'a, 'b>], text_areas: &[TextArea<'a, 'b>],
default_color: Color,
cache: &mut SwashCache, cache: &mut SwashCache,
mut metadata_to_depth: impl FnMut(usize) -> f32, mut metadata_to_depth: impl FnMut(usize) -> f32,
) -> Result<(), PrepareError> { ) -> Result<(), PrepareError> {
@ -319,7 +318,7 @@ impl TextRenderer {
let color = match glyph.color_opt { let color = match glyph.color_opt {
Some(some) => some, Some(some) => some,
None => default_color, None => text_area.default_color,
}; };
let depth = metadata_to_depth(glyph.metadata); let depth = metadata_to_depth(glyph.metadata);
@ -417,7 +416,6 @@ impl TextRenderer {
atlas: &mut TextAtlas, atlas: &mut TextAtlas,
screen_resolution: Resolution, screen_resolution: Resolution,
text_areas: &[TextArea<'a, 'b>], text_areas: &[TextArea<'a, 'b>],
default_color: Color,
cache: &mut SwashCache, cache: &mut SwashCache,
) -> Result<(), PrepareError> { ) -> Result<(), PrepareError> {
self.prepare_with_depth( self.prepare_with_depth(
@ -426,7 +424,6 @@ impl TextRenderer {
atlas, atlas,
screen_resolution, screen_resolution,
text_areas, text_areas,
default_color,
cache, cache,
zero_depth, zero_depth,
) )