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

Position::Fixed - window-relative positioning #718

Open
viridia opened this issue Oct 8, 2024 · 0 comments
Open

Position::Fixed - window-relative positioning #718

viridia opened this issue Oct 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@viridia
Copy link

viridia commented Oct 8, 2024

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

UI elements such as dialog boxes and popup menus need to be positioned in window coordinates. One way to do this is to create them as parentless elements, however there are downsides to this approach: it means, for example, that messages that are bubbled up the ancestor chain no longer reach their intended destinations.

Consider for example a menu button widget with a dropdown menu. We don't want the dropdown to be cut off if it's too tall, so we need to clip its size to the window size, and possibly "flip" it to the other side of the button if there is insufficient space. However, we also want the dropdown to behave like a child:

  • The dropdown is despawned when the button is.
  • Messages emitted by children of the dropdown can be received by the parent.

In CSS, this can be done in a variety of ways, one of which is position: fixed, which is an alternative to position: absolute or position: relative. It indicates that the element should be positioned relative to the window rect rather than to its parent element rect, and in all other respects behaviors like position: absolute.

What solution would you like?

A Position::Fixed would behave similarly to the CSS position: fixed, in that it would always compute the parent rectangle using the window bounds - in other words, it would treat the element like it had no parent. In all other respects it would behave like Absolute positioning.

What alternative(s) have you considered?

There are workarounds, including:

  • Implement this function in Bevy by lying to Taffy about the parent rectangle.
  • Use parentless elements with some other means of tracking ownership (doesn't solve the messaging issue).

However, none of these solutions are as clean.

Additional context

Bevy issue for this: bevyengine/bevy#9564

@viridia viridia added the enhancement New feature or request label Oct 8, 2024
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

1 participant