|
@@ -8,14 +8,14 @@
|
|
|
|
|
|
use std::{ops::Deref, rc::Rc};
|
|
use std::{ops::Deref, rc::Rc};
|
|
|
|
|
|
-use cache::{Layer, LayoutCacheKey, NodeState};
|
|
|
|
|
|
+use cache::{Layer, NodeState};
|
|
use kahlo::math::{PixelBox, PixelSideOffsets};
|
|
use kahlo::math::{PixelBox, PixelSideOffsets};
|
|
|
|
|
|
mod arr;
|
|
mod arr;
|
|
mod cache;
|
|
mod cache;
|
|
mod calc;
|
|
mod calc;
|
|
|
|
|
|
-pub use cache::LayoutCache;
|
|
|
|
|
|
+pub use cache::{LayoutCache,LayoutNodeID};
|
|
pub use calc::recalculate;
|
|
pub use calc::recalculate;
|
|
|
|
|
|
pub struct CellMarker;
|
|
pub struct CellMarker;
|
|
@@ -193,7 +193,7 @@ pub struct LayoutNode {
|
|
/// Human-readable label for making layout tree dumps easier to read.
|
|
/// Human-readable label for making layout tree dumps easier to read.
|
|
label: Option<String>,
|
|
label: Option<String>,
|
|
/// Unique identifier for this LayoutNode
|
|
/// Unique identifier for this LayoutNode
|
|
- cache_key: LayoutCacheKey,
|
|
|
|
|
|
+ cache_key: LayoutNodeID,
|
|
/// Reference to the global layout item cache.
|
|
/// Reference to the global layout item cache.
|
|
cache: Rc<LayoutCache>,
|
|
cache: Rc<LayoutCache>,
|
|
/// Layout behaviour, or how this node behaves with respect to its parent.
|
|
/// Layout behaviour, or how this node behaves with respect to its parent.
|
|
@@ -230,7 +230,7 @@ impl std::fmt::Debug for LayoutNode {
|
|
|
|
|
|
impl LayoutNode {
|
|
impl LayoutNode {
|
|
pub fn new(cache: Rc<LayoutCache>) -> Self {
|
|
pub fn new(cache: Rc<LayoutCache>) -> Self {
|
|
- let cache_key = LayoutCacheKey::generate();
|
|
|
|
|
|
+ let cache_key = LayoutNodeID::generate();
|
|
cache.update_queue.borrow_mut().push(cache_key);
|
|
cache.update_queue.borrow_mut().push(cache_key);
|
|
Self {
|
|
Self {
|
|
label: None,
|
|
label: None,
|
|
@@ -247,6 +247,10 @@ impl LayoutNode {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ pub fn id(&self) -> LayoutNodeID {
|
|
|
|
+ self.cache_key
|
|
|
|
+ }
|
|
|
|
+
|
|
pub fn cache(&self) -> &Rc<LayoutCache> {
|
|
pub fn cache(&self) -> &Rc<LayoutCache> {
|
|
&self.cache
|
|
&self.cache
|
|
}
|
|
}
|
|
@@ -260,7 +264,7 @@ impl LayoutNode {
|
|
}
|
|
}
|
|
|
|
|
|
pub fn relayout_tree(&self) {
|
|
pub fn relayout_tree(&self) {
|
|
- let mut to_mark: Vec<LayoutCacheKey> = vec![self.cache_key];
|
|
|
|
|
|
+ let mut to_mark: Vec<LayoutNodeID> = vec![self.cache_key];
|
|
while let Some(next) = to_mark.pop() {
|
|
while let Some(next) = to_mark.pop() {
|
|
self.cache.with_state(next, |ns| {
|
|
self.cache.with_state(next, |ns| {
|
|
ns.needs_update = true;
|
|
ns.needs_update = true;
|
|
@@ -378,7 +382,7 @@ impl Clone for LayoutNode {
|
|
fn clone(&self) -> Self {
|
|
fn clone(&self) -> Self {
|
|
Self {
|
|
Self {
|
|
label: self.label.clone(),
|
|
label: self.label.clone(),
|
|
- cache_key: LayoutCacheKey::generate(),
|
|
|
|
|
|
+ cache_key: LayoutNodeID::generate(),
|
|
cache: self.cache.clone(),
|
|
cache: self.cache.clone(),
|
|
behaviour: self.behaviour,
|
|
behaviour: self.behaviour,
|
|
child_arrangement: self.child_arrangement.clone(),
|
|
child_arrangement: self.child_arrangement.clone(),
|
|
@@ -437,6 +441,56 @@ pub fn dump_node_tree(lna: LayoutNodeAccess, out: &mut String) {
|
|
dump_node_tree_helper(lna, 0, out);
|
|
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<()> {
|
|
|
|
+ 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, ",\"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, ",\"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,
|
|
|
|
+ )?;
|
|
|
|
+ match lna.table_cell() {
|
|
|
|
+ None => write!(out, ",\"table_cell\": null")?,
|
|
|
|
+ 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)?
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ write!(out, ",\"children\": [")?;
|
|
|
|
+
|
|
|
|
+ let mut needs_sep = false;
|
|
|
|
+ for child in lna.child_iter() {
|
|
|
|
+ if needs_sep {
|
|
|
|
+ out.write(",".as_bytes())?;
|
|
|
|
+ } else {
|
|
|
|
+ needs_sep = true;
|
|
|
|
+ }
|
|
|
|
+ dump_tree_json(child, out)?;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ write!(out, r#"]}}"#)?;
|
|
|
|
+
|
|
|
|
+ Ok(())
|
|
|
|
+}
|
|
|
|
+
|
|
/// Iterator implementation to iterate across children of a LayoutNodeContainer
|
|
/// Iterator implementation to iterate across children of a LayoutNodeContainer
|
|
#[derive(Clone)]
|
|
#[derive(Clone)]
|
|
pub struct LayoutChildIter<'l> {
|
|
pub struct LayoutChildIter<'l> {
|