-
Notifications
You must be signed in to change notification settings - Fork 27
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
Consider using Taffy for Flexbox and CSS Grid support #3
Comments
Taffy looks great! I hope I can take a deeper dive into it soon. What I'm definitely interested in is making this useable by higher-level layout libraries like Taffy and Yoga. Whatever API changes you might need for that, I would support, although since you (and Yoga I think?) target native code, I guess it would only work with your WASM build. For the long-run, I do want to implement at least some of flexbox internally. While it is the hard path, I think great advantages come from having full control over source code in one place, similar to Serenity's ethos. (At least as long as I can make that work, who knows...). |
Yeah, I might need to have a think about that. This is definitely made a little trickier by the fact that they might both need to call each other down the tree. Taffy actually has a low-level API designed for this, but it's not exposed over WASM currently (and performance might well be bad). Taffy and Yoga both have the concept of a "measure function" which enable them to call out to an external implementation to measure/layout a child node. Perhaps if dropflow also had that then they can be integrating by nesting trees each time the layout type switched.
Feel free to port Taffy's code directly if you want. It's also MIT licensed and follows the spec pretty closely :) Libweb's implementation also looks good from what I've seen (I'd personally probably avoid porting Yoga as it's codebase isn't as clean (and has no grid support)). I'd expect a port to JS to work quite well, but not sure what the performance would be like. Both Taffy and Yoga are targeting realtime (60fps or even 120fps) rendering speeds for relatively large trees. Currently a tree with around 10k flexbox nodes will layout in around 4ms. That doesn't include text layout, so it's not an apples-to-apples comparison, but it seems quite a bit faster than dropflow (to be expected I guess - both because text layout is likely to be slower and because JS is likely to be slower) I'm also looking at implementing CSS2 layout on the Rust side. Probably either in cosmic-text or parley, although porting your code directly now represents an intriguing alternative possibility (I'm particular interested to see how you've combined Additionally we have a project to turn this into a modular webview by combining it with Firefox's style engine (which does selector resolution, media queries, etc and is available as a Rust crate). |
Oh, of course... having Taffy and dropflow call each other might be messy.
I'm relieved that it doesn't look like a totally unmanageable amount of code. Are there any gaps in grid or flexbox support? My strategy for flow layout has been to get low-level/older stuff working first and then work outward, but I have wondered if I'll have to cover the spec as-needed for grid and flexbox. Ladybird did an approach like that for flow layout: last I looked they only implemented 2-3 common scenarios for floats, and they'll fill out the rest of support as they go.
Jealousy! I might have started out with Rust if I knew this would end up in a useable state. I often see a layout difference of about 10x when I compare dropflow to browsers. That can be reduced to as low as 2x but only in the best case and with clever use.
I will say using another text layout engine may present challenges because the CSS2 spec is a text layout engine. For example, leading could be done differently by those libraries than CSS2. Using HarfBuzz directly is hard mode though; if you don't need perfect support you could skip a lot of work.
I treat it as neutral, so it inherits the direction of adjacent text (code).
Very cool, and thanks for the invite! |
It's not too late ;)
Yeah, it's not too bad! Regarding gaps, the roadmap issue is a good place to look. To summarise, support is actually pretty good (discrepancies with browsers (if any) are likely to be in edge cases) and the major missing pieces I'm tracking are:
Additionally:
These engines are all quite new and unestablished. So I'm hoping to have some sway in how they implement such things. To start with imperfect will definitely be better than none (we don't support inline-block at all at the moment), but eventually it would be nice to match web exactly. Servo's layout engine is another option that has decent CSS2 support, but they are MPL licensed which isn't ideal for integrating with a MIT codebase. |
That's impressive though. I'd expect the doesn't-work-yets above if you haven't finished flow layout yet. And I never use named grid lines anyways :)
I was excited when they updated this, because people are always having issues with flexboxes-in-flexboxes. If I'm not mistaken, this is the Chrome issue where they tried it, but it broke the web 😞. So browsers are still on the original spec. The WPT scripts thing is a problem for me too. And gsnedder's reply makes me think we would have to update more tests to use the script they use in WPT, and then you would have to port that script to Rust, and I'd have to tweak it to work in dropflow. I hope one of us finds a better solution for that; it sounds like they're open to supporting more engines. |
Full disclosure: I'm a maintainer of Taffy
I just saw your project on HN, and couldn't help but feel like a library I work on: Taffy https://github.com/DioxusLabs/taffy would be a perfect complement to it. We support Flexbox and CSS Grid layout (and blocks-that-contains-blocks, but I suspect you already implement that) but not any of the rest of the CSS2-style layout (we're also missing some features necessary for full web compatibility:
position: static
,direction: rtl
, andbox-sizing: content-box
being the main ones off the top of my head).Taffy is implemented in Rust, and the WASM bindings (DioxusLabs/taffy#394) are currently incomplete (Flexbox is usable with the current state of that PR - CSS Grid isn't yet), but I could look into getting those into a releasable state if you are interested.
You may also wish to consider Yoga https://github.com/facebook/yoga (which I am not affiliated with) which is implemented in C++ and has more established WASM bindings but only supports Flexbox.
The text was updated successfully, but these errors were encountered: