Fix the page growing while scrolled: close panel rows at their own bottom

end_row folded the panels' bottoms from 0.0, so a row whose bottom was above
the top of the window (negative screen y while scrolled) was closed at y=0.
Everything after it was placed from there, the scroll content grew by the
scroll offset, and the scroll bar kept shrinking at the bottom. The lowest
bottom is now a plain function in fmt with a native test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-28 18:02:00 -07:00
1 parent 3ede855fbb
commit 9630b96c1b
2 files changed
+17 -1

No files matched your search

+16
View File
@@ -9,6 +9,13 @@ pub fn previous_label(range: Range) -> String {
format!("previous {}", label.strip_prefix("last ").unwrap_or(label))
}
/// The lowest edge of a row of panels: the largest of their `bottoms`, or
/// `empty` when there are none. The bottoms are screen positions, so they are
/// negative while the row is scrolled above the top of the window.
pub fn lowest(bottoms: impl IntoIterator<Item = f32>, empty: f32) -> f32 {
bottoms.into_iter().reduce(f32::max).unwrap_or(empty)
}
/// Whole-number percentages of `parts` that add up to exactly 100, giving the
/// leftovers of rounding to the largest shares. All zero when nothing is counted.
pub fn shares(parts: &[u64]) -> Vec<u64> {
@@ -229,6 +236,15 @@ pub fn hidden_after_all<'a>(ticked: bool, languages: impl Iterator<Item = &'a st
mod tests {
use super::*;
#[test]
fn a_row_scrolled_above_the_window_still_ends_at_its_own_bottom() {
// Rows closed by their lowest panel: the same answer wherever the page is scrolled.
assert_eq!(lowest([260.0, 300.0, 280.0], 0.0), 300.0);
assert_eq!(lowest([-340.0, -300.0, -320.0], 0.0), -300.0);
assert_eq!(lowest([-17250.0, -17210.5], 0.0), -17210.5);
assert_eq!(lowest([], 42.0), 42.0);
}
#[test]
fn counts_have_thousands_separators() {
assert_eq!(count(0), "0");
+1 -1
View File
@@ -71,7 +71,7 @@ pub fn cells(ui: &Ui, height: f32, spans: &[usize]) -> Vec<Rect> {
/// Close a row of panels drawn at `rects`: the cursor moves below the tallest.
pub fn end_row(ui: &mut Ui, rects: &[Rect]) {
let bottom = rects.iter().map(|rect| rect.bottom()).fold(0.0, f32::max);
let bottom = crate::fmt::lowest(rects.iter().map(|rect| rect.bottom()), ui.cursor().top());
let left = rects.first().map_or(ui.cursor().left(), |rect| rect.left());
ui.allocate_rect(
Rect::from_min_max(Pos2::new(left, ui.cursor().top()), Pos2::new(ui.cursor().right(), bottom)),