working blocked constant redraws

This commit is contained in:
filipriec
2025-04-18 21:43:54 +02:00
parent a0467d17a8
commit f357d6f0ee

View File

@@ -63,6 +63,7 @@ pub async fn run_ui() -> Result<()> {
// --- FPS Calculation State --- // --- FPS Calculation State ---
let mut last_frame_time = Instant::now(); let mut last_frame_time = Instant::now();
let mut current_fps = 0.0; let mut current_fps = 0.0;
let mut needs_redraw = true;
loop { loop {
// --- Synchronize UI View from Active Buffer --- // --- Synchronize UI View from Active Buffer ---
@@ -96,29 +97,32 @@ pub async fn run_ui() -> Result<()> {
// Draw the current state *first*. This ensures the loading dialog // Draw the current state *first*. This ensures the loading dialog
// set in the *previous* iteration gets rendered before the pending // set in the *previous* iteration gets rendered before the pending
// action check below. // action check below.
terminal.draw(|f| { if needs_redraw {
render_ui( terminal.draw(|f| {
f, render_ui(
&mut form_state, f,
&mut auth_state, &mut form_state,
&login_state, &mut auth_state,
&register_state, &login_state,
&intro_state, &register_state,
&mut admin_state, &intro_state,
&buffer_state, &mut admin_state,
&theme, &buffer_state,
event_handler.is_edit_mode, // Use event_handler's state &theme,
&event_handler.highlight_state, event_handler.is_edit_mode, // Use event_handler's state
app_state.total_count, &event_handler.highlight_state,
app_state.current_position, app_state.total_count,
&app_state.current_dir, app_state.current_position,
&event_handler.command_input, &app_state.current_dir,
event_handler.command_mode, &event_handler.command_input,
&event_handler.command_message, event_handler.command_mode,
current_fps, &event_handler.command_message,
&app_state, current_fps,
); &app_state,
}).context("Terminal draw call failed")?; );
}).context("Terminal draw call failed")?;
needs_redraw = false;
}
// --- Cursor Visibility Logic --- // --- Cursor Visibility Logic ---
// (Keep existing cursor logic here - depends on state drawn above) // (Keep existing cursor logic here - depends on state drawn above)
@@ -167,6 +171,7 @@ pub async fn run_ui() -> Result<()> {
&mut current_position, &mut current_position,
) )
.await; .await;
needs_redraw = true;
} }
// Update position based on handler's modification // Update position based on handler's modification
@@ -222,6 +227,7 @@ pub async fn run_ui() -> Result<()> {
login_state.password.clear(); login_state.password.clear();
login_state.set_has_unsaved_changes(false); login_state.set_has_unsaved_changes(false);
login_state.current_cursor_pos = 0; login_state.current_cursor_pos = 0;
needs_redraw = true;
} }
Err(mpsc::error::TryRecvError::Empty) => { /* No message waiting */ } Err(mpsc::error::TryRecvError::Empty) => { /* No message waiting */ }
Err(mpsc::error::TryRecvError::Disconnected) => { Err(mpsc::error::TryRecvError::Disconnected) => {
@@ -275,6 +281,7 @@ pub async fn run_ui() -> Result<()> {
// --- Position Change Handling (after outcome processing and pending actions) --- // --- Position Change Handling (after outcome processing and pending actions) ---
let position_changed = app_state.current_position != position_before_event; let position_changed = app_state.current_position != position_before_event;
let current_total_count = app_state.total_count; let current_total_count = app_state.total_count;
let mut position_logic_needs_redraw = false;
if app_state.ui.show_form { if app_state.ui.show_form {
if position_changed && !event_handler.is_edit_mode { if position_changed && !event_handler.is_edit_mode {
let current_input = form_state.get_current_input(); let current_input = form_state.get_current_input();
@@ -285,6 +292,7 @@ pub async fn run_ui() -> Result<()> {
}; };
form_state.current_cursor_pos = form_state.current_cursor_pos =
event_handler.ideal_cursor_column.min(max_cursor_pos); event_handler.ideal_cursor_column.min(max_cursor_pos);
position_logic_needs_redraw = true;
// Ensure position never exceeds total_count + 1 // Ensure position never exceeds total_count + 1
if app_state.current_position > current_total_count + 1 { if app_state.current_position > current_total_count + 1 {
@@ -353,6 +361,7 @@ pub async fn run_ui() -> Result<()> {
0 0
}; };
register_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos); register_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
position_logic_needs_redraw = true;
} }
} else if app_state.ui.show_login { } else if app_state.ui.show_login {
if !event_handler.is_edit_mode { if !event_handler.is_edit_mode {
@@ -363,8 +372,12 @@ pub async fn run_ui() -> Result<()> {
0 0
}; };
login_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos); login_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
position_logic_needs_redraw = true;
} }
} }
if position_logic_needs_redraw {
needs_redraw = true;
}
// --- End Position Change Handling --- // --- End Position Change Handling ---
// Check exit condition *after* all processing for the iteration // Check exit condition *after* all processing for the iteration