-
Notifications
You must be signed in to change notification settings - Fork 112
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
Fix flexbox baseline alignment #325
Conversation
1dc8683
to
ef8e73d
Compare
- Introduce LayoutAlgorithm trait
ef8e73d
to
2cc99ee
Compare
This still doesn't implement baseline alignment for CSS Grid, but I now think I'd like to merge this without that to unblock #326. These changes (fixing baseline alignment for flexbox, and refactoring the flexbox implementation so that it doesn't require accessing the layout of descendant nodes other than direct children) are worthwhile on their own, and baseline alignment for CSS Grid can follow in another PR. |
src/compute/flexbox.rs
Outdated
@@ -130,14 +158,14 @@ struct AlgoConstants { | |||
} | |||
|
|||
/// Computes the layout of [`LayoutTree`] according to the flexbox algorithm | |||
pub fn compute( | |||
pub fn compute_generic( |
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.
This name isn't very clear.
src/compute/grid/mod.rs
Outdated
/// Grid layout algorithm | ||
/// This consists of a few phases: | ||
/// - Resolving the explicit grid | ||
/// - Placing items (which also resolves the implicit grid) | ||
/// - Track (row/column) sizing | ||
/// - Alignment & Final item placement | ||
pub fn compute( | ||
pub fn compute_generic( |
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.
Ditto on the name here.
|
||
/// The public interface to a generic algorithm that abstracts over all of Taffy's algorithms | ||
/// and applies the correct one based on the `Display` style | ||
pub struct GenericAlgorithm; |
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.
Hmm. I'm not very happy with this naming / docs. Maybe something like UnifyingLayoutAlgorithm
?
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.
This struct actually disappears in my latest version of #326, as I've made the "generic" algorithm and the "leaf" algorithm operate on &mut Taffy
rather than &mut impl LayoutTree
(so they don't fit the LayoutAlgorithm
trait anymore). This allows us to remove measure_funcs from the LayoutTree
trait and make them an implementation detail of our Taffy
storage implementation.
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.
Good I'm fine to wait.
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.
Some feedback on structure and docs. I would like to get this merged quickly though, so feel free to defer some of the work (e.g. the trait refactor) to a follow-up PR.
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
@alice-i-cecile I've renamed the Is there anything else blocking this? |
Nope, this now LGTM. |
Objective
Context
Note: This PR depends on #320 which in turn depends on #317both now merged!I did a quick run of the benchmarks vs.
main
to check for regressions, and actually I'm seeing mild performance wins (10% - 30% on some benchmarks) on quite a few of the benchmarks. There is also a ~10% regression on a couple, but those are the very smallest ones that are completing in single-digit microseconds anyway, so I'm not going to worry too much about those (we probably ought to remove those super small ones at some point - I don't think they're very representative of real-world performance).Feedback wanted
Does changing each algorithm's
perform_layout
function to return:instead of
Size<f32>
as I have done in this PR seem reasonable? This is instead of the 3rd layout method proposed in #28 (comment)