Skip to content

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

Open
lucasmerlin wants to merge 5 commits intomainfrom
lucas/atom-improvements
Open

Atom improvements: Atom::id, align, closure, max_size#7958
lucasmerlin wants to merge 5 commits intomainfrom
lucas/atom-improvements

Conversation

@lucasmerlin
Copy link
Collaborator

  • Add id field to Atom/SizedAtom for custom rendering identification
  • Add align field (Align2) for per-atom alignment within available space
  • Add AtomKind::Closure for custom sizing logic
  • Add max_size/max_width/max_height to AtomLayout
  • Deprecate AtomKind::Custom in favor of Atom::custom(id) / atom_id()
  • Replace SizedAtomKind::Custom with SizedAtomKind::Sized
  • Change Atoms::extend_left/extend_right to take Self instead of impl IntoAtoms
  • Add AtomExt::atom_id and AtomExt::atom_align builder methods

@github-actions
Copy link

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
/// }
/// # });
/// ```
#[deprecated = "Use Atom::custom(id) instead"]
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
#[deprecated = "Use Atom::custom(id) instead"]
#[deprecated = "Use Atom::custom(id, $what size do I put here?) instead"]

Comment on lines 75 to 76
#[deprecated = "Use Atom::custom(id) instead"]
Custom(Id),
Copy link
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

Text(Arc<Galley>),
Image(Image<'a>, Vec2),
Custom(Id),
Sized(Vec2),
Copy link
Owner

Choose a reason for hiding this comment

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

Aren't Text and Image sized too?

TextWrapMode,
FontSelection,
) -> (
Vec2,
Copy link
Owner

Choose a reason for hiding this comment

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

What is this? Can this return a named struct instead? And maybe group (some) of the params as a struct too?

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