mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 23:00:04 -04:00
Include popups and tooltips in Harness::fit_contents (#7556)
This makes `Harness::fit_contents` also use popups and tooltips to compute the size of the contents.
This commit is contained in:
@@ -276,14 +276,39 @@ impl<'a, State> Harness<'a, State> {
|
||||
self.output = output;
|
||||
}
|
||||
|
||||
/// Calculate the rect that includes all popups and tooltips.
|
||||
fn compute_total_rect_with_popups(&self) -> Option<Rect> {
|
||||
// Start with the standard response rect
|
||||
let mut used = if let Some(response) = self.response.as_ref() {
|
||||
response.rect
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
||||
// Add all visible areas from other orders (popups, tooltips, etc.)
|
||||
self.ctx.memory(|mem| {
|
||||
mem.areas()
|
||||
.visible_layer_ids()
|
||||
.into_iter()
|
||||
.filter(|layer_id| layer_id.order != egui::Order::Background)
|
||||
.filter_map(|layer_id| mem.area_rect(layer_id.id))
|
||||
.for_each(|area_rect| used |= area_rect);
|
||||
});
|
||||
|
||||
Some(used)
|
||||
}
|
||||
|
||||
/// Resize the test harness to fit the contents. This only works when creating the Harness via
|
||||
/// [`Harness::new_ui`] / [`Harness::new_ui_state`] or
|
||||
/// [`HarnessBuilder::build_ui`] / [`HarnessBuilder::build_ui_state`].
|
||||
pub fn fit_contents(&mut self) {
|
||||
self._step(true);
|
||||
if let Some(response) = &self.response {
|
||||
self.set_size(response.rect.size());
|
||||
|
||||
// Calculate size including all content (main UI + popups + tooltips)
|
||||
if let Some(rect) = self.compute_total_rect_with_popups() {
|
||||
self.set_size(rect.size());
|
||||
}
|
||||
|
||||
self.run_ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user