Fix scroll: PgUp/PgDn move cursor in place, add Scrollbar widget
SectionTree.handle_nav() now takes viewport height: - PgUp/PgDn move both cursor and viewport by one page, keeping the cursor at the same screen position - Home/End jump to first/last item - scroll_to_selected() uses actual viewport height instead of hardcoded 30 Added render_scrollable() in widgets.rs: renders a Paragraph with a vertical Scrollbar when content exceeds the viewport. Used by the conscious and subconscious screens. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
818cdcc4e5
commit
19bb6d02e3
3 changed files with 74 additions and 39 deletions
|
|
@ -7,12 +7,11 @@ use ratatui::{
|
|||
layout::Rect,
|
||||
style::{Color, Style},
|
||||
text::Line,
|
||||
widgets::{Paragraph, Wrap},
|
||||
Frame,
|
||||
};
|
||||
|
||||
use super::{App, ScreenView, screen_legend};
|
||||
use super::widgets::{SectionTree, pane_block};
|
||||
use super::widgets::{SectionTree, pane_block, render_scrollable};
|
||||
|
||||
pub(crate) struct ConsciousScreen {
|
||||
agent: std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>,
|
||||
|
|
@ -41,7 +40,7 @@ impl ScreenView for ConsciousScreen {
|
|||
if let ratatui::crossterm::event::Event::Key(key) = event {
|
||||
if key.kind != ratatui::crossterm::event::KeyEventKind::Press { continue; }
|
||||
let context_state = self.read_context_state();
|
||||
self.tree.handle_nav(key.code, &context_state);
|
||||
self.tree.handle_nav(key.code, &context_state, area.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,11 +96,6 @@ impl ScreenView for ConsciousScreen {
|
|||
let block = pane_block("context")
|
||||
.title_top(Line::from(screen_legend()).left_aligned());
|
||||
|
||||
let para = Paragraph::new(lines)
|
||||
.block(block)
|
||||
.wrap(Wrap { trim: false })
|
||||
.scroll((self.tree.scroll, 0));
|
||||
|
||||
frame.render_widget(para, area);
|
||||
render_scrollable(frame, area, lines, block, self.tree.scroll);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue