generated from GarandPLG/rust-flake-template
Add bounded focus and padding to skirmish UI
- Initialize FocusedCell with map dimensions and start near the map centre. - Store max rows/cols in FocusedCell and clamp moves to these bounds. - Scroll actions now adjust the corresponding offset and also move the focused cell, keeping navigation consistent. - Zoom actions modify the vertical offset to keep the view centered after changing zoom levels. - Cell widget now uses a Padding widget with dynamic top padding based on the area height.
This commit is contained in:
@@ -2,7 +2,7 @@ use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Alignment, Rect},
|
||||
style::{Color, Style, Stylize},
|
||||
widgets::{Block, Borders, Paragraph, Widget},
|
||||
widgets::{Block, Borders, Padding, Paragraph, Widget},
|
||||
};
|
||||
|
||||
// pub enum CellTags {
|
||||
@@ -59,7 +59,13 @@ impl Widget for CellWidget {
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.style(Style::default().fg(self.is_selected()))
|
||||
.title(self.display_coords().green()),
|
||||
.title(self.display_coords().green())
|
||||
.padding(Padding {
|
||||
left: 0,
|
||||
right: 0,
|
||||
top: if area.height <= 3 { 0 } else { area.height / 3 },
|
||||
bottom: 0,
|
||||
}),
|
||||
)
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user