Expand Window + Resize areas to be large enough for last frames content

This commit is contained in:
Emil Ernerfeldt 2020-12-25 15:41:18 +01:00
parent 997cd4b279
commit cd7abb457f
2 changed files with 13 additions and 8 deletions

View file

@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* `Slider` and `DragValue` uses fewer decimals by default. See the full precision by hovering over the value.
* `egui::App`: added `fn name(&self)` and `fn clear_color(&self)`.
* Combo boxes has scroll bars when needed.
* Expand `Window` + `Resize` containers to be large enough for last frames content
* `ui.columns`: Columns now defaults to justified top-to-down layouts.
### Fixed 🐛

View file

@ -182,6 +182,8 @@ impl Resize {
.at_least(self.min_size)
.at_most(self.max_size);
let mut user_requested_size = state.requested_size.take();
let corner_response = if self.resizable {
// Resize-corner:
let corner_size = Vec2::splat(ui.style().visuals.resize_corner_size);
@ -191,7 +193,8 @@ impl Resize {
if corner_response.active {
if let Some(mouse_pos) = ui.input().mouse.pos {
state.desired_size = mouse_pos - position + 0.5 * corner_response.rect.size();
user_requested_size =
Some(mouse_pos - position + 0.5 * corner_response.rect.size());
}
}
Some(corner_response)
@ -199,9 +202,15 @@ impl Resize {
None
};
if let Some(requested_size) = state.requested_size.take() {
state.desired_size = requested_size;
if let Some(user_requested_size) = user_requested_size {
state.desired_size = user_requested_size;
} else {
// We are not being actively resized, so auto-expand to include size of last frame.
// This prevents auto-shrinking if the contents contain width-filling widgets (separators etc)
// but it makes a lot of interactions with `Window`s nicer.
state.desired_size = state.desired_size.max(state.last_content_size);
}
state.desired_size = state
.desired_size
.at_least(self.min_size)
@ -269,11 +278,6 @@ impl Resize {
ui.allocate_space(state.last_content_size);
}
if ui.memory().resize.get(&id).is_none() {
// First frame.
state.desired_size = state.desired_size.at_least(state.last_content_size);
}
// ------------------------------
if self.with_stroke && corner_response.is_some() {