Add zoom support and dynamic keybinding layout

Introduce ZoomIn/ZoomOut actions and a Zoom group with corresponding
keybindings.
Add a CLI option to set the initial zoom level and a ZoomLevel enum.
Expose a utility to compute the largest keybinding group size for layout
sizing.
Refactor board widget to adjust cell dimensions based on zoom level and
simplify offset calculations.
Update views to use the new layout sizing helper and integrate zoom
handling in skirmish logic.
This commit is contained in:
2026-03-29 14:12:03 +02:00
parent edf491457e
commit 1d1dc0f2f7
11 changed files with 145 additions and 49 deletions
+34
View File
@@ -1,5 +1,6 @@
use clap::ValueEnum;
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Action {
@@ -17,6 +18,8 @@ pub enum Action {
Enter,
Esc,
Backspace,
ZoomIn,
ZoomOut,
WildCard(char),
}
@@ -27,6 +30,7 @@ pub enum Group {
Scroll,
Select,
Input,
Zoom,
Quit,
}
@@ -168,6 +172,24 @@ pub static KEYBINDINGS: &[KeyBinding] = &[
symbol: "Backspace",
description: "Delete character",
},
KeyBinding {
action: Action::ZoomIn,
code: KeyCode::Char(','),
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
group: Group::Zoom,
symbol: ",",
description: "Zoom in",
},
KeyBinding {
action: Action::ZoomOut,
code: KeyCode::Char('.'),
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
group: Group::Zoom,
symbol: ".",
description: "Zoom out",
},
KeyBinding {
action: Action::WildCard('_'),
code: KeyCode::Char('_'),
@@ -202,3 +224,15 @@ pub fn event_to_action(event: &KeyEvent) -> Option<Action> {
None
}
pub fn count_largest_group(actions: &Vec<Action>) -> u16 {
let mut group_counts: HashMap<Group, u16> = HashMap::new();
for action in actions {
if let Some(binding) = binding_for(*action) {
*group_counts.entry(binding.group).or_insert(0) += 1;
}
}
group_counts.values().copied().max().map_or(0, |v| v)
}