Skip to content

Add AtomKind::Layout, for nesting AtomLayout#8219

Open
lucasmerlin wants to merge 7 commits into
mainfrom
lucas/atom-layout-measure-paint-split
Open

Add AtomKind::Layout, for nesting AtomLayout#8219
lucasmerlin wants to merge 7 commits into
mainfrom
lucas/atom-layout-measure-paint-split

Conversation

@lucasmerlin

@lucasmerlin lucasmerlin commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

This allows you to put an AtomLayout inside another AtomLayout. Right now this has limited use, but once we add wrapping, vertical AtomLayout and AtomUi, this will be a really powerful new layouting primitive for egui.

Added a test for this in #8221

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Preview available at https://egui-pr-preview.github.io/pr/8219-lucasatom-layout-measure-paint-split
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@lucasmerlin lucasmerlin added feature New feature or request egui labels Jun 2, 2026
@lucasmerlin lucasmerlin marked this pull request as ready for review June 2, 2026 15:18
/// # });
#[derive(Clone, Debug, Default)]
pub struct Atoms<'a>(SmallVec<[Atom<'a>; ATOMS_SMALL_VEC_SIZE]>);
pub struct Atoms<'a>(Vec<Atom<'a>>);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the nesting was impossible with smallvec due to it being invariant (whatever that means). I've run into this before.
So I switched to Vec. We could also use tinyvec or the smallvec 2.0 beta, which fixes this problem.

@emilk emilk Jun 10, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means an additional allocation for each widget 😬 Something I really would like to avoid.

Have you benchmarked the impact of this?

@lucasmerlin lucasmerlin added the layout Related to widget layout label Jun 3, 2026
Comment on lines 32 to 45
pub struct AtomLayout<'a> {
id: Option<Id>,
pub atoms: Atoms<'a>,
gap: Option<f32>,
pub(crate) frame: Frame,
pub(crate) sense: Sense,
fallback_text_color: Option<Color32>,
fallback_font: Option<FontSelection>,
min_size: Vec2,
max_size: Vec2,
wrap_mode: Option<TextWrapMode>,
align2: Option<Align2>,
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should also split AtomLayout into a Widget (WidgetAtom?) and a Layout (ContainerAtom?) part. Because now it kinda does both, represent how a group of Atoms should be laid out / rendered (what Margin / Frame / etc), and how it should behave as a widget (what Id / Sense should it have).

We'd then still want both a AtomKind::Container and a AtomKind::Widget, since it allocating a Response is what makes the future AtomTrait work via reading back the Response.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented it here:
#8222

@emilk emilk left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to avoid that extra allocation 😬

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

Labels

egui feature New feature or request layout Related to widget layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants