Implement SVG rendering

This commit is contained in:
Antonio Scandurra
2021-04-06 13:46:33 +02:00
parent 2970e934da
commit e0c43dac25
9 changed files with 505 additions and 49 deletions
+22 -1
View File
@@ -10,12 +10,13 @@ pub struct Scene {
active_layer_stack: Vec<usize>,
}
#[derive(Default, Debug)]
#[derive(Default)]
pub struct Layer {
clip_bounds: Option<RectF>,
quads: Vec<Quad>,
shadows: Vec<Shadow>,
glyphs: Vec<Glyph>,
icons: Vec<Icon>,
paths: Vec<Path>,
}
@@ -44,6 +45,13 @@ pub struct Glyph {
pub color: ColorU,
}
pub struct Icon {
pub bounds: RectF,
pub svg: usvg::Tree,
pub path: String,
pub color: ColorU,
}
#[derive(Clone, Copy, Default, Debug)]
pub struct Border {
pub width: f32,
@@ -107,6 +115,10 @@ impl Scene {
self.active_layer().push_glyph(glyph)
}
pub fn push_icon(&mut self, icon: Icon) {
self.active_layer().push_icon(icon)
}
pub fn push_path(&mut self, path: Path) {
self.active_layer().push_path(path);
}
@@ -123,6 +135,7 @@ impl Layer {
quads: Vec::new(),
shadows: Vec::new(),
glyphs: Vec::new(),
icons: Vec::new(),
paths: Vec::new(),
}
}
@@ -155,6 +168,14 @@ impl Layer {
self.glyphs.as_slice()
}
pub fn push_icon(&mut self, icon: Icon) {
self.icons.push(icon);
}
pub fn icons(&self) -> &[Icon] {
self.icons.as_slice()
}
fn push_path(&mut self, path: Path) {
if !path.bounds.is_empty() {
self.paths.push(path);