Make sure the scroll bar is never outside the screen rectangle (#475)

* Make sure the scroll bar is never outside the screen rectangle

This is an alternative attempt to fix the bug mentioned in
https://github.com/emilk/egui/pull/392

egui expects that the container can always be made wider,
which is true for all egui Ui:s, but not true for the outer
frame/chrome that egui ultimately needs to sit within.

* Clamp scroll to screen rect rather than available rect

* Fix scrollbar spacing when shrinking too small

* Update changelog
This commit is contained in:
Emil Ernerfeldt 2021-06-12 14:30:42 +02:00 committed by GitHub
parent e007afc3c3
commit 998e07d865
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View file

@ -28,6 +28,9 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
* `TopPanel::top` is now `TopBottomPanel::top`.
* `SidePanel::left` no longet takes the default width by argument, but by a builder call.
### Fixed 🐛
* Fix invisible scroll bar when native window is too narrow for egui.
## 0.12.0 - 2021-05-10 - Multitouch, user memory, window pivots, and improved plots

View file

@ -267,6 +267,7 @@ impl Prepared {
state.offset.y = offset_y + spacing;
}
let inner_rect = {
let width = if inner_rect.width().is_finite() {
inner_rect.width().max(content_size.x) // Expand width to fit content
} else {
@ -274,7 +275,19 @@ impl Prepared {
content_size.x
};
let inner_rect = Rect::from_min_size(inner_rect.min, vec2(width, inner_rect.height()));
let mut inner_rect =
Rect::from_min_size(inner_rect.min, vec2(width, inner_rect.height()));
// The window that egui sits in can't be expanded by egui, so we need to respect it:
let max_x = ui.input().screen_rect().right()
- current_scroll_bar_width
- ui.spacing().item_spacing.x;
inner_rect.max.x = inner_rect.max.x.at_most(max_x);
// TODO: when we support it, we should maybe auto-enable
// horizontal scrolling if this limit is reached
inner_rect
};
let outer_rect = Rect::from_min_size(
inner_rect.min,