|
@@ -15,7 +15,7 @@ mod arr;
|
|
|
mod cache;
|
|
|
mod calc;
|
|
|
|
|
|
-pub use cache::{LayoutCache,LayoutNodeID};
|
|
|
+pub use cache::{LayoutCache, LayoutNodeID};
|
|
|
pub use calc::recalculate;
|
|
|
|
|
|
pub struct CellMarker;
|
|
@@ -441,37 +441,56 @@ pub fn dump_node_tree(lna: LayoutNodeAccess, out: &mut String) {
|
|
|
dump_node_tree_helper(lna, 0, out);
|
|
|
}
|
|
|
|
|
|
-pub fn dump_tree_json<W: ?Sized + std::io::Write>(lna: LayoutNodeAccess, out: &mut std::io::BufWriter<W>) -> std::io::Result<()> {
|
|
|
+pub fn dump_tree_json<W: ?Sized + std::io::Write>(
|
|
|
+ lna: LayoutNodeAccess,
|
|
|
+ out: &mut std::io::BufWriter<W>,
|
|
|
+) -> std::io::Result<()> {
|
|
|
use std::io::Write;
|
|
|
|
|
|
write!(out, "{{")?;
|
|
|
write!(out, "\"label\": \"{}\" ", lna.label().unwrap_or("null"))?;
|
|
|
- write!(out, ",\"id\": {} ", <LayoutNodeID as Into<usize>>::into(lna.id()))?;
|
|
|
+ write!(
|
|
|
+ out,
|
|
|
+ ",\"id\": {} ",
|
|
|
+ <LayoutNodeID as Into<usize>>::into(lna.id())
|
|
|
+ )?;
|
|
|
write!(out, ",\"behaviour\": \"{:?}\"", lna.behaviour())?;
|
|
|
write!(out, ",\"child_arrangement\": \"{:?}\"", lna.arrangement())?;
|
|
|
- write!(out, ",\"width_policy\": [{},{},{}]",
|
|
|
- lna.width_policy().minimum,
|
|
|
- lna.width_policy().desired,
|
|
|
- lna.width_policy().slack_weight)?;
|
|
|
- write!(out, ",\"height_policy\": [{},{},{}]",
|
|
|
- lna.height_policy().minimum,
|
|
|
- lna.height_policy().desired,
|
|
|
- lna.height_policy().slack_weight)?;
|
|
|
+ write!(
|
|
|
+ out,
|
|
|
+ ",\"width_policy\": [{},{},{}]",
|
|
|
+ lna.width_policy().minimum,
|
|
|
+ lna.width_policy().desired,
|
|
|
+ lna.width_policy().slack_weight
|
|
|
+ )?;
|
|
|
+ write!(
|
|
|
+ out,
|
|
|
+ ",\"height_policy\": [{},{},{}]",
|
|
|
+ lna.height_policy().minimum,
|
|
|
+ lna.height_policy().desired,
|
|
|
+ lna.height_policy().slack_weight
|
|
|
+ )?;
|
|
|
write!(out, ",\"halign\": \"{:?}\"", lna.halign())?;
|
|
|
write!(out, ",\"valign\": \"{:?}\"", lna.valign())?;
|
|
|
- write!(out, ",\"margin\": {{\"top\": {}, \"bottom\": {}, \"left\": {}, \"right\": {}}}",
|
|
|
- lna.margin().top,
|
|
|
- lna.margin().bottom,
|
|
|
- lna.margin().left,
|
|
|
- lna.margin().right,
|
|
|
+ write!(
|
|
|
+ out,
|
|
|
+ ",\"margin\": {{\"top\": {}, \"bottom\": {}, \"left\": {}, \"right\": {}}}",
|
|
|
+ lna.margin().top,
|
|
|
+ lna.margin().bottom,
|
|
|
+ lna.margin().left,
|
|
|
+ lna.margin().right,
|
|
|
)?;
|
|
|
match lna.table_cell() {
|
|
|
None => write!(out, ",\"table_cell\": null")?,
|
|
|
- Some(c) => write!(out, ",\"table_cell\": [{},{}]", c.x, c.y)?
|
|
|
+ Some(c) => write!(out, ",\"table_cell\": [{},{}]", c.x, c.y)?,
|
|
|
}
|
|
|
match lna.render_area() {
|
|
|
None => write!(out, ",\"render_area\": null")?,
|
|
|
- Some(a) => write!(out, ",\"render_area\": [[{},{}],[{},{}]]", a.min.x, a.min.y, a.max.x, a.max.y)?
|
|
|
+ Some(a) => write!(
|
|
|
+ out,
|
|
|
+ ",\"render_area\": [[{},{}],[{},{}]]",
|
|
|
+ a.min.x, a.min.y, a.max.x, a.max.y
|
|
|
+ )?,
|
|
|
}
|
|
|
|
|
|
write!(out, ",\"children\": [")?;
|
|
@@ -521,6 +540,26 @@ impl<'l> Iterator for LayoutChildIter<'l> {
|
|
|
/// Wrapper struct to access a [`LayoutNodeContainer`].
|
|
|
#[derive(Clone, Copy)]
|
|
|
pub struct LayoutNodeAccess<'l> {
|
|
|
+ // general problem here:
|
|
|
+ // - this needs to be a reference to make the LNA clone/copy easily,
|
|
|
+ // - the reference means there needs to be a persistent object,
|
|
|
+ // - using the widget as a persistent object means only one level of heirarchy is supported,
|
|
|
+ // - so either:
|
|
|
+ // a) nodes are stored in some sort of container in the widget, which makes access annoying, or
|
|
|
+ // b) LayoutNodeContainer is given a tag type parameter to allow multiple implementations on a single type? this somewhat complicates the LayoutNodeAccess type
|
|
|
+ // this could *also* be changed to store a Box<dyn LayoutNodeContainer>, which would allow for a different set of ownership semantics; the result is significantly less efficient as it requires allocations to occur during tree traversal
|
|
|
+ // could require each external node linkage source to return a slice of all child nodes?
|
|
|
+ // - still runs into boxing requirements
|
|
|
+ // could also accept closures that are passed reference to slice of child nodes
|
|
|
+ //
|
|
|
+ // another possible solution here is to simply return an iterator across children
|
|
|
+ // - this does not require an object in quite the same way?
|
|
|
+ // - ExactSizeIterator handles most of the functionality nicely
|
|
|
+ // - and this way there need not be a single trait impl on the widget type; this allows for a
|
|
|
+ // full hierarchy to be specified
|
|
|
+ //
|
|
|
+ // alternatively, simply provide better mechanism for tree storage / easy node access
|
|
|
+ // - simple macro that generates types and impl automatically?
|
|
|
lnc: &'l dyn LayoutNodeContainer,
|
|
|
}
|
|
|
|