1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

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).
This commit is contained in:
Lucas Meurer
2026-03-24 11:04:36 +01:00
committed by GitHub
parent 91effb9e57
commit c0ea6117e0
3 changed files with 18 additions and 5 deletions

View File

@@ -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<'_> { impl Widget for AtomLayout<'_> {
fn ui(self, ui: &mut Ui) -> Response { fn ui(self, ui: &mut Ui) -> Response {
self.show(ui).response self.show(ui).response

View File

@@ -409,7 +409,7 @@ impl<'t> TextEdit<'t> {
impl Widget for TextEdit<'_> { impl Widget for TextEdit<'_> {
fn ui(self, ui: &mut Ui) -> Response { 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. // so we can clip it to the available size. Thus, extract it from the atom closure here.
let mut get_galley = None; let mut get_galley = None;
let inner_rect_id = Id::new("text_edit_rect"); let inner_rect_id = Id::new("text_edit_rect");
let atom_response = { let mut response = {
let any_shrink = hint_text.any_shrink(); let any_shrink = hint_text.any_shrink();
// Ideally we could just do `let mut atoms = prefix` here, but that won't compile // 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). // but due to servo/rust-smallvec#146 (also see the comment below).
@@ -716,8 +716,7 @@ impl TextEdit<'_> {
allocated.paint(ui) allocated.paint(ui)
}; };
let inner_rect = atom_response.rect(inner_rect_id).unwrap_or(Rect::ZERO); let inner_rect = response.rect(inner_rect_id).unwrap_or(Rect::ZERO);
let mut response = atom_response.response;
// Our atom closure was now called, so the galley should always be available here // 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"); let mut galley = get_galley.expect("Galley should be available here");

View File

@@ -5,7 +5,7 @@ use crate::text::CCursorRange;
/// The output from a [`TextEdit`](crate::TextEdit). /// The output from a [`TextEdit`](crate::TextEdit).
pub struct TextEditOutput { pub struct TextEditOutput {
/// The interaction response. /// The interaction response.
pub response: crate::Response, pub response: crate::AtomLayoutResponse,
/// How the text was displayed. /// How the text was displayed.
pub galley: Arc<crate::Galley>, pub galley: Arc<crate::Galley>,