Add `Response::intrinsic_size` to enable better layout in 3rd party crates (#5082)
This adds a `intrinsic_size` field to the Response struct which allows me to grow a egui button frame while still being able to know it's intrinsic size in [egui_flex](https://github.com/lucasmerlin/hello_egui/tree/main/crates/egui_flex) * Related to https://github.com/emilk/egui/issues/4378#issuecomment-2333800938 * [X] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
2a40d16e5a
commit
bfafddfdec
|
|
@ -1212,6 +1212,7 @@ impl Context {
|
||||||
is_pointer_button_down_on: false,
|
is_pointer_button_down_on: false,
|
||||||
interact_pointer_pos: None,
|
interact_pointer_pos: None,
|
||||||
changed: false,
|
changed: false,
|
||||||
|
intrinsic_size: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,18 @@ pub struct Response {
|
||||||
/// for instance if an existing slider value was clamped to the given range.
|
/// for instance if an existing slider value was clamped to the given range.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub changed: bool,
|
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<Vec2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
|
|
@ -1144,6 +1156,7 @@ impl Response {
|
||||||
|| other.is_pointer_button_down_on,
|
|| other.is_pointer_button_down_on,
|
||||||
interact_pointer_pos: self.interact_pointer_pos.or(other.interact_pointer_pos),
|
interact_pointer_pos: self.interact_pointer_pos.or(other.interact_pointer_pos),
|
||||||
changed: self.changed || other.changed,
|
changed: self.changed || other.changed,
|
||||||
|
intrinsic_size: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1050,7 +1050,9 @@ impl Ui {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn allocate_response(&mut self, desired_size: Vec2, sense: Sense) -> Response {
|
pub fn allocate_response(&mut self, desired_size: Vec2, sense: Sense) -> Response {
|
||||||
let (id, rect) = self.allocate_space(desired_size);
|
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.
|
/// Returns a [`Rect`] with exactly what you asked for.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue