WIP: Start on rendering glyphs

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-03-23 15:15:41 +01:00
co-authored by Nathan Sobo
parent 43abd96769
commit 764bfba2e2
9 changed files with 211 additions and 65 deletions
+27 -2
View File
@@ -1,6 +1,9 @@
use core::f32;
use crate::{
color::ColorU,
fonts::{FontId, GlyphId},
geometry::{rect::RectF, vector::Vector2F},
};
use crate::{color::ColorU, geometry::rect::RectF};
pub struct Scene {
scale_factor: f32,
layers: Vec<Layer>,
@@ -12,6 +15,7 @@ pub struct Layer {
clip_bounds: Option<RectF>,
quads: Vec<Quad>,
shadows: Vec<Shadow>,
glyphs: Vec<Glyph>,
}
#[derive(Default, Debug)]
@@ -30,6 +34,15 @@ pub struct Shadow {
pub color: ColorU,
}
#[derive(Debug)]
pub struct Glyph {
pub font_id: FontId,
pub font_size: f32,
pub glyph_id: GlyphId,
pub origin: Vector2F,
pub color: ColorU,
}
#[derive(Clone, Copy, Default, Debug)]
pub struct Border {
pub width: f32,
@@ -76,6 +89,10 @@ impl Scene {
self.active_layer().push_shadow(shadow)
}
pub fn push_glyph(&mut self, glyph: Glyph) {
self.active_layer().push_glyph(glyph)
}
fn active_layer(&mut self) -> &mut Layer {
&mut self.layers[*self.active_layer_stack.last().unwrap()]
}
@@ -97,6 +114,14 @@ impl Layer {
pub fn shadows(&self) -> &[Shadow] {
self.shadows.as_slice()
}
fn push_glyph(&mut self, glyph: Glyph) {
self.glyphs.push(glyph);
}
pub fn glyphs(&self) -> &[Glyph] {
self.glyphs.as_slice()
}
}
impl Border {