Skip to content

Position::Fixed - window-relative positioning #718

@viridia

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions