From f6d820e51b2d20448368a93a88efc75f8e877f96 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 19 Jan 2024 17:56:49 +0100 Subject: [PATCH] WIP --- Cargo.lock | 2 +- crates/gpui/Cargo.toml | 2 +- crates/gpui/src/elements/div.rs | 9 +++------ crates/gpui/src/taffy.rs | 7 ++++++- crates/gpui/src/window.rs | 12 ++++++++++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 010e7763e4..015f96033a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7774,7 +7774,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=64f8aa0fb114d939ca0d53ddc44045a03fde548d#64f8aa0fb114d939ca0d53ddc44045a03fde548d" dependencies = [ "arrayvec 0.7.4", "grid", diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 70608ccb0c..4b5baf1ed2 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -46,7 +46,7 @@ serde_derive.workspace = true serde_json.workspace = true smallvec.workspace = true smol.workspace = true -taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "1876f72bee5e376023eaa518aa7b8a34c769bd1b" } +taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "64f8aa0fb114d939ca0d53ddc44045a03fde548d", features = ["content_size"] } thiserror.workspace = true time.workspace = true tiny-skia = "0.5" diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index aa912eadbe..3b3e35a9e5 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -802,6 +802,7 @@ impl Element for Div { ( layout_id, DivState { + layout_id, interactive_state, child_layout_ids, }, @@ -839,12 +840,7 @@ impl Element for Div { } (child_max - child_min).into() } else { - for child_layout_id in &element_state.child_layout_ids { - let child_bounds = cx.layout_bounds(*child_layout_id); - child_min = child_min.min(&child_bounds.origin); - child_max = child_max.max(&child_bounds.lower_right()); - } - (child_max - child_min).into() + cx.layout_scroll_size(element_state.layout_id) }; self.interactivity.paint( @@ -876,6 +872,7 @@ impl IntoElement for Div { } pub struct DivState { + layout_id: LayoutId, child_layout_ids: SmallVec<[LayoutId; 2]>, interactive_state: InteractiveElementState, } diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rs index 26d5a2e69e..b77e91056d 100644 --- a/crates/gpui/src/taffy.rs +++ b/crates/gpui/src/taffy.rs @@ -1,5 +1,5 @@ use crate::{ - AbsoluteLength, Bounds, DefiniteLength, Edges, Length, Pixels, Point, Size, Style, + size, AbsoluteLength, Bounds, DefiniteLength, Edges, Length, Pixels, Point, Size, Style, WindowContext, }; use collections::{FxHashMap, FxHashSet}; @@ -227,6 +227,11 @@ impl TaffyLayoutEngine { bounds } + + pub fn layout_scroll_size(&self, id: LayoutId) -> Size { + let layout = self.taffy.layout(id.into()).expect(EXPECT_MESSAGE); + size(layout.scroll_width().into(), layout.scroll_height().into()) + } } #[derive(Copy, Clone, Eq, PartialEq, Debug)] diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 4e7ba2001a..b7dcda548e 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -874,12 +874,20 @@ impl<'a> WindowContext<'a> { .layout_engine .as_mut() .unwrap() - .layout_bounds(layout_id) - .map(Into::into); + .layout_bounds(layout_id); bounds.origin += self.element_offset(); bounds } + /// todo!() + pub fn layout_scroll_size(&self, layout_id: LayoutId) -> Size { + self.window + .layout_engine + .as_ref() + .unwrap() + .layout_scroll_size(layout_id) + } + fn window_bounds_changed(&mut self) { self.window.scale_factor = self.window.platform_window.scale_factor(); self.window.viewport_size = self.window.platform_window.content_size();