Skip to content

⚠️ Atom improvements: Atom::id, align, closure, max_size#7958

Merged
emilk merged 9 commits intomainfrom
lucas/atom-improvements
Mar 10, 2026
Merged

⚠️ Atom improvements: Atom::id, align, closure, max_size#7958
emilk merged 9 commits intomainfrom
lucas/atom-improvements

Conversation

@lucasmerlin
Copy link
Copy Markdown
Collaborator

@lucasmerlin lucasmerlin commented Mar 5, 2026

Migration guide:

  • AtomKind::Custom has been removed. You can now set an id to any kind via Atom::custom or AtomExt::atom_id.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 5, 2026

Preview available at https://egui-pr-preview.github.io/pr/7958-lucasatom-improvements
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 force-pushed the lucas/atom-improvements branch from e8e2fa4 to c2e9f55 Compare March 5, 2026 12:50
@lucasmerlin lucasmerlin added feature New feature or request egui labels Mar 5, 2026
@lucasmerlin lucasmerlin changed the title Atom improvements: id, align, closure, max_size Atom improvements: Atom::id, align, closure, max_size Mar 5, 2026
Change the signature from `impl IntoAtoms` to `Self` to avoid
lifetime issues when working with atoms of different lifetimes.
Use `push_left`/`push_right` in a loop as an alternative.
- Add `id` field to Atom/SizedAtom for custom rendering identification
- Add `align` field (Align2) for per-atom alignment within available space
- Add `AtomExt::atom_id` and `AtomExt::atom_align` builder methods
- Deprecate `AtomKind::Custom` in favor of `Atom::custom(id)` + `atom_id()`
- Replace `SizedAtomKind::Custom` with `SizedAtomKind::Sized`
- Move custom rect tracking from SizedAtomKind to SizedAtom::id
- Migrate DragValue to use new `atom.id` field
Add a closure-based atom kind for custom sizing logic. The closure
receives available size, wrap mode, and font selection, and returns
the intrinsic size and a SizedAtomKind.

Also hoists `wrap_mode` resolution out of the `Text` match arm so
all variants can use it.
Allows limiting the widget size below the available Ui size.
Has no effect in justified layouts to avoid content/frame mismatch.
@lucasmerlin lucasmerlin force-pushed the lucas/atom-improvements branch from c2e9f55 to 324e188 Compare March 5, 2026 13:32
Comment on lines 75 to 76
#[deprecated = "Use Atom::custom(id) instead"]
Custom(Id),
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.

We could also remove this variant and add a deprecated function called fn Custom (sic). Might make the rest of the PR simpler

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.

That won't work since we can't set the Id that way. I've now removed Custom though, I doubt that saw much direct usage and migration should be simple enough.

@lucasmerlin lucasmerlin changed the title Atom improvements: Atom::id, align, closure, max_size ⚠️ Atom improvements: Atom::id, align, closure, max_size Mar 6, 2026
@emilk
Copy link
Copy Markdown
Owner

emilk commented Mar 6, 2026

I'm turning this into a draft until my comments above are resolved

@emilk emilk marked this pull request as draft March 6, 2026 14:42
@emilk emilk marked this pull request as ready for review March 10, 2026 08:01
@emilk emilk merged commit 8b90dc6 into main Mar 10, 2026
46 checks passed
@emilk emilk deleted the lucas/atom-improvements branch March 10, 2026 11:03
Masterchef365 pushed a commit to Masterchef365/egui that referenced this pull request Apr 3, 2026
…lk#7958)

Migration guide:
- `AtomKind::Custom` has been removed. You can now set an id to any kind
via `Atom::custom` or `AtomExt::atom_id`.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants