generated from GarandPLG/rust-flake-template
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user