You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you want to answer the question "What is this Ui part of?". For instance: sometimes you want to paint the background of a widget to extend to the edges of the panel it is in, but that panel may be several Uis removed from the current widget.
What you want is access to a stack of parent Ui frames, with some semantics.
Each stack should contain:
Id
Frame (inner & outer margins, stroke, …)
min_size and max_size (with/without margins)
Type (Panel, Area, Group, …)
We would push onto this stack each time we create a new Ui.
This means the root of the stack is created by Ui::new (most often created by Area/Window and Panel).
Then things like ui.group, ui.horizontal, egui::Frame etc would push onto this stack before calling into its contents, and then pop afterwards.
Working name: StackFrame.
Then we add impl Ui { pub fn stack(&self) -> &Stack { … } } and then users can walk the stack to implement advanced styling.
Implementation
Ui::new creates the stack as a Rc<RefCell<Stack>> and hands it to its children.
Future work: columns
We can use this architecture to implement columnar layouts, allowing aligning widgets that share an ancestor.
Each StackFrame has an optional field for column widths.
An egui::Grid would create such a special stack frame.
When adding a widget, we would walk up the stack to find which column we are in, and align to that, then register if we overflowed that width. ui.end_row() would reset a column=0.
Maybe this should be a separate stack? Probably.
Anyway, this requires more design, so let's not discuss this further here.
The text was updated successfully, but these errors were encountered:
* Closes#4534
This PR:
- Introduces `Ui::stack()`, which returns the `UiStack` structure
providing information on the current `Ui` hierarchy.
- **BREAKING**: `Ui::new()` now takes a `UiStackInfo` argument, which is
used to populate some of this `Ui`'s `UiStack`'s fields.
- **BREAKING**: `Ui::child_ui()` and `Ui::child_ui_with_id_source()` now
take an `Option<UiStackInfo>` argument, which is used to populate some
of the children `Ui`'s `UiStack`'s fields.
- New `Area::kind()` builder function, to set the `UiStackKind` value of
the `Area`'s `Ui`.
- Adds a (minimalistic) demo to egui demo (in the "Misc Demos" window).
- Adds a more thorough `test_ui_stack` test/playground demo.
TODO:
- [x] benchmarks
- [x] add example to demo
Future work:
- Add `UiStackKind` and related support for more container (e.g.
`CollapsingHeader`, etc.)
- Add a tag/property system that would allow adding arbitrary data to a
stack node. This data could then be queried by nested `Ui`s. Probably
needed for #3284.
- Add support to track columnar layouts.
---------
Co-authored-by: Emil Ernerfeldt <[email protected]>
hacknus
pushed a commit
to hacknus/egui
that referenced
this issue
Oct 30, 2024
* Closesemilk#4534
This PR:
- Introduces `Ui::stack()`, which returns the `UiStack` structure
providing information on the current `Ui` hierarchy.
- **BREAKING**: `Ui::new()` now takes a `UiStackInfo` argument, which is
used to populate some of this `Ui`'s `UiStack`'s fields.
- **BREAKING**: `Ui::child_ui()` and `Ui::child_ui_with_id_source()` now
take an `Option<UiStackInfo>` argument, which is used to populate some
of the children `Ui`'s `UiStack`'s fields.
- New `Area::kind()` builder function, to set the `UiStackKind` value of
the `Area`'s `Ui`.
- Adds a (minimalistic) demo to egui demo (in the "Misc Demos" window).
- Adds a more thorough `test_ui_stack` test/playground demo.
TODO:
- [x] benchmarks
- [x] add example to demo
Future work:
- Add `UiStackKind` and related support for more container (e.g.
`CollapsingHeader`, etc.)
- Add a tag/property system that would allow adding arbitrary data to a
stack node. This data could then be queried by nested `Ui`s. Probably
needed for emilk#3284.
- Add support to track columnar layouts.
---------
Co-authored-by: Emil Ernerfeldt <[email protected]>
Sometimes you want to answer the question "What is this Ui part of?". For instance: sometimes you want to paint the background of a widget to extend to the edges of the panel it is in, but that panel may be several
Ui
s removed from the current widget.What you want is access to a stack of parent Ui frames, with some semantics.
Each stack should contain:
Id
Frame
(inner & outer margins, stroke, …)min_size
andmax_size
(with/without margins)We would push onto this stack each time we create a new
Ui
.This means the root of the stack is created by
Ui::new
(most often created byArea/Window
andPanel
).Then things like
ui.group
,ui.horizontal
,egui::Frame
etc would push onto this stack before calling into its contents, and then pop afterwards.Working name:
StackFrame
.Then we add
impl Ui { pub fn stack(&self) -> &Stack { … } }
and then users can walk the stack to implement advanced styling.Implementation
Ui::new
creates the stack as aRc<RefCell<Stack>>
and hands it to its children.Future work: columns
We can use this architecture to implement columnar layouts, allowing aligning widgets that share an ancestor.
Each
StackFrame
has an optional field for column widths.An
egui::Grid
would create such a special stack frame.When adding a widget, we would walk up the stack to find which column we are in, and align to that, then register if we overflowed that width.
ui.end_row()
would reset a column=0.Maybe this should be a separate stack? Probably.
Anyway, this requires more design, so let's not discuss this further here.
The text was updated successfully, but these errors were encountered: