Skip to main content

clamp_scroll

Function clamp_scroll 

Source
pub fn clamp_scroll(
    app: &mut App,
    messages_rect: Rect,
    lines: &[Line<'_>],
) -> u16
Expand description

Clamp scroll offset so the visible slice of lines stays within messages_rect and honor the SCROLL_BOTTOM follow-tail sentinel.

The chat Paragraph is rendered without wrapping (see module docs), so the total rendered height equals lines.len() and no per-line width arithmetic is needed.

§Arguments

  • app — mutable app state; chat_scroll is read and the computed max_scroll is written via AppState::set_chat_max_scroll.
  • messages_rect — the panel rect including borders; interior height is height - 2.
  • lines — the rendered chat lines for this frame.

§Returns

The clamped scroll offset suitable for Paragraph::scroll((offset, 0)). Saturates at u16::MAX for safety on very tall buffers.

§Examples

let r = clamp_scroll(a, ratatui::layout::Rect::new(0, 0, 80, 24), &vec![]);
assert_eq!(r, 0);