Skip to content

TextEdit Atom prefix/suffix#7587

Merged
lucasmerlin merged 36 commits intomainfrom
lucas/atomize-text-edit
Mar 20, 2026
Merged

TextEdit Atom prefix/suffix#7587
lucasmerlin merged 36 commits intomainfrom
lucas/atomize-text-edit

Conversation

@lucasmerlin
Copy link
Copy Markdown
Collaborator

@lucasmerlin lucasmerlin commented Oct 6, 2025

This PR changes the layout within the TextEdit to be done with AtomLayout. It also adds a Prefix and Postfix that allows adding permanent icons / icon buttons within the textedit.

Breaking changes:

  • Removed TextEdit::hint_text_font. Hint text is an atom now, so the font can be set that way
Screenshot 2025-10-06 at 12 25 21

@lucasmerlin lucasmerlin added this to the 0.33.0 milestone Oct 6, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 8, 2025

Preview available at https://egui-pr-preview.github.io/pr/7587-lucasatomize-text-edit
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 modified the milestones: 0.33.0, 0.34.0 Oct 9, 2025
@lucasmerlin lucasmerlin added feature New feature or request egui labels Mar 5, 2026
@lucasmerlin lucasmerlin changed the title Make TextEdit work with Atoms TextEdit Atom pre/postfixes Mar 5, 2026
@lucasmerlin lucasmerlin marked this pull request as ready for review March 5, 2026 09:36
@emilk emilk changed the title TextEdit Atom pre/postfixes TextEdit Atom prefix/suffix Mar 5, 2026
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.

I suggest we put this in a separate PR so it gets a separate entry in the changelog ("Added AtomKind::Closure and deprecated AtomKind::Custom")

@lucasmerlin lucasmerlin force-pushed the lucas/atomize-text-edit branch from 94c927c to 1992f0d Compare March 5, 2026 12:50
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/atomize-text-edit branch from 1992f0d to 0d6e754 Compare March 5, 2026 13:32
@lucasmerlin lucasmerlin force-pushed the lucas/atomize-text-edit branch from 0d6e754 to 5bb05a8 Compare March 6, 2026 14:14
@lucasmerlin lucasmerlin marked this pull request as draft March 6, 2026 14:16
@lucasmerlin lucasmerlin changed the base branch from main to lucas/atom-improvements March 9, 2026 10:11
Base automatically changed from lucas/atom-improvements to main March 10, 2026 11:03
# Conflicts:
#	crates/egui/src/atomics/atom_layout.rs
#	crates/egui/src/widgets/text_edit/builder.rs
#	crates/egui_demo_app/tests/snapshots/imageviewer.png
#	crates/egui_demo_lib/tests/snapshots/demos/Clipboard Test.png
#	crates/egui_demo_lib/tests/snapshots/demos/Code Example.png
#	crates/egui_demo_lib/tests/snapshots/demos/Font Book.png
#	crates/egui_demo_lib/tests/snapshots/demos/TextEdit.png
#	crates/egui_demo_lib/tests/snapshots/demos/Undo Redo.png
#	crates/egui_demo_lib/tests/snapshots/demos/Window Options.png
#	crates/egui_demo_lib/tests/snapshots/demos/Window Resize Test.png
#	tests/egui_tests/tests/snapshots/layout/text_edit.png
#	tests/egui_tests/tests/snapshots/layout/text_edit_clip.png
#	tests/egui_tests/tests/snapshots/layout/text_edit_placeholder_clip.png
#	tests/egui_tests/tests/snapshots/text_edit_rtl_1.png
#	tests/egui_tests/tests/snapshots/visuals/drag_value.png
@lucasmerlin lucasmerlin force-pushed the lucas/atomize-text-edit branch from 6c78c4c to d043b60 Compare March 18, 2026 14:15
@lucasmerlin lucasmerlin marked this pull request as ready for review March 18, 2026 14:46
@emilk
Copy link
Copy Markdown
Owner

emilk commented Mar 18, 2026

The screenshot tests shows some TextEdit shrunk - why is that exactly?

Comment on lines +527 to +530
// TODO(servo/rust-smallvec#146): Use extend_right instead of the loop once we have smallvec 2.0
for atom in prefix {
atoms.push_right(atom);
}
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 already have Atoms newtype wrapper that has .extend_right

Suggested change
// TODO(servo/rust-smallvec#146): Use extend_right instead of the loop once we have smallvec 2.0
for atom in prefix {
atoms.push_right(atom);
}
atoms.extend_right(prefix);

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 tried, but it wouldn't compile due to lifetime errors, due to the SmallVec issue linked in the todo comment.

Comment on lines -1152 to -1153
// Layout again to avoid frame delay, and to keep `text` and `galley` in sync.
*galley = layouter(ui, text, wrap_width);
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.

do we now have a frame delay? And is text and galley now out of sync?

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 can live with a frame-delay if it simplifies the code, but then maybe let's add a request_discard so we can avoid it when multi-pass is enabled?

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.

Found a nicer fix, which also allows me to remove the hack where we allocated extra space when the text was changed. Also added some tests for this.

@lucasmerlin
Copy link
Copy Markdown
Collaborator Author

The screenshot tests shows some TextEdit shrunk - why is that exactly?

Previously the style.text_edit_width was used for the inner width, meaning if it was 200, the text edit used slightly more than that for it's margins. Now this is the outer width, meaning it should be exactly 200 in width, which I feel is the correct behavior.

Copy link
Copy Markdown
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

awesome!

@lucasmerlin lucasmerlin merged commit 8b23153 into main Mar 20, 2026
46 checks passed
@lucasmerlin lucasmerlin deleted the lucas/atomize-text-edit branch March 20, 2026 10:29
lucasmerlin added a commit that referenced this pull request Mar 24, 2026
This broke in #7587

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
Masterchef365 pushed a commit to Masterchef365/egui that referenced this pull request Apr 3, 2026
* part of emilk#7264
* part of emilk#7445

This PR changes the layout within the TextEdit to be done with
AtomLayout. It also adds a Prefix and Postfix that allows adding
permanent icons / icon buttons within the textedit.

Breaking changes:
- Removed `TextEdit::hint_text_font`. Hint text is an atom now, so the
font can be set that way

<img width="264" height="130" alt="Screenshot 2025-10-06 at 12 25 21"
src="https://github.com/user-attachments/assets/03b6b56b-ca82-4ac3-b5c0-585cca336834"
/>

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
Co-authored-by: lucasmerlin <[email protected]>
Masterchef365 pushed a commit to Masterchef365/egui that referenced this pull request Apr 3, 2026
This broke in emilk#7587

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
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.

3 participants