Skip to content
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

Implement "root" layout mode #530

Open
nicoburns opened this issue Aug 29, 2023 · 3 comments
Open

Implement "root" layout mode #530

nicoburns opened this issue Aug 29, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@nicoburns
Copy link
Collaborator

nicoburns commented Aug 29, 2023

What problem does this solve or what need does it fill?

There are some styles that can only or are best applied by the parent of a node. These include:

  • position (notably position: absolute)
  • top/bottom/left/right
  • margin

And perhaps:

  • Perhaps width/height/max_width/max_height/min_width/min_height
  • aspect_ratio

Currently these are either not applied to root nodes, or are applied in a duplicated manner within the node's algorithm itself.

What solution would you like?

Much like we have a dedicated simple algorithm for leaf nodes, we ought to create one for root nodes which is applied to the top-level node in any call to compute_layout.

Additional context

  • I've tested this on web, and browsers allow the root <html> node to have styles like position/top/left/margin, etc applied. And it seems like a useful thing to allow, so I think we ought to the same.
  • This layout mode could probably be reused for layout of position: fixed nodes which layout in a very similar way to the root node.
@nicoburns
Copy link
Collaborator Author

Hmm.... so investigating this, it looks like web more or less treats the viewport as a display: block node with a single child (the root node). That behaviour is not entirely ideal for bevy, as it would be super-nice if margin: auto "just worked" for centering the root node. But it would at least make absolute positioning (and fixed margins, and horizontal auto margins) work. And we also can't really implement it for the 0.3.x series, as that doesn't support display: block yet! Annoying.

Perhaps we can eventually make the viewport behaviour configurable through something like the following enum (as a tree-wide config setting):

enum ViewportLayoutBehaviour {
    BlockLike,
    GridLike,
    FlexLike, // Do we even need this? Not sure what it would be useful for.
}

Where BlockLike is the default web-compatible mode. And GridLike and FlexLike would be Taffy-proprietary extensions.

@shirakaba
Copy link

shirakaba commented Sep 25, 2023

@nicoburns (Assuming I've understood the discussion here), I think a FlexLike root might be of interest to React Native users implementing a new virtualised ListView. Each cell in the list could be effectively a new root/viewport, and – as Flexbox layout is the default in React Native – it'd be the appropriate display mode there.

@thecodrr
Copy link

This is quite a critical blocker for layout systems that try to behave like browsers. Taffy right now requires you to wrap the actual root node with another dummy root node in order for things like margin to work. That wouldn't be a big issue but the way block layout & its margin collapsing works makes recreating browser layouts impossible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants