Add ability to debug element trees as JSON

This commit is contained in:
Nathan Sobo
2021-04-07 21:54:14 -06:00
parent 57a3207897
commit 0664321125
25 changed files with 554 additions and 41 deletions
+17 -2
View File
@@ -1,7 +1,8 @@
use crate::{
geometry::{rect::RectF, vector::Vector2F},
AfterLayoutContext, Element, ElementBox, Event, EventContext, LayoutContext, PaintContext,
SizeConstraint,
json::{self, json, ToJson},
AfterLayoutContext, DebugContext, Element, ElementBox, Event, EventContext, LayoutContext,
PaintContext, SizeConstraint,
};
pub struct Stack {
@@ -71,6 +72,20 @@ impl Element for Stack {
}
false
}
fn debug(
&self,
bounds: RectF,
_: &Self::LayoutState,
_: &Self::PaintState,
ctx: &DebugContext,
) -> json::Value {
json!({
"type": "Stack",
"bounds": bounds.to_json(),
"children": self.children.iter().map(|child| child.debug(ctx)).collect::<Vec<json::Value>>()
})
}
}
impl Extend<ElementBox> for Stack {