Replies: 2 comments 2 replies
-
Working with egui, one quickly notices that the layout options are quite limited. You can have rows and columns of nodes, with different sizes, but you don't have all the layout options of flexbox or grid. The reason is that auto-sizing calculations requires two layout passes: a first pass to measure the minimum size of all elements, and a second pass to calculate the actual size. For example, in a flexbox scenario, you first calculate the minimum size of each item, and then if there is any space left over, you distribute that extra space to each child depending on the value of their This is difficult to do in an immediate-mode UI, since there's no way to determine the minimum size of the next sibling during layout, as it hasn't been created yet. Instead, layout constraints in an immediate-mode framework tend to be strictly "top-down". Depending on your layout needs, this tends to be either extremely frustrating or it doesn't affect you at all. |
Beta Was this translation helpful? Give feedback.
-
Got immediate mode working in bevy using 3rd approach. I insert, remove entities and components using Commands and I access already inserted UI data using queries. Video: immediate_mode.movAPI looks very similar to suggested API, except functions are implemented as normal systems. Will try to create a crate from this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Combining Immediate Mode UI with Retained Mode UI
Hello, I am the author of egui_taffy and currently working on a game called Settletopia.
I believe Bevy has a unique opportunity to combine the simplicity of an immediate mode UI API (like egui) with the retained mode UI that Bevy’s ECS excels at.
The Problem with Building UI in Bevy
Right now, creating deep hierarchies of interactable UI nodes is complex. Common tasks like:
require boilerplate (extra marker components, systems, and bundles). This makes UI code harder to reason about and slows iteration.
We need simpler API for fast prototype iteration and for UI code to be more easier to reason about.
Introducing Immediate Mode to Bevy
Imagine if we could build interactive UI in Bevy with a single function, extended with retained mode UI where necessary.
Here is a conceptual API sketch:
This example shows how we could:
I am already writing code like this using egui. Would love to use similar approach in bevy, where i could fall back to fully ECS implemented widgets where needed.
Why Don’t We Have This Yet?
In my understanding:
World
as game data, making it difficult to simultaneously insert/remove UI entities while accessing ECS data. Therefore additional data store is needed where differences need to be stored until they can be applied.Conceptually:
This would allow immediate updates to UI while still accessing/ modifying game data.
Possible Approaches
Scoped Worlds
Extend
world.resource_scope(...)
to allow something likeI’m unsure if this is technically feasible with Bevy’s ECS internals.
Separate UI World (similar to
RenderWorld
)UiWorld
.UiWorld
andAppWorld
from the sameSystemParam
. (there have been attempts to do this: Systems with parallelizable mutable access to multiple worlds. #16933)RenderWorld
as needed.This feels like the cleanest approach. But currently bevy tries to store everything in the main world.
Commands-based diffs
ui::Node
or other component directly. Likenode_ref.component_mut::<SomeComponent>().some_field = 10;
Related Work
and there are many others.
Summary
I believe combining immediate mode ergonomics with retained mode ECS power could make Bevy’s UI:
This is not a fully fleshed-out design, but rather a proposal to explore this direction. I hope this sparks discussion and inspires contributors to consider new approaches to Bevy UI.
Additional thoughts
It should be possible to even add immediate mode widgets inside retained mode widgets.
Beta Was this translation helpful? Give feedback.
All reactions