-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute content size, padding and border for each node #573
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to admit, it's becoming quite hard for me to grasp all the layout logic as it's becoming more and more complex.
I wonder if we can improve this somehow, maybe with more inline docs or with better abstractions or if the complexity of Flexbox and the performance considerations make this a necessity.
Regarding the performance, it would of course be great if we only had to pay this cost if scrolling is enabled, but I assume this would be difficult to implement right now.
I assume Bevy and other clients will always have this feature enabled, so it would be great to reduce the performance cost somehow.
If the feature is enabled by default or not is less important IMO.
257ec2a
to
0e74c94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be merged as-is (causes 5-20% performance hit). Or can anyone think of any way to reduce to reduce the performance impact - as far as I can tell is the actually computation of the content sizes from the sizes of the child nodes?
I'm okay to merge as is: I think this is fundamentally a necessary feature for the spec.
If it should be merged, should it be enabled by default?
Hmm. So ultimately our users are UI crates that consume taffy. Some of them will be simple, and won't support scrolling, others are more complex and do. Unless they make a feature flag to mirror this, that control won't be exposed to users.
In Bevy for example, I would probably push for a mirror of this feature flag, and then enable it by default in Bevy.
On the balance, I think we should keep this on by default, to match our existing policy of enabling default features for multiple different layout algorithms, even if not all of them are useful to all UI crates.
a51ed92
to
d8d0700
Compare
…taken up by scrollbars
5eeff39
to
5117d41
Compare
5117d41
to
b260448
Compare
0b210ca
to
26b1238
Compare
26b1238
to
6be8996
Compare
There's still a performance hit with this, but it's much better since #579 (now more like 5-8%). So I think I'm going to enable this by default. I suspect we may also need to tweak the computed size in future (as we discover bugs), but I think this is good enough as a first cut at the feature. |
We reverted bump to taffy 0.4.3 following an issue spotted by @maxdeviant where chat text input was not being rendered correctly: ![image](https://github.com/zed-industries/zed/assets/24362066/9d7e6444-47b1-4ac2-808f-bf10404377c0) 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: https://github.com/zed-industries/zed/blob/df190ea84621837c44fa50c62837bdbea04b9e22/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 DioxusLabs/taffy#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: #11606 #11622 #7868 #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
We reverted bump to taffy 0.4.3 following an issue spotted by @maxdeviant where chat text input was not being rendered correctly: ![image](https://github.com/zed-industries/zed/assets/24362066/9d7e6444-47b1-4ac2-808f-bf10404377c0) 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: https://github.com/zed-industries/zed/blob/df190ea84621837c44fa50c62837bdbea04b9e22/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 DioxusLabs/taffy#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: zed-industries#11606 zed-industries#11622 zed-industries#7868 zed-industries#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
Objective
border
calculated value #223Changes made
Overflow::Clip
variant added to theOverflow
enum. Layout withClip
behaves the same asVisible
, except the overflowing contents don't contribute to the ancestor nodes' content sizes.content_size
feature flag addedcontent_size
field added toLayout
struct (stored on Node) andLayoutOutput
(returned to parent) structsborder
andpadding
fields added to theLayout
structcontent_size
computation for all layout modesscroll_width
andscroll_height
methods toLayout
and add tests for scroll width/heightTodo
Context
Useful for any UI toolkit wanting to implement scrolling (e.g. bevyengine/bevy#8104). Although it's worth noting that this implementation assumes that every node is a scroll node, and it may be possible to do this cheaper if you can avoid that assumption at a higher level.
Feedback wanted