1use crate::{
2 geometry::vector::Vector2F, AfterLayoutContext, AppContext, Element, Event, EventContext,
3 LayoutContext, MutableAppContext, PaintContext, SizeConstraint,
4};
5
6pub struct Svg {
7 path: String,
8 // tree: Option<Rc<usvg::Tree>>,
9 size: Option<Vector2F>,
10}
11
12impl Svg {
13 pub fn new(path: String) -> Self {
14 Self {
15 path,
16 // tree: None,
17 size: None,
18 }
19 }
20}
21
22impl Element for Svg {
23 fn layout(
24 &mut self,
25 constraint: SizeConstraint,
26 ctx: &mut LayoutContext,
27 _: &AppContext,
28 ) -> Vector2F {
29 // let size;
30 // match ctx.asset_cache.svg(&self.path) {
31 // Ok(tree) => {
32 // size = if constraint.max.x().is_infinite() && constraint.max.y().is_infinite() {
33 // let rect = usvg_rect_to_euclid_rect(&tree.svg_node().view_box.rect);
34 // rect.size()
35 // } else {
36 // let max_size = constraint.max;
37 // let svg_size = usvg_rect_to_euclid_rect(&tree.svg_node().view_box.rect).size();
38
39 // if max_size.x().is_infinite()
40 // || max_size.x() / max_size.y() > svg_size.x() / svg_size.y()
41 // {
42 // vec2f(svg_size.x() * max_size.y() / svg_size.y(), max_size.y())
43 // } else {
44 // vec2f(max_size.x(), svg_size.y() * max_size.x() / svg_size.x())
45 // }
46 // };
47 // self.tree = Some(tree);
48 // }
49 // Err(error) => {
50 // log::error!("{}", error);
51 // size = constraint.min;
52 // }
53 // };
54
55 // self.size = Some(size);
56 // size
57 todo!()
58 }
59
60 fn after_layout(&mut self, _: &mut AfterLayoutContext, _: &mut MutableAppContext) {}
61
62 fn paint(&mut self, origin: Vector2F, ctx: &mut PaintContext, _: &AppContext) {
63 // if let Some(tree) = self.tree.as_ref() {
64 // ctx.canvas
65 // .draw_svg(tree, RectF::new(origin, self.size.unwrap()));
66 // }
67 }
68
69 fn size(&self) -> Option<Vector2F> {
70 self.size
71 }
72
73 fn dispatch_event(&self, _: &Event, _: &mut EventContext, _: &AppContext) -> bool {
74 false
75 }
76}