Skip to main content

compute_updates_modal_scroll_for_selection

Function compute_updates_modal_scroll_for_selection 

Source
pub fn compute_updates_modal_scroll_for_selection(
    entry_line_starts: &[u16],
    total_lines: u16,
    content_rect: Option<(u16, u16, u16, u16)>,
    selected: usize,
    total_items: usize,
    current_scroll: u16,
) -> u16
Expand description

What: Compute updates-modal scroll offset that keeps the selected entry visible.

Inputs:

  • entry_line_starts: Mapping from entry index to first rendered line in wrapped output.
  • total_lines: Total rendered line count across wrapped updates rows.
  • content_rect: Optional updates content rectangle tuple (x, y, width, height).
  • selected: Selected entry index.
  • total_items: Number of entries in the updates list.
  • current_scroll: Existing scroll offset before adjustment.

Output:

  • Returns the next clamped scroll offset as u16.

Details:

  • Derives visible_lines from content_rect height and falls back to 1 when absent.
  • Uses rendered-line mapping to support wrapped rows consistently.
  • Clamps output to valid range to prevent underflow/overscroll.