mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-21 20:23:11 +00:00
Add backwards fill
This commit is contained in:
parent
0dc25e7c2a
commit
7a4897d2b3
1 changed files with 12 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue