fixing this
This commit is contained in:
@@ -77,7 +77,7 @@ pub fn render_login(
|
||||
// Login Button
|
||||
let login_button_index = 0;
|
||||
let login_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == login_button_index
|
||||
app_state.focused_button_index== login_button_index
|
||||
} else {
|
||||
false
|
||||
};
|
||||
@@ -104,7 +104,7 @@ pub fn render_login(
|
||||
// Return Button
|
||||
let return_button_index = 1; // Assuming Return is the second general element
|
||||
let return_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == return_button_index
|
||||
app_state.focused_button_index== return_button_index
|
||||
} else {
|
||||
false // Not active if focus is in canvas or other modes
|
||||
};
|
||||
|
||||
@@ -92,7 +92,7 @@ pub fn render_register(
|
||||
// Register Button
|
||||
let register_button_index = 0;
|
||||
let register_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == register_button_index
|
||||
app_state.focused_button_index== register_button_index
|
||||
} else {
|
||||
false
|
||||
};
|
||||
@@ -119,7 +119,7 @@ pub fn render_register(
|
||||
// Return Button (logic remains similar)
|
||||
let return_button_index = 1;
|
||||
let return_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == return_button_index
|
||||
app_state.focused_button_index== return_button_index
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ pub async fn execute_action<S: CanvasState>(
|
||||
if current_field == last_field_index {
|
||||
// Already on the last field, move focus outside
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
app_state.general.selected_item = 0; // Focus first general item (e.g., Login button)
|
||||
app_state.focused_button_index= 0;
|
||||
key_sequence_tracker.reset();
|
||||
Ok("Focus moved below canvas".to_string())
|
||||
} else {
|
||||
|
||||
@@ -63,15 +63,14 @@ pub async fn handle_navigation_event(
|
||||
let (context, index) = if app_state.ui.show_intro {
|
||||
(UiContext::Intro, app_state.ui.intro_state.selected_option)
|
||||
} else if app_state.ui.show_login && app_state.ui.focus_outside_canvas {
|
||||
(UiContext::Login, app_state.general.selected_item)
|
||||
(UiContext::Login, app_state.focused_button_index)
|
||||
} else if app_state.ui.show_register && app_state.ui.focus_outside_canvas {
|
||||
(UiContext::Register, app_state.general.selected_item)
|
||||
(UiContext::Register, app_state.focused_button_index)
|
||||
} else if app_state.ui.show_admin {
|
||||
(UiContext::Admin, app_state.general.selected_item)
|
||||
(UiContext::Admin, admin_state.get_selected_index().unwrap_or(0))
|
||||
} else if app_state.ui.dialog.dialog_show {
|
||||
(UiContext::Dialog, app_state.ui.dialog.dialog_active_button_index)
|
||||
} else {
|
||||
// Handle cases where select is pressed but no button context applies
|
||||
return Ok(EventOutcome::Ok("Select (No Action)".to_string()));
|
||||
};
|
||||
return Ok(EventOutcome::ButtonSelected { context, index });
|
||||
@@ -84,7 +83,7 @@ pub async fn handle_navigation_event(
|
||||
|
||||
pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState, admin_state: &mut AdminState) {
|
||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
|
||||
if app_state.general.selected_item == 0 {
|
||||
if app_state.button_focus_index == 0 {
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
if app_state.ui.show_login {
|
||||
let last_field_index = login_state.fields().len().saturating_sub(1);
|
||||
@@ -94,7 +93,7 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_
|
||||
register_state.set_current_field(last_field_index);
|
||||
}
|
||||
} else {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
||||
app_state.button_focus_index = app_state.general.selected_item.saturating_sub(1);
|
||||
}
|
||||
} else if app_state.ui.show_intro {
|
||||
app_state.ui.intro_state.previous_option();
|
||||
@@ -106,8 +105,8 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_
|
||||
pub fn move_down(app_state: &mut AppState, admin_state: &mut AdminState) {
|
||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register {
|
||||
let num_general_elements = 2;
|
||||
if app_state.general.selected_item < num_general_elements - 1 {
|
||||
app_state.general.selected_item += 1;
|
||||
if app_state.button_focus_index < num_general_elements - 1 {
|
||||
app_state.button_focus_index += 1;
|
||||
}
|
||||
} else if app_state.ui.show_intro {
|
||||
app_state.ui.intro_state.next_option();
|
||||
@@ -132,7 +131,7 @@ pub fn previous_option(app_state: &mut AppState) {
|
||||
} else {
|
||||
let option_count = app_state.profile_tree.profiles.len();
|
||||
app_state.general.current_option = if app_state.general.current_option == 0 {
|
||||
option_count.saturating_sub(1) // Wrap to last option
|
||||
option_count.saturating_sub(1)
|
||||
} else {
|
||||
app_state.general.current_option - 1
|
||||
};
|
||||
|
||||
@@ -143,7 +143,7 @@ impl EventHandler {
|
||||
};
|
||||
}
|
||||
UiContext::Admin => {
|
||||
admin::handle_admin_selection(app_state);
|
||||
admin::handle_admin_selection(app_state, admin_state);
|
||||
|
||||
message = format!("Admin Option {} selected", index);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ pub struct AppState {
|
||||
pub profile_tree: ProfileTreeResponse,
|
||||
pub selected_profile: Option<String>,
|
||||
pub current_mode: AppMode,
|
||||
pub focused_button_index: usize,
|
||||
|
||||
// UI preferences
|
||||
pub ui: UiState,
|
||||
@@ -52,6 +53,7 @@ impl AppState {
|
||||
profile_tree: ProfileTreeResponse::default(),
|
||||
selected_profile: None,
|
||||
current_mode: AppMode::General,
|
||||
focused_button_index: 0,
|
||||
ui: UiState::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
|
||||
pub fn handle_admin_selection(app_state: &mut AppState) {
|
||||
pub fn handle_admin_selection(app_state: &mut AppState, admin_state: &AdminState) {
|
||||
let profiles = &app_state.profile_tree.profiles;
|
||||
if !profiles.is_empty() && app_state.general.selected_item < profiles.len() {
|
||||
app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone());
|
||||
|
||||
@@ -103,7 +103,7 @@ pub async fn back_to_main(
|
||||
|
||||
// Reset focus state
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
app_state.general.selected_item = 0;
|
||||
app_state.focused_button_index= 0;
|
||||
|
||||
"Returned to main menu".to_string()
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ pub async fn back_to_main(
|
||||
|
||||
// Reset focus state
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
app_state.general.selected_item = 0; // Reset intro selection
|
||||
app_state.button_focus_index = 0;
|
||||
|
||||
"Returned to main menu".to_string()
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn handle_intro_selection(app_state: &mut AppState, index: usize) { // Add i
|
||||
app_state.ui.show_intro = false;
|
||||
app_state.ui.show_register = true;
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
app_state.general.selected_item = 0;
|
||||
app_state.button_focus_index = 0;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user