use super::MatchListState;
use crate::{incremental::ExtendIncremental, util::as_usize};
#[inline]
pub fn incr(
previous: MatchListState,
cursor: u32,
padding_top: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
let mut total_remaining = previous.size;
let new_size_above = sizes_below_incl.extend_bounded(
total_remaining - padding_top,
as_usize(cursor - previous.selection),
);
total_remaining -= new_size_above;
let max_allowed_above = previous
.above
.saturating_sub(new_size_above)
.max(padding_top);
sizes_above.extend_unbounded(max_allowed_above);
sizes_below_incl.extend_unbounded(total_remaining - max_allowed_above);
}
#[inline]
pub fn decr(
previous: MatchListState,
cursor: u32,
padding_top: u16,
padding_bottom: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
let mut total_remaining = previous.size;
let selection_rendered = sizes_below_incl.extend_bounded(total_remaining - padding_top, 1);
total_remaining -= selection_rendered;
total_remaining -=
sizes_below_incl.extend_unbounded((padding_bottom + 1).saturating_sub(selection_rendered));
total_remaining -=
sizes_above.extend_bounded(total_remaining, as_usize(previous.selection - cursor));
let max_space_below = total_remaining - total_remaining.min(previous.above);
total_remaining -= sizes_below_incl.extend_unbounded(max_space_below);
sizes_above.extend_unbounded(total_remaining);
}
#[inline]
pub fn incr_rev(
previous: MatchListState,
cursor: u32,
padding_top: u16,
padding_bottom: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
let mut total_remaining = previous.size;
let selection_rendered = sizes_below_incl.extend_bounded(total_remaining - padding_top, 1);
total_remaining -= selection_rendered;
let rendered_above = sizes_above.extend_bounded(
total_remaining.min(previous.size - padding_bottom - 1),
as_usize(cursor - previous.selection),
);
total_remaining -= rendered_above;
let max_space_above = previous.size
- (rendered_above + selection_rendered.max(padding_bottom + 1)).max(previous.below);
total_remaining -= sizes_above.extend_unbounded(max_space_above);
sizes_below_incl.extend_unbounded(total_remaining);
}
#[inline]
pub fn decr_rev(
previous: MatchListState,
cursor: u32,
padding_top: u16,
mut sizes_below_incl: impl ExtendIncremental,
mut sizes_above: impl ExtendIncremental,
) {
let mut total_remaining = previous.size;
let new_size_above = sizes_below_incl.extend_bounded(
total_remaining - padding_top,
as_usize(previous.selection - cursor),
);
total_remaining -= new_size_above;
let max_space_above = (previous.size - previous.below)
.saturating_sub(new_size_above)
.max(padding_top);
total_remaining -= sizes_above.extend_unbounded(max_space_above);
sizes_below_incl.extend_unbounded(total_remaining);
}