mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 13:29:48 -04:00
wip: scrolling and some more styling
This commit is contained in:
parent
80713bc3e9
commit
bce69a5604
@ -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
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -98,11 +98,10 @@ 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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user