generated from GarandPLG/rust-flake-template
Add text input handling to settings popup
Introduce a `selected_setting_new_value` field in `SettingsState` and initialize it. Add `Backspace` and `WildCard(char)` actions with an `Input` group, and corresponding keybindings. Update `event_to_action` to map wildcard characters to `Action::WildCard`. Handle backspace and character input in `settings_keybindings` to edit the new field. Display the edited value in the settings popup and include the new actions in the UI.
This commit is contained in:
@@ -7,6 +7,8 @@ use ratatui::crossterm::event::KeyEvent;
|
||||
pub fn settings_keybindings(app: &mut App, key_event: &KeyEvent) {
|
||||
if let Some(action) = event_to_action(&key_event) {
|
||||
match action {
|
||||
// Action::Up,
|
||||
// Action::Down,
|
||||
Action::Quit => app.exit = true,
|
||||
Action::Quit2 => app.exit = true,
|
||||
Action::Esc => app.view = View::MainMenu,
|
||||
@@ -14,6 +16,22 @@ pub fn settings_keybindings(app: &mut App, key_event: &KeyEvent) {
|
||||
app.game_states.settings_state.show_popup =
|
||||
!app.game_states.settings_state.show_popup
|
||||
}
|
||||
Action::Backspace => {
|
||||
if app.game_states.settings_state.show_popup {
|
||||
app.game_states
|
||||
.settings_state
|
||||
.selected_setting_new_value
|
||||
.pop();
|
||||
}
|
||||
}
|
||||
Action::WildCard(c) => {
|
||||
if app.game_states.settings_state.show_popup {
|
||||
app.game_states
|
||||
.settings_state
|
||||
.selected_setting_new_value
|
||||
.push(c);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user