mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-23 05:19: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 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
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
|
@ -98,41 +98,40 @@ 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 {
|
||||||
let outer_block = Block::bordered()
|
let outer_block = Block::bordered()
|
||||||
.title(Line::from(
|
.title(Line::from(
|
||||||
self.name
|
self.name
|
||||||
.file_name()
|
.file_name()
|
||||||
.map(|p| p.to_string_lossy().to_string())
|
.map(|p| p.to_string_lossy().to_string())
|
||||||
.unwrap_or_else(|| String::from("Unknown")),
|
.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
|
|
||||||
))
|
))
|
||||||
.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()) {
|
for (rect, f) in self.get_render_parts(area.clone()) {
|
||||||
f(rect, buf, self);
|
f(rect, buf, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
outer_block.render(area, buf);
|
outer_block.render(area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user