general mode
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// src/modes/general/navigation.rs
|
||||
use crate::state::state::AppState;
|
||||
use crate::ui::handlers::form::FormState;
|
||||
|
||||
pub fn move_up(app_state: &mut AppState) {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
||||
}
|
||||
|
||||
pub fn move_down(app_state: &mut AppState, item_count: usize) {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_add(1);
|
||||
if item_count > 0 {
|
||||
app_state.general.selected_item = app_state.general.selected_item.min(item_count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next_option(app_state: &mut AppState, option_count: usize) {
|
||||
app_state.general.current_option = app_state.general.current_option.saturating_add(1);
|
||||
if option_count > 0 {
|
||||
app_state.general.current_option = app_state.general.current_option.min(option_count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn previous_option(app_state: &mut AppState) {
|
||||
app_state.general.current_option = app_state.general.current_option.saturating_sub(1);
|
||||
}
|
||||
|
||||
pub fn select(app_state: &mut AppState) {
|
||||
if app_state.ui.show_intro {
|
||||
app_state.ui.show_intro = false;
|
||||
} else if app_state.ui.show_admin {
|
||||
app_state.ui.show_admin = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle_sidebar(app_state: &mut AppState) {
|
||||
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
|
||||
}
|
||||
|
||||
pub fn next_field(form_state: &mut FormState) {
|
||||
if !form_state.fields.is_empty() {
|
||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prev_field(form_state: &mut FormState) {
|
||||
if !form_state.fields.is_empty() {
|
||||
form_state.current_field = if form_state.current_field == 0 {
|
||||
form_state.fields.len() - 1
|
||||
} else {
|
||||
form_state.current_field - 1
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_enter_command_mode(event_handler: &mut crate::modes::handlers::event::EventHandler) {
|
||||
event_handler.command_mode = true;
|
||||
event_handler.command_input.clear();
|
||||
event_handler.command_message.clear();
|
||||
}
|
||||
|
||||
// Helper function for bounds checking in lists
|
||||
pub fn clamp_index(selected: usize, item_count: usize) -> usize {
|
||||
if item_count == 0 {
|
||||
0
|
||||
} else {
|
||||
selected.min(item_count - 1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user