gpui: Bump taffy to 0.4.3 again (#11655)
We reverted bump to taffy 0.4.3 following an issue spotted by
@maxdeviant where chat text input was not being rendered correctly:

This was an issue with the previous attempt to upgrade to taffy 0.4.0 as
well. We bail early in `compute_auto_height_layout` due to a missing
width:
df190ea846/crates/editor/src/element.rs (L5266)
The same issue is visible in story for auto-height editor (or rather,
the breakage is visible - the editor simply does not render at all
there).
I tracked down the breakage to
https://github.com/DioxusLabs/taffy/pull/573 ; it looks like it
specifically affects editors with auto-height. In taffy <0.4 which we
were using previously, we'd eventually get a proper width for
auto-height EditorElement after having initially computed the size. With
taffy 0.4 however (and specifically that PR mentioned earlier), we're
getting `Size::NONE` in layout phase [^1].
I've noticed though that even with taffy <0.3, the
`known_dimensions.width` was always equal to `available_space.width` in
layout phase. Hence, I went with falling back to `available_space.width`
when it is a definite value and we don't have a
`known_dimensions.width`.
Done this way, both chat input and auto-height story render correctly.
/cc @as-cii
Related:
https://github.com/zed-industries/zed/pull/11606
https://github.com/zed-industries/zed/pull/11622
https://github.com/zed-industries/zed/pull/7868
https://github.com/zed-industries/zed/pull/7896
[^1]: This could possibly be related to change in what gets passed in
https://github.com/DioxusLabs/taffy/pull/573/files#diff-60c916e9b0c507925f032cecdde6ae163e41b84b8e4bc0a6c04f7d846b0aad9eR133
, though I'm not sure if editor is a leaf node in this case
Release Notes:
- N/A
This commit is contained in:
parent
df190ea846
commit
df00854bbc
4 changed files with 36 additions and 23 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -4721,9 +4721,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "grid"
|
name = "grid"
|
||||||
version = "0.11.0"
|
version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1df00eed8d1f0db937f6be10e46e8072b0671accb504cf0f959c5c52c679f5b9"
|
checksum = "d196ffc1627db18a531359249b2bf8416178d84b729f3cebeb278f285fb9b58c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "group"
|
name = "group"
|
||||||
|
@ -9976,12 +9976,14 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "taffy"
|
name = "taffy"
|
||||||
version = "0.3.11"
|
version = "0.4.3"
|
||||||
source = "git+https://github.com/DioxusLabs/taffy?rev=1876f72bee5e376023eaa518aa7b8a34c769bd1b#1876f72bee5e376023eaa518aa7b8a34c769bd1b"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b2e140b328c6cb5e744bb2c65910b47df86b239afc793ee2c52262569cf9225"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"grid",
|
"grid",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"serde",
|
||||||
"slotmap",
|
"slotmap",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -3670,19 +3670,23 @@ impl Element for EditorElement {
|
||||||
let editor_handle = cx.view().clone();
|
let editor_handle = cx.view().clone();
|
||||||
let max_line_number_width =
|
let max_line_number_width =
|
||||||
self.max_line_number_width(&editor.snapshot(cx), cx);
|
self.max_line_number_width(&editor.snapshot(cx), cx);
|
||||||
cx.request_measured_layout(Style::default(), move |known_dimensions, _, cx| {
|
cx.request_measured_layout(
|
||||||
editor_handle
|
Style::default(),
|
||||||
.update(cx, |editor, cx| {
|
move |known_dimensions, available_space, cx| {
|
||||||
compute_auto_height_layout(
|
editor_handle
|
||||||
editor,
|
.update(cx, |editor, cx| {
|
||||||
max_lines,
|
compute_auto_height_layout(
|
||||||
max_line_number_width,
|
editor,
|
||||||
known_dimensions,
|
max_lines,
|
||||||
cx,
|
max_line_number_width,
|
||||||
)
|
known_dimensions,
|
||||||
})
|
available_space.width,
|
||||||
.unwrap_or_default()
|
cx,
|
||||||
})
|
)
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
EditorMode::Full => {
|
EditorMode::Full => {
|
||||||
let mut style = Style::default();
|
let mut style = Style::default();
|
||||||
|
@ -5261,9 +5265,16 @@ fn compute_auto_height_layout(
|
||||||
max_lines: usize,
|
max_lines: usize,
|
||||||
max_line_number_width: Pixels,
|
max_line_number_width: Pixels,
|
||||||
known_dimensions: Size<Option<Pixels>>,
|
known_dimensions: Size<Option<Pixels>>,
|
||||||
|
available_width: AvailableSpace,
|
||||||
cx: &mut ViewContext<Editor>,
|
cx: &mut ViewContext<Editor>,
|
||||||
) -> Option<Size<Pixels>> {
|
) -> Option<Size<Pixels>> {
|
||||||
let width = known_dimensions.width?;
|
let width = known_dimensions.width.or_else(|| {
|
||||||
|
if let AvailableSpace::Definite(available_width) = available_width {
|
||||||
|
Some(available_width)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})?;
|
||||||
if let Some(height) = known_dimensions.height {
|
if let Some(height) = known_dimensions.height {
|
||||||
return Some(size(width, height));
|
return Some(size(width, height));
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ slotmap = "1.0.6"
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
sum_tree.workspace = true
|
sum_tree.workspace = true
|
||||||
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "1876f72bee5e376023eaa518aa7b8a34c769bd1b" }
|
taffy = "0.4.3"
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
util.workspace = true
|
util.workspace = true
|
||||||
|
|
|
@ -9,14 +9,14 @@ use taffy::{
|
||||||
geometry::{Point as TaffyPoint, Rect as TaffyRect, Size as TaffySize},
|
geometry::{Point as TaffyPoint, Rect as TaffyRect, Size as TaffySize},
|
||||||
style::AvailableSpace as TaffyAvailableSpace,
|
style::AvailableSpace as TaffyAvailableSpace,
|
||||||
tree::NodeId,
|
tree::NodeId,
|
||||||
Taffy,
|
TaffyTree, TraversePartialTree as _,
|
||||||
};
|
};
|
||||||
|
|
||||||
type NodeMeasureFn =
|
type NodeMeasureFn =
|
||||||
Box<dyn FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut WindowContext) -> Size<Pixels>>;
|
Box<dyn FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut WindowContext) -> Size<Pixels>>;
|
||||||
|
|
||||||
pub struct TaffyLayoutEngine {
|
pub struct TaffyLayoutEngine {
|
||||||
taffy: Taffy,
|
taffy: TaffyTree<()>,
|
||||||
styles: FxHashMap<LayoutId, Style>,
|
styles: FxHashMap<LayoutId, Style>,
|
||||||
children_to_parents: FxHashMap<LayoutId, LayoutId>,
|
children_to_parents: FxHashMap<LayoutId, LayoutId>,
|
||||||
absolute_layout_bounds: FxHashMap<LayoutId, Bounds<Pixels>>,
|
absolute_layout_bounds: FxHashMap<LayoutId, Bounds<Pixels>>,
|
||||||
|
@ -29,7 +29,7 @@ static EXPECT_MESSAGE: &str = "we should avoid taffy layout errors by constructi
|
||||||
impl TaffyLayoutEngine {
|
impl TaffyLayoutEngine {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
TaffyLayoutEngine {
|
TaffyLayoutEngine {
|
||||||
taffy: Taffy::new(),
|
taffy: TaffyTree::new(),
|
||||||
styles: FxHashMap::default(),
|
styles: FxHashMap::default(),
|
||||||
children_to_parents: FxHashMap::default(),
|
children_to_parents: FxHashMap::default(),
|
||||||
absolute_layout_bounds: FxHashMap::default(),
|
absolute_layout_bounds: FxHashMap::default(),
|
||||||
|
@ -114,7 +114,7 @@ impl TaffyLayoutEngine {
|
||||||
fn max_depth(&self, depth: u32, parent: LayoutId) -> anyhow::Result<u32> {
|
fn max_depth(&self, depth: u32, parent: LayoutId) -> anyhow::Result<u32> {
|
||||||
println!(
|
println!(
|
||||||
"{parent:?} at depth {depth} has {} children",
|
"{parent:?} at depth {depth} has {} children",
|
||||||
self.taffy.child_count(parent.0)?
|
self.taffy.child_count(parent.0)
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut max_child_depth = 0;
|
let mut max_child_depth = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue