From 39ccbbb91851e640f027c70c8ac4baa57ee6c61c Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 22 Nov 2023 11:51:11 +0000 Subject: [PATCH] Upgrade Taffy + eliminate child_layouts Vec --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/view/taffy_layout.rs | 6 ------ src/widget/taffy_layout.rs | 25 ++++++++++--------------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 018f788d6..4e2849eca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2163,7 +2163,7 @@ dependencies = [ [[package]] name = "taffy" version = "0.3.11" -source = "git+https://github.com/DioxusLabs/taffy?rev=1876f72bee5e376023eaa518aa7b8a34c769bd1b#1876f72bee5e376023eaa518aa7b8a34c769bd1b" +source = "git+https://github.com/DioxusLabs/taffy?rev=7781c70241f7f572130c13106f2a869a9cf80885#7781c70241f7f572130c13106f2a869a9cf80885" dependencies = [ "arrayvec", "grid", diff --git a/Cargo.toml b/Cargo.toml index 31b36a9d2..f2191269f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/src/view/taffy_layout.rs b/src/view/taffy_layout.rs index 558b598bd..535a41a5f 100644 --- a/src/view/taffy_layout.rs +++ b/src/view/taffy_layout.rs @@ -126,12 +126,6 @@ impl> View for TaffyLayout { .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; diff --git a/src/widget/taffy_layout.rs b/src/widget/taffy_layout.rs index 02875f0e9..5368c6f40 100644 --- a/src/widget/taffy_layout.rs +++ b/src/widget/taffy_layout.rs @@ -46,7 +46,6 @@ type DummyMeasureFunction = pub struct TaffyLayout { pub children: Vec, pub child_caches: Vec, - pub child_layouts: Vec, pub style: taffy::Style, pub background_color: Option, } @@ -59,7 +58,6 @@ impl TaffyLayout { TaffyLayout { children, child_caches: caches, - child_layouts: vec![taffy::Layout::new(); len], style, background_color, } @@ -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 { @@ -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( @@ -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 @@ -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();