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 char_queue: Vec<char>,
pub range_select: RangeSelection,
pub dialog_scroll: u16,
dirty: bool,
popup: Text<'ws>,
clipboard: Option<ClipboardContents>,
@ -91,6 +92,7 @@ impl<'ws> Default for AppState<'ws> {
numeric_prefix: Default::default(),
char_queue: Default::default(),
range_select: Default::default(),
dialog_scroll: 0,
dirty: Default::default(),
popup: Default::default(),
clipboard: Default::default(),
@ -332,6 +334,12 @@ impl<'ws> Workspace<'ws> {
KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => {
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
}

View File

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

View File

@ -98,41 +98,40 @@ impl<'widget, 'ws: 'widget> Widget for &'widget mut Workspace<'ws> {
where
Self: Sized,
{
if self.state.modality() == &Modality::Dialog {
// Use a popup here.
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);
popup.render(area, buf);
} else {
let outer_block = Block::bordered()
.title(Line::from(
self.name
.file_name()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|| String::from("Unknown")),
))
.title_bottom(match self.state.modality() {
Modality::Navigate => "navigate",
Modality::CellEdit => "edit",
Modality::Command => "command",
Modality::Dialog => "",
Modality::RangeSelect => "range-copy",
})
.title_bottom(
Line::from(format!(
"{},{}",
self.book.location.row, self.book.location.col
let outer_block = Block::bordered()
.title(Line::from(
self.name
.file_name()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|| String::from("Unknown")),
))
.right_aligned(),
);
.title_bottom(match self.state.modality() {
Modality::Navigate => "navigate",
Modality::CellEdit => "edit",
Modality::Command => "command",
Modality::Dialog => "",
Modality::RangeSelect => "range-copy",
})
.title_bottom(
Line::from(format!(
"{},{}",
self.book.location.row, self.book.location.col
))
.right_aligned(),
);
for (rect, f) in self.get_render_parts(area.clone()) {
f(rect, buf, self);
}
for (rect, f) in self.get_render_parts(area.clone()) {
f(rect, buf, self);
}
outer_block.render(area, buf);
outer_block.render(area, buf);
}
}
}