generated from GarandPLG/rust-flake-template
Add scrolling actions and board widget
Introduce directional and scroll actions, update keybindings, add scrollbar state to SkirmishState, and render the board with a new BoardWidget. Adjust CLI defaults and layout heights accordingly.
This commit is contained in:
+17
-13
@@ -1,4 +1,8 @@
|
||||
use crate::app::{App, keybindings::Action, widgets::KeybindingsWidget};
|
||||
use crate::app::{
|
||||
App,
|
||||
keybindings::Action,
|
||||
widgets::{BoardWidget, KeybindingsWidget},
|
||||
};
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Alignment, Constraint, Layout, Margin, Rect},
|
||||
@@ -11,7 +15,7 @@ pub fn skirmish_view(app: &App, area: Rect, buf: &mut Buffer) {
|
||||
let vertical_layout: Layout = Layout::vertical([
|
||||
Constraint::Length(4),
|
||||
Constraint::Fill(1),
|
||||
Constraint::Length(4),
|
||||
Constraint::Length(6),
|
||||
]);
|
||||
|
||||
let [title_area, main_area, keybindings_area] = vertical_layout.areas(area);
|
||||
@@ -65,24 +69,24 @@ pub fn skirmish_view(app: &App, area: Rect, buf: &mut Buffer) {
|
||||
let board_area: Rect = board_block.inner(main_area);
|
||||
board_block.render(main_area, buf);
|
||||
|
||||
let inner_board_area: Rect = board_area.inner(Margin {
|
||||
let cells_area: Rect = board_area.inner(Margin {
|
||||
horizontal: 1,
|
||||
vertical: 1,
|
||||
});
|
||||
|
||||
let map_width: u16 = inner_board_area.width / (app.states.settings.map_width as u16);
|
||||
let map_height: u16 = inner_board_area.height / (app.states.settings.map_height as u16);
|
||||
|
||||
Paragraph::new(format!(
|
||||
"x = {}, y = {}, mw = {}, mh = {}",
|
||||
inner_board_area.width, inner_board_area.height, map_width, map_height
|
||||
))
|
||||
.block(Block::default())
|
||||
.render(inner_board_area, buf);
|
||||
BoardWidget::new(app, cells_area.width, cells_area.height).render(cells_area, buf);
|
||||
}
|
||||
|
||||
{
|
||||
let actions: Vec<Action> = vec![Action::Quit, Action::Quit2, Action::Esc];
|
||||
let actions: Vec<Action> = vec![
|
||||
Action::ScrollUp,
|
||||
Action::ScrollDown,
|
||||
Action::ScrollLeft,
|
||||
Action::ScrollRight,
|
||||
Action::Quit,
|
||||
Action::Quit2,
|
||||
Action::Esc,
|
||||
];
|
||||
|
||||
KeybindingsWidget::new(actions).render(keybindings_area, buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user