Stream logs into a ScrollView
Recipe for offset slicing and scrollbars.
Stream logs into a ScrollView
Problem: show an unbounded line stream in a bounded viewport.
Steps:
- Keep
logs: Vec<String>andoffset: u16in view state. Render:
ScrollView::new()
.offset(self.offset)
.flex_grow(1.0)
.children(self.logs.iter().map(Text::new))
- Append lines from background actions; leave
offsetalone to pin the top, or clamp it to the bottom to tail the stream. - Drive
offsetfromUp/Downkeys withsaturating_sub/saturating_add— the position stays stable across frames. - A scrollbar (
█/│) appears automatically once content overflows the viewport.
Check: push 2,000 lines and confirm the frame stays interactive; the
runnable agent_dashboard example streams mock tool output this way:
cargo run -p veloce-tui --example agent_dashboard