Skip to content

Store a Ui/Frame-stack #4534

@emilk

Description

@emilk

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.

Metadata

Metadata

Assignees

Labels

layoutRelated to widget layoutrerunDesired for Rerun.iostylevisuals and theming

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions