Scrollbar initial values
This commit is contained in:
parent
4e17ef1e09
commit
df1d1dddc6
3 changed files with 27 additions and 14 deletions
|
|
@ -116,13 +116,19 @@ impl App {
|
|||
fn render(&mut self) {
|
||||
let _ = self.terminal.draw(|frame| {
|
||||
let area = frame.area();
|
||||
|
||||
const HEADER_HEIGHT: u16 = 3;
|
||||
const FOOTER_HEIGHT: u16 = 3;
|
||||
|
||||
let max_content_height = area.height.saturating_sub(HEADER_HEIGHT + FOOTER_HEIGHT);
|
||||
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(1),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(HEADER_HEIGHT),
|
||||
Constraint::Length(max_content_height.max(1)),
|
||||
Constraint::Length(FOOTER_HEIGHT),
|
||||
])
|
||||
.split(area);
|
||||
|
||||
|
|
@ -177,7 +183,13 @@ impl App {
|
|||
.begin_symbol(Some("↑"))
|
||||
.end_symbol(Some("↓"));
|
||||
|
||||
frame.render_stateful_widget(scrollbar, area[1], &mut state.scroll_state);
|
||||
frame.render_stateful_widget(
|
||||
scrollbar,
|
||||
area[1],
|
||||
&mut state
|
||||
.scroll_state
|
||||
.viewport_content_length(area[0].height as usize),
|
||||
);
|
||||
}
|
||||
|
||||
fn handle_events(&mut self) -> io::Result<()> {
|
||||
|
|
@ -191,12 +203,10 @@ impl App {
|
|||
|
||||
match key.code {
|
||||
KeyCode::Char('q') | KeyCode::Esc => self.should_quit = true,
|
||||
KeyCode::Up | KeyCode::Char('k') => {
|
||||
self.state.scroll_state.prev();
|
||||
}
|
||||
KeyCode::Down | KeyCode::Char('j') => {
|
||||
self.state.scroll_state.next();
|
||||
}
|
||||
KeyCode::Up | KeyCode::Char('k') => self.state.scroll_state.prev(),
|
||||
KeyCode::Down | KeyCode::Char('j') => self.state.scroll_state.next(),
|
||||
KeyCode::Home => self.state.scroll_state.first(),
|
||||
KeyCode::End => self.state.scroll_state.last(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue