wip: scrolling and some more styling

This commit is contained in:
Jeremy Wall 2025-02-28 21:21:43 -05:00
parent 80713bc3e9
commit bce69a5604
3 changed files with 38 additions and 29 deletions

View File

@ -77,6 +77,7 @@ pub struct AppState<'ws> {
pub numeric_prefix: Vec<char>, pub numeric_prefix: Vec<char>,
pub char_queue: Vec<char>, pub char_queue: Vec<char>,
pub range_select: RangeSelection, pub range_select: RangeSelection,
pub dialog_scroll: u16,
dirty: bool, dirty: bool,
popup: Text<'ws>, popup: Text<'ws>,
clipboard: Option<ClipboardContents>, clipboard: Option<ClipboardContents>,
@ -91,6 +92,7 @@ impl<'ws> Default for AppState<'ws> {
numeric_prefix: Default::default(), numeric_prefix: Default::default(),
char_queue: Default::default(), char_queue: Default::default(),
range_select: Default::default(), range_select: Default::default(),
dialog_scroll: 0,
dirty: Default::default(), dirty: Default::default(),
popup: Default::default(), popup: Default::default(),
clipboard: Default::default(), clipboard: Default::default(),
@ -332,6 +334,12 @@ impl<'ws> Workspace<'ws> {
KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => { KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => {
self.exit_dialog_mode()? self.exit_dialog_mode()?
} }
KeyCode::Char('j') | KeyCode::Down => {
self.state.dialog_scroll = self.state.dialog_scroll.saturating_add(1);
}
KeyCode::Char('k') | KeyCode::Up => {
self.state.dialog_scroll = self.state.dialog_scroll.saturating_sub(1);
}
_ => { _ => {
// NOOP // NOOP
} }

View File

@ -3,7 +3,7 @@ use ratatui::{
layout::{Constraint, Layout, Rect}, layout::{Constraint, Layout, Rect},
style::{Color, Style, Stylize}, style::{Color, Style, Stylize},
text::Text, text::Text,
widgets::{Block, Paragraph, Widget}, widgets::{Block, Paragraph, Widget, Wrap},
}; };
pub struct Dialog<'w> { pub struct Dialog<'w> {
@ -21,8 +21,8 @@ impl<'w> Dialog<'w> {
} }
} }
pub fn scroll(mut self, scroll: (u16, u16)) -> Self { pub fn scroll(mut self, line: u16) -> Self {
self.scroll = scroll; self.scroll.0 = line;
self self
} }
} }
@ -44,8 +44,10 @@ impl<'w> Widget for Dialog<'w> {
let dialog_block = Block::bordered() let dialog_block = Block::bordered()
.title_top(self.title) .title_top(self.title)
.title_bottom("j,k or up,down to scroll")
.style(Style::default().on_black()); .style(Style::default().on_black());
let dialog = Paragraph::new(self.content.clone()) let dialog = Paragraph::new(self.content.clone())
.wrap(Wrap::default())
.scroll(self.scroll.clone()) .scroll(self.scroll.clone())
.block(dialog_block) .block(dialog_block)
.style(Style::default()); .style(Style::default());

View File

@ -98,11 +98,10 @@ impl<'widget, 'ws: 'widget> Widget for &'widget mut Workspace<'ws> {
where where
Self: Sized, Self: Sized,
{ {
if self.state.modality() == &Modality::Dialog { if self.state.modality() == &Modality::Dialog {
// Use a popup here. // Use a popup here.
let lines = Text::from_iter(self.state.popup.iter().cloned()); let lines = Text::from_iter(self.state.popup.iter().cloned());
let popup = dialog::Dialog::new(lines, "Help").scroll((0, 0)); let popup = dialog::Dialog::new(lines, "Help").scroll(self.state.dialog_scroll);
//let popup = Paragraph::new(lines); //let popup = Paragraph::new(lines);
popup.render(area, buf); popup.render(area, buf);
} else { } else {