diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 162ff4a739e..1a1e5f6c212 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1147,6 +1147,7 @@ impl Context { is_pointer_button_down_on: false, interact_pointer_pos: None, changed: false, + intrinsic_size: None, }; self.write(|ctx| { diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index d6a9a8a0c7f..bac50977a0c 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -118,6 +118,18 @@ pub struct Response { /// Always `false` for something like a [`Button`](crate::Button). #[doc(hidden)] pub changed: bool, + + /// The intrinsic / desired size of the widget. + /// + /// For a button, this will be the size of the label + the frames padding, + /// even if the button is laid out in a justified layout and the actual size will be larger. + /// + /// If this is `None`, use [`Self::rect`] instead. + /// + /// At the time of writing, this is only used by external crates + /// for improved layouting. + /// See for instance [`egui_flex`](https://github.com/lucasmerlin/hello_egui/tree/main/crates/egui_flex). + pub intrinsic_size: Option, } impl Response { @@ -1137,6 +1149,7 @@ impl Response { || other.is_pointer_button_down_on, interact_pointer_pos: self.interact_pointer_pos.or(other.interact_pointer_pos), changed: self.changed || other.changed, + intrinsic_size: None, } } } diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index ac31bf4856c..7a869fde749 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1035,7 +1035,9 @@ impl Ui { /// ``` pub fn allocate_response(&mut self, desired_size: Vec2, sense: Sense) -> Response { let (id, rect) = self.allocate_space(desired_size); - self.interact(rect, id, sense) + let mut response = self.interact(rect, id, sense); + response.intrinsic_size = Some(desired_size); + response } /// Returns a [`Rect`] with exactly what you asked for.