WIP on rebuilding with extracted UI framework

This commit is contained in:
Nathan Sobo
2021-03-18 13:13:31 -06:00
parent 356bc41752
commit 23308e17a9
33 changed files with 2673 additions and 657 deletions
+1
View File
@@ -2,6 +2,7 @@ use crate::{
color::ColorU,
fonts::{FamilyId, Properties},
geometry::vector::{vec2f, Vector2F},
text_layout::Line,
AfterLayoutContext, AppContext, Element, Event, EventContext, LayoutContext, MutableAppContext,
PaintContext, SizeConstraint,
};
+5 -2
View File
@@ -49,7 +49,10 @@ pub trait Element {
fn dispatch_event(&self, event: &Event, ctx: &mut EventContext, app: &AppContext) -> bool;
fn boxed(self) -> Box<dyn Element> {
fn boxed(self) -> Box<dyn Element>
where
Self: 'static + Sized,
{
Box::new(self)
}
}
@@ -60,7 +63,7 @@ pub trait ParentElement<'a>: Extend<Box<dyn Element>> + Sized {
}
fn add_child(&mut self, child: Box<dyn Element>) {
self.add_childen(Some(child));
self.add_children(Some(child));
}
fn with_children(mut self, children: impl IntoIterator<Item = Box<dyn Element>>) -> Self {
+6 -11
View File
@@ -1,12 +1,7 @@
use crate::{
geometry::{
rect::RectF,
vector::{vec2f, Vector2F},
},
AfterLayoutContext, AppContext, Element, Event, EventContext, LayoutContext, MutableAppContext,
PaintContext, SizeConstraint,
geometry::vector::Vector2F, AfterLayoutContext, AppContext, Element, Event, EventContext,
LayoutContext, MutableAppContext, PaintContext, SizeConstraint,
};
use std::rc::Rc;
pub struct Svg {
path: String,
@@ -65,10 +60,10 @@ impl Element for Svg {
fn after_layout(&mut self, _: &mut AfterLayoutContext, _: &mut MutableAppContext) {}
fn paint(&mut self, origin: Vector2F, ctx: &mut PaintContext, _: &AppContext) {
if let Some(tree) = self.tree.as_ref() {
ctx.canvas
.draw_svg(tree, RectF::new(origin, self.size.unwrap()));
}
// if let Some(tree) = self.tree.as_ref() {
// ctx.canvas
// .draw_svg(tree, RectF::new(origin, self.size.unwrap()));
// }
}
fn size(&self) -> Option<Vector2F> {
+1 -1
View File
@@ -136,7 +136,7 @@ where
SizeConstraint::new(vec2f(size.x(), 0.0), vec2f(size.x(), f32::INFINITY));
let first_item = (self.build_items)(0..1, app).next();
if let Some(first_item) = first_item {
if let Some(mut first_item) = first_item {
let mut item_size = first_item.layout(item_constraint, ctx, app);
item_size.set_x(size.x());
item_constraint.min = item_size;