diff --git a/crates/ui/src/fmt.rs b/crates/ui/src/fmt.rs index ef2408c..f516131 100644 --- a/crates/ui/src/fmt.rs +++ b/crates/ui/src/fmt.rs @@ -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, 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 { @@ -229,6 +236,15 @@ pub fn hidden_after_all<'a>(ticked: bool, languages: impl Iterator Vec { /// 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)),