Skip to content

Commit

Permalink
Upgrade Taffy + eliminate child_layouts Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Nov 22, 2023
1 parent e78ad81 commit 39ccbbb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ wayland = ["glazier/wayland"]

[dependencies]
xilem_core.workspace = true
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "1876f72bee5e376023eaa518aa7b8a34c769bd1b" }
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "7781c70241f7f572130c13106f2a869a9cf80885" }
vello = { git = "https://github.com/linebender/vello", rev = "9d7c4f00d8db420337706771a37937e9025e089c" }
wgpu = "0.17.0"
parley = { git = "https://github.com/dfrg/parley", rev = "2371bf4b702ec91edee2d58ffb2d432539580e1e" }
Expand Down
6 changes: 0 additions & 6 deletions src/view/taffy_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ impl<T, A, VT: ViewSequence<T, A>> View<T, A> for TaffyLayout<T, A, VT> {
.rebuild(cx, &prev.children, state, &mut splice)
});

// Keep child_layouts Vec length in sync with children Vec length
element.child_layouts.truncate(element.children.len());
for _ in element.child_layouts.len()..element.children.len() {
element.child_layouts.push(taffy::Layout::new());
}

if self.style != prev.style {
element.style = self.style.clone();
element.background_color = self.background_color;
Expand Down
25 changes: 10 additions & 15 deletions src/widget/taffy_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type DummyMeasureFunction =
pub struct TaffyLayout {
pub children: Vec<Pod>,
pub child_caches: Vec<taffy::Cache>,
pub child_layouts: Vec<taffy::Layout>,
pub style: taffy::Style,
pub background_color: Option<Color>,
}
Expand All @@ -59,7 +58,6 @@ impl TaffyLayout {
TaffyLayout {
children,
child_caches: caches,
child_layouts: vec![taffy::Layout::new(); len],
style,
background_color,
}
Expand Down Expand Up @@ -226,8 +224,14 @@ impl<'w, 'a, 'b> taffy::PartialLayoutTree for TaffyLayoutCtx<'w, 'a, 'b> {
}
}

fn get_unrounded_layout_mut(&mut self, node_id: taffy::NodeId) -> &mut ::taffy::tree::Layout {
&mut self.widget.child_layouts[usize::from(node_id)]
fn set_unrounded_layout(&mut self, node_id: taffy::NodeId, layout: &::taffy::tree::Layout) {
self.widget.children[usize::from(node_id)].set_origin(
self.cx,
Point {
x: layout.location.x as f64,
y: layout.location.y as f64,
},
)
}

fn get_cache_mut(&mut self, node_id: taffy::NodeId) -> &mut ::taffy::tree::Cache {
Expand All @@ -248,7 +252,7 @@ impl<'w, 'a, 'b> taffy::PartialLayoutTree for TaffyLayoutCtx<'w, 'a, 'b> {
width: size.width as f32,
height: size.height as f32,
};
taffy::LayoutOutput::from(taffy_size)
taffy::LayoutOutput::from_outer_size(taffy_size)
}
taffy::RunMode::ComputeSize => {
let axis_size = self.widget.children[usize::from(node_id)].compute_max_intrinsic(
Expand All @@ -267,7 +271,7 @@ impl<'w, 'a, 'b> taffy::PartialLayoutTree for TaffyLayoutCtx<'w, 'a, 'b> {
},
taffy::RequestedAxis::Both => unreachable!(),
};
taffy::LayoutOutput::from(taffy_size)
taffy::LayoutOutput::from_outer_size(taffy_size)
}
taffy::RunMode::PerformHiddenLayout => {
// TODO: set size of widget to zero
Expand Down Expand Up @@ -333,15 +337,6 @@ impl Widget for TaffyLayout {
}
};

for (child, layout) in self.children.iter_mut().zip(&self.child_layouts) {
child.set_origin(
cx,
Point {
x: layout.location.x as f64,
y: layout.location.y as f64,
},
);
}
cx.request_paint();

let max = bc.max();
Expand Down

0 comments on commit 39ccbbb

Please sign in to comment.