Add Color trait

This commit is contained in:
grovesNL 2022-05-09 22:40:00 -02:30
parent 63a1a8f7ce
commit 5605879164
2 changed files with 35 additions and 16 deletions

View file

@ -28,6 +28,10 @@ use wgpu::{
pub use fontdue;
pub trait Color: Copy {
fn color(&self) -> [u8; 4];
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PrepareError {
AtlasFull,
@ -86,7 +90,7 @@ pub struct Params {
fn try_allocate(
atlas_packer: &mut BucketedAtlasAllocator,
layout: &Layout,
layout: &Layout<impl Color>,
glyph_cache: &mut HashMap<GlyphRasterConfig, GlyphDetails>,
width: usize,
height: usize,
@ -346,7 +350,7 @@ impl TextRenderer {
queue: &Queue,
screen_resolution: Resolution,
fonts: &[Font],
layouts: &[&Layout],
layouts: &[&Layout<impl Color>],
) -> Result<(), PrepareError> {
if screen_resolution != self.params.screen_resolution {
self.params.screen_resolution = screen_resolution;
@ -485,7 +489,7 @@ impl TextRenderer {
pos: [glyph.x.round() as u32, glyph.y.round() as u32],
dim: [details.width, details.height],
uv: [atlas_x, atlas_y],
color: [255, 255, 0, 255],
color: glyph.user_data.color(),
})
.take(4),
);