1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Fix debug-panic in ScrollArea if contents fit without scrolling (#7440)

If the ScrollArea's contents are smaller than the inner rect, but the
scrollbar is set to always visible, clicking on it led to a remap from
an empty range to calculate the new offset, which triggered a debug
assertion in the remap function, because the result is indeterminate.

Since in this case there is no need to scroll, we just skip the remap
and set the offset to 0 directly.

* Closes <https://github.com/emilk/egui/issues/7362>
* [x] I have followed the instructions in the PR template
This commit is contained in:
YgorSouza
2025-08-14 10:41:51 +02:00
committed by Emil Ernerfeldt
parent 7036d6a982
commit b732992f69

View File

@@ -1315,11 +1315,13 @@ impl Prepared {
});
let new_handle_top = pointer_pos[d] - *scroll_start_offset_from_top_left;
state.offset[d] = remap(
new_handle_top,
scroll_bar_rect.min[d]..=(scroll_bar_rect.max[d] - handle_rect.size()[d]),
0.0..=max_offset[d],
);
let handle_travel =
scroll_bar_rect.min[d]..=(scroll_bar_rect.max[d] - handle_rect.size()[d]);
state.offset[d] = if handle_travel.start() == handle_travel.end() {
0.0
} else {
remap(new_handle_top, handle_travel, 0.0..=max_offset[d])
};
// some manual action taken, scroll not stuck
state.scroll_stuck_to_end[d] = false;