-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add PositionType::Fixed #9564
Comments
@nicoburns this feels like a feature we should implement in Taffy, and then expose in Bevy. Do you agree? |
You might not need to. The root element (that is, any UI element that doesn't have a parent) already has this behavior; perhaps all you need to do is layout the element as if it had no parent. |
I think this can be implemented quite easily in Bevy itself. The proposal makes a reasonable argument as to why it would be useful I guess. I'm not sure about the name, scrolling is something we are planning to implement and there is a PR #8104 though it hasn't seen much progress lately. Regardless, feels like we should be able to come up with something more descriptive than |
|
Other possible names:
|
I like |
|
Coming from CSS / Tailwind, Looking at the variants, I'm somewhat new to Rust and just getting into Bevy, so I am considering this as a good first issue to take and contribute! |
That sounds great! Link this issue in that PR and we'll give you some reviews :) |
Hello where to fix |
BTW, just to be clear - the reason I chose the word "fixed" is because:
In other words, web developers will know exactly what it means. Non-web developers will have to learn what it means :) |
@UkoeHB @nicoburns Some additional thoughts on implementation. There are two obvious approaches:
This raises some questions:
|
Both options seem fine to me. |
Wearing my |
@alice-i-cecile I had put the issue of fixed positions aside and focused on other things, but now that I'm finished with those other things this is once again a blocker (specifically, it's hindering my work on dialogs and popup menus in UI). What can we do to get this moving? I also wonder whether it would be more difficult to implement this in Taffy than in Bevy. I haven't looked at the Taffy code. I know that in the Bevy code, there is sufficient context information to be able to do this, but I don't know whether or not that is true in Taffy. Specifically: if the Taffy layout algorithm only contains information about the immediate parent, and not information about the absolute position of the item relative to the window, then this might require changing the Taffy APIs to include such information. For example: the Taffy Adding additional fields for absolute window coordinates might be a major breaking change for Taffy. I think doing this feature in Bevy might be significantly easier - what do you think? |
Let's start with it in Bevy then :) @nicoburns and I can upstream it later if desired. |
What problem does this solve or what need does it fill?
For modal dialogs and popup menus, it is helpful to be able to position an element relative to the window rather than its parent element.
What solution would you like?
Currently the UI
PositionType
enum supports two types of positioning:PositionType::Absolute
andPositionType::Relative
which correspond to the CSS propertiesposition: absolute
andposition: relative
. This proposal adds a third choice,PositionType::Fixed
which positions elements relative to the window, and which also corresponds to the CSS attribute of that name. In other words, the element's parent position is ignored, and instead its layout is considered as if its parent was the same coordinates and dimensions as the window.Note: the semantics of "fixed" as proposed here are slightly different than the meaning of the CSS property - a "fixed" element in CSS is one that never scrolls, and is always relative to the viewport. Since Bevy doesn't have scrolling, the difference is moot.
What alternative(s) have you considered?
For something like a modal dialog or popup menu, it's possible to work around this by creating a completely separate view hierarchy for the overlay element, and then using state variables to control the opening and closing of it.
However, this approach has a drawback, which means that you can no longer use event bubbling to communicate between the dialogue and the code that invoked it. (I know Bevy doesn't have bubbling yet, but bevy_eventlistener does, and I believe bubbling is a planned feature).
Particularly for popup menus, the logic for positioning a menu requires placing the menu in absolute window coordinates (often limiting the menu size or switching sides depending on the available space), but still communicating with the anchor element (such as the menu button) as if it were a child element. (This also requires knowing the coordinates of the anchor in absolute window coordinates, but that's a different problem).
Dialogues which represent major "game modes" are often root-level components and thus don't require this; however contextual dialogues which are triggered by some other UI element (such as a combo box) are often implemented as children of that element; requiring the dialogue to be a root involves additional boilerplate.
Additional context
Frameworks such as React and Solid also provide a feature known as "portals" which allow sub-components to render elements that are located at the root of the DOM but still communicate with their parents as though they were children. This feature covers some of the same use cases.
The text was updated successfully, but these errors were encountered: