Skip to content

Commit

Permalink
Bump to Taffy with separate cache trait
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Burns <[email protected]>
  • Loading branch information
nicoburns committed Dec 12, 2024
1 parent 280b1ba commit a0e9c2f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dioxus-core = { version = "0.6" }
dioxus-html = { version = "0.6" }
dioxus-cli-config = { version = "0.6" }
dioxus-devtools = { version = "0.6" }
taffy = { version = "0.6", default-features = false, features = ["std", "flexbox", "grid", "block_layout", "content_size"] }
taffy = { git = "https://github.com/dioxuslabs/taffy", rev = "63f4adebf", default-features = false, features = ["std", "flexbox", "grid", "block_layout", "content_size"] }

# Linebender + WGPU
peniko = "0.2"
Expand Down
47 changes: 38 additions & 9 deletions packages/blitz-dom/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::cell::Ref;
use std::sync::Arc;
use taffy::{
compute_block_layout, compute_cached_layout, compute_flexbox_layout, compute_grid_layout,
compute_leaf_layout, prelude::*, Cache, FlexDirection, LayoutPartialTree, NodeId,
compute_leaf_layout, prelude::*, FlexDirection, LayoutPartialTree, NodeId,
ResolveOrZero, RoundTree, Style, TraversePartialTree, TraverseTree,
};

Expand Down Expand Up @@ -70,10 +70,6 @@ impl LayoutPartialTree for Document {
= &'a taffy::Style
where
Self: 'a;
type CacheMut<'b>
= &'b mut Cache
where
Self: 'b;

fn get_core_container_style(&self, node_id: NodeId) -> &Style {
&self.node_from_id(node_id).style
Expand All @@ -83,10 +79,6 @@ impl LayoutPartialTree for Document {
self.node_from_id_mut(node_id).unrounded_layout = *layout;
}

fn get_cache_mut(&mut self, node_id: NodeId) -> &mut Cache {
&mut self.node_from_id_mut(node_id).cache
}

fn compute_child_layout(
&mut self,
node_id: NodeId,
Expand Down Expand Up @@ -281,6 +273,43 @@ impl LayoutPartialTree for Document {
}
}

impl taffy::CacheTree for Document {
#[inline]
fn cache_get(
&self,
node_id: NodeId,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
run_mode: taffy::RunMode,
) -> Option<taffy::LayoutOutput> {
self.node_from_id(node_id)
.cache
.get(known_dimensions, available_space, run_mode)
}

#[inline]
fn cache_store(
&mut self,
node_id: NodeId,
known_dimensions: Size<Option<f32>>,
available_space: Size<AvailableSpace>,
run_mode: taffy::RunMode,
layout_output: taffy::LayoutOutput,
) {
self.node_from_id_mut(node_id).cache.store(
known_dimensions,
available_space,
run_mode,
layout_output,
);
}

#[inline]
fn cache_clear(&mut self, node_id: NodeId) {
self.node_from_id_mut(node_id).cache.clear();
}
}

impl taffy::LayoutBlockContainer for Document {
type BlockContainerStyle<'a>
= &'a Style
Expand Down
9 changes: 0 additions & 9 deletions packages/blitz-dom/src/layout/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ impl taffy::LayoutPartialTree for TableTreeWrapper<'_> {
= &'a taffy::Style
where
Self: 'a;
type CacheMut<'b>
= &'b mut taffy::Cache
where
Self: 'b;

fn get_core_container_style(&self, _node_id: taffy::NodeId) -> &taffy::Style {
&self.ctx.style
Expand All @@ -207,11 +203,6 @@ impl taffy::LayoutPartialTree for TableTreeWrapper<'_> {
self.doc.set_unrounded_layout(node_id, layout)
}

fn get_cache_mut(&mut self, node_id: taffy::NodeId) -> &mut taffy::Cache {
let node_id = taffy::NodeId::from(self.ctx.items[usize::from(node_id)].node_id);
&mut self.doc.node_from_id_mut(node_id).cache
}

fn compute_child_layout(
&mut self,
node_id: taffy::NodeId,
Expand Down

0 comments on commit a0e9c2f

Please sign in to comment.