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:
1 parent
363baa1c1a
commit
07e941eba1
4 files changed
+50
-20
No files matched your search
@@ -9,35 +9,47 @@ pub fn skirmish_keybindings(app: &mut App, key_event: &KeyEvent) {
|
||||
if let Some(action) = event_to_action(&key_event) {
|
||||
common_keybindings(app, action);
|
||||
match action {
|
||||
Action::Up => {
|
||||
app.states.skirmish.focused_cell.move_up();
|
||||
|
||||
// if app.states.skirmish.horizontal_offset.get_value() {
|
||||
|
||||
// }
|
||||
}
|
||||
Action::Up => app.states.skirmish.focused_cell.move_up(),
|
||||
Action::Down => app.states.skirmish.focused_cell.move_down(),
|
||||
Action::Left => app.states.skirmish.focused_cell.move_left(),
|
||||
Action::Right => app.states.skirmish.focused_cell.move_right(),
|
||||
Action::ScrollUp => app.states.skirmish.vertical_offset.prev(),
|
||||
Action::ScrollDown => app.states.skirmish.vertical_offset.next(),
|
||||
Action::ScrollLeft => app.states.skirmish.horizontal_offset.prev(),
|
||||
Action::ScrollRight => app.states.skirmish.horizontal_offset.next(),
|
||||
Action::ScrollUp => {
|
||||
app.states.skirmish.vertical_offset.prev();
|
||||
app.states.skirmish.focused_cell.move_up();
|
||||
}
|
||||
Action::ScrollDown => {
|
||||
app.states.skirmish.vertical_offset.next();
|
||||
app.states.skirmish.focused_cell.move_down();
|
||||
}
|
||||
Action::ScrollLeft => {
|
||||
app.states.skirmish.horizontal_offset.prev();
|
||||
app.states.skirmish.focused_cell.move_left();
|
||||
}
|
||||
Action::ScrollRight => {
|
||||
app.states.skirmish.horizontal_offset.next();
|
||||
app.states.skirmish.focused_cell.move_right();
|
||||
}
|
||||
Action::ZoomIn => match app.states.skirmish.zoom_level {
|
||||
ZoomLevel::ZoomedIn => {}
|
||||
ZoomLevel::Default => {
|
||||
app.states.skirmish.zoom_level = ZoomLevel::ZoomedIn;
|
||||
app.states.skirmish.vertical_offset.next();
|
||||
}
|
||||
ZoomLevel::ZoomedOut => {
|
||||
app.states.skirmish.zoom_level = ZoomLevel::Default;
|
||||
app.states.skirmish.vertical_offset.next();
|
||||
app.states.skirmish.vertical_offset.next();
|
||||
}
|
||||
},
|
||||
Action::ZoomOut => match app.states.skirmish.zoom_level {
|
||||
ZoomLevel::ZoomedIn => {
|
||||
app.states.skirmish.zoom_level = ZoomLevel::Default;
|
||||
app.states.skirmish.vertical_offset.prev();
|
||||
}
|
||||
ZoomLevel::Default => {
|
||||
app.states.skirmish.zoom_level = ZoomLevel::ZoomedOut;
|
||||
app.states.skirmish.vertical_offset.prev();
|
||||
app.states.skirmish.vertical_offset.prev();
|
||||
}
|
||||
ZoomLevel::ZoomedOut => {}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user