Refactor flexbox algorithm into smaller units#47
Refactor flexbox algorithm into smaller units#47TimJentzsch wants to merge 30 commits intoDioxusLabs:mainfrom
Conversation
This will make it easier to pass them around to the functions implementing each step of the algorithm.
|
This is an excellent PR description and process. I'm looking forward to seeing this develop :) |
f094fce to
6798052
Compare
57e840f to
ec17845
Compare
820d8f4 to
53fe85a
Compare
a8dff70 to
3565790
Compare
1181506 to
d584cb9
Compare
…-flexbox-algorithm
|
While I don't think that we should merge this just yet, this PR is ready for an initial review pass. I'm especially looking for feedback/ideas regarding the following:
Feel free to nitpick this PR, I think it's important that we create a good foundation here for future developments. |
|
I did a quick pass and overall I like the direction of this PR. Adding actual links to the spec with the relevant section when it is mentioned is really nice. I also like passing the constants struct around. I agree that the file is quite big, but after a quick review it's hard to tell what part could be extracted. I guess things like computing constants could be in a separate file. I'm not familiar enough with what it does to confidently say it doesn't change any behavior though. I wonder if it's possible to do some of that in a few separate PRs. Like for example, could you do a PR that focuses on improving the comments without doing anything else? This could help make it easier to review. (for the record, I come from the bevy community) |
|
Thank you for your feedback! I thought that maybe the different "sections" of the flexbox specs could be in different files. But I'm not sure if it's good practice in Rust to split Separating the doc improvements and refactoring would be possible in theory, but the "new" comments are tailored to them being on a new function, it would be weird to add the section name to each comment when it's in a single function IMO. |
|
I would really like unit tests for this, but in a follow-up PR. I'll do a pass on this in the coming week, commit-by-commit :) |
Is this code somehow responsible for a non-spec-abiding variant of step 4? My code-comprehension isn't good enough to see if that is actually the case, but there are no other candidates I see that could be implementing step 4 |
Yes, this is better. It improves readability :) |
It definitely might be, as step 4 is about Determine the main size of the flex container |
Weibye
left a comment
There was a problem hiding this comment.
I think this looks good to me, it is much improved from what was :)
| } | ||
| } | ||
|
|
||
| fn compute_internal( |
There was a problem hiding this comment.
This now has a much clearer high-level overview, which makes it easier to follow what is happening. Great work!
Co-authored-by: Andreas Weibye <[email protected]>
Co-authored-by: Andreas Weibye <[email protected]>
alice-i-cecile
left a comment
There was a problem hiding this comment.
Less intimidating to review than I was afraid of! This is a sizable improvement, great work.
|
@TimJentzsch this is failing due to two missing imports: use crate::style::{Style, FlexDirection};Github is hating me, so I can't easily make the changes myself. Once that's done this is ready to merge. |
|
I'm on vacation right now but will get on that in a couple of days |
|
Sounds good. I'll see what I can do on my own then :) |
|
Merged as #88 :D |

Objective
Fixes #43.
The
algo.rsfile and thecompute_internalspecifically is extremely complex and will be hard to maintain in the long run. It needs to be separated into smaller units to be easier to change, test and reason about.Solution
compute_internalfunction has been divided into multiple smaller functions.#[allow(clippy::cognitive_complexity)]has been removed.As this is going to be a rather large change, I opened this up as WIP PR. Feel free to give feedback continuously as I make changes, if you notice any bigger problems with my implementation already.