use super::MatchListState;
use crate::incremental::ExtendIncremental;
#[inline]
pub fn larger(
previous: MatchListState,
mut total_remaining: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
total_remaining -= sizes_below_incl.extend_unbounded(total_remaining - previous.above);
sizes_above.extend_unbounded(total_remaining);
}
#[inline]
pub fn smaller(
previous: MatchListState,
mut total_remaining: u16,
padding_top: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
let max_allowed_above = previous
.above
.saturating_sub(previous.size - total_remaining)
.max(padding_top);
let max_allowed_below = total_remaining - max_allowed_above;
total_remaining -= sizes_below_incl.extend_unbounded(max_allowed_below);
sizes_above.extend_unbounded(total_remaining);
}
#[inline]
pub fn larger_rev(
previous: MatchListState,
mut total_remaining: u16,
padding_top: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
let new_size = total_remaining;
total_remaining -= sizes_below_incl.extend_bounded(total_remaining - padding_top, 1);
total_remaining -= sizes_above.extend_unbounded(total_remaining.min(new_size - previous.below));
sizes_below_incl.extend_unbounded(total_remaining);
}
#[inline]
pub fn smaller_rev(
previous: MatchListState,
mut total_remaining: u16,
padding_top: u16,
padding_bottom: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
let screen_delta = previous.size - total_remaining;
let selection_size = sizes_below_incl.extend_bounded(total_remaining - padding_top, 1);
let max_allowed_below = previous
.below
.saturating_sub(screen_delta)
.max(padding_bottom + 1)
.max(selection_size);
let max_allowed_above = total_remaining - max_allowed_below;
total_remaining -= selection_size;
total_remaining -= sizes_above.extend_unbounded(max_allowed_above);
sizes_below_incl.extend_unbounded(total_remaining);
}