use lv_tui::prelude::*;
use lv_tui::widgets::{Column, Label, Scroll};
struct Root { body: Column }
impl Root {
fn new(body: Column) -> Self { Self { body } }
}
impl Component for Root {
fn render(&self, cx: &mut RenderCx) { self.body.render(cx); }
fn layout(&mut self, r: Rect, cx: &mut LayoutCx) { self.body.layout(r, cx); }
fn focusable(&self) -> bool { false }
fn event(&mut self, e: &Event, cx: &mut EventCx) {
if e.is_key(Key::Char('q')) { cx.quit(); }
if let Event::Key(_) = e { self.body.event(e, cx); }
}
fn for_each_child(&self, f: &mut dyn FnMut(&Node)) { self.body.for_each_child(f); }
fn for_each_child_mut(&mut self, f: &mut dyn FnMut(&mut Node)) { self.body.for_each_child_mut(f); }
}
fn main() -> lv_tui::Result<()> {
let mut scroll_content = Column::new().gap(0);
for i in 0..50 {
scroll_content = scroll_content.child(
Label::new(format!("Line {:02}: this is scrollable content", i))
);
}
let body = Column::new()
.padding(1).gap(1)
.child(Label::new("=== Scroll Demo (Up/Down to scroll) ==="))
.child(
Scroll::new(scroll_content)
)
.child(Label::new("press Up/Down to scroll, q to quit"));
lv_tui::app::App::new(Root::new(body)).run()
}