This commit is contained in:
Antonio Scandurra 2024-01-19 17:56:49 +01:00
parent 01f06f96a1
commit f6d820e51b
5 changed files with 21 additions and 11 deletions

2
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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,
}

View file

@ -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<Pixels> {
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)]

View file

@ -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<Pixels> {
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();