Add backwards fill

This commit is contained in:
philippeitis 2021-10-15 11:33:53 -07:00 committed by GitHub
parent 0dc25e7c2a
commit 7a4897d2b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -151,6 +151,8 @@ impl<'a> List<'a> {
let mut end = offset;
let mut height = 0;
// Fills forwards until max_height is reached
// or no more items are left.
for item in self.items.iter().skip(offset) {
if height + item.height() > max_height {
break;
@ -158,6 +160,16 @@ impl<'a> List<'a> {
height += item.height();
end += 1;
}
// Fills backwards, if offset is too large
// and we have insufficient items.
for item in self.items[..start].iter().rev() {
if height + item.height() > max_height {
break;
}
height += item.height();
start -= 1;
}
(start, end)
}