pub fn clamp_scroll(
app: &mut App,
messages_rect: Rect,
lines: &[Line<'_>],
) -> u16Expand 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_scrollis read and the computedmax_scrollis written viaAppState::set_chat_max_scroll.messages_rect— the panel rect including borders; interior height isheight - 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);