From c0ea6117e0526c86c8d113f316cf217d6bc04f86 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Tue, 24 Mar 2026 11:04:36 +0100 Subject: [PATCH] Use `AtomLayoutResponse` in `TextEditOutput` (#8003) This is necessary to add e.g. buttons as prefix/suffix within the textedit (so you can read the rect and place the button). I'm not sure if deref on the AtomLayoutResponse is the right call but it should make the migration easier and is generally convenient (but might lead to some confusion). --- crates/egui/src/atomics/atom_layout.rs | 14 ++++++++++++++ crates/egui/src/widgets/text_edit/builder.rs | 7 +++---- crates/egui/src/widgets/text_edit/output.rs | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/egui/src/atomics/atom_layout.rs b/crates/egui/src/atomics/atom_layout.rs index da7f672a1..c408146d6 100644 --- a/crates/egui/src/atomics/atom_layout.rs +++ b/crates/egui/src/atomics/atom_layout.rs @@ -520,6 +520,20 @@ impl AtomLayoutResponse { } } +impl Deref for AtomLayoutResponse { + type Target = Response; + + fn deref(&self) -> &Self::Target { + &self.response + } +} + +impl DerefMut for AtomLayoutResponse { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.response + } +} + impl Widget for AtomLayout<'_> { fn ui(self, ui: &mut Ui) -> Response { self.show(ui).response diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 50154102a..086cf3091 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -409,7 +409,7 @@ impl<'t> TextEdit<'t> { impl Widget for TextEdit<'_> { fn ui(self, ui: &mut Ui) -> Response { - self.show(ui).response + self.show(ui).response.response } } @@ -563,7 +563,7 @@ impl TextEdit<'_> { // so we can clip it to the available size. Thus, extract it from the atom closure here. let mut get_galley = None; let inner_rect_id = Id::new("text_edit_rect"); - let atom_response = { + let mut response = { let any_shrink = hint_text.any_shrink(); // Ideally we could just do `let mut atoms = prefix` here, but that won't compile // but due to servo/rust-smallvec#146 (also see the comment below). @@ -716,8 +716,7 @@ impl TextEdit<'_> { allocated.paint(ui) }; - let inner_rect = atom_response.rect(inner_rect_id).unwrap_or(Rect::ZERO); - let mut response = atom_response.response; + let inner_rect = response.rect(inner_rect_id).unwrap_or(Rect::ZERO); // Our atom closure was now called, so the galley should always be available here let mut galley = get_galley.expect("Galley should be available here"); diff --git a/crates/egui/src/widgets/text_edit/output.rs b/crates/egui/src/widgets/text_edit/output.rs index 8149bbe58..3339f325e 100644 --- a/crates/egui/src/widgets/text_edit/output.rs +++ b/crates/egui/src/widgets/text_edit/output.rs @@ -5,7 +5,7 @@ use crate::text::CCursorRange; /// The output from a [`TextEdit`](crate::TextEdit). pub struct TextEditOutput { /// The interaction response. - pub response: crate::Response, + pub response: crate::AtomLayoutResponse, /// How the text was displayed. pub galley: Arc,