Merge scroll fix: a row scrolled above the window ends at its own bottom
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
commit
29e5103648
2 files changed
+17
-1
No files matched your search
@@ -9,6 +9,13 @@ pub fn previous_label(range: Range) -> String {
|
|||||||
format!("previous {}", label.strip_prefix("last ").unwrap_or(label))
|
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
|
/// 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.
|
/// leftovers of rounding to the largest shares. All zero when nothing is counted.
|
||||||
pub fn shares(parts: &[u64]) -> Vec<u64> {
|
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 {
|
mod tests {
|
||||||
use super::*;
|
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]
|
#[test]
|
||||||
fn counts_have_thousands_separators() {
|
fn counts_have_thousands_separators() {
|
||||||
assert_eq!(count(0), "0");
|
assert_eq!(count(0), "0");
|
||||||
|
|||||||
@@ -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.
|
/// Close a row of panels drawn at `rects`: the cursor moves below the tallest.
|
||||||
pub fn end_row(ui: &mut Ui, rects: &[Rect]) {
|
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());
|
let left = rects.first().map_or(ui.cursor().left(), |rect| rect.left());
|
||||||
ui.allocate_rect(
|
ui.allocate_rect(
|
||||||
Rect::from_min_max(Pos2::new(left, ui.cursor().top()), Pos2::new(ui.cursor().right(), bottom)),
|
Rect::from_min_max(Pos2::new(left, ui.cursor().top()), Pos2::new(ui.cursor().right(), bottom)),
|
||||||
|
|||||||
Reference in new issue
Block a user