features ui debug is now working perfectly well, it debugs the rerender flags
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
// src/components/common/status_line.rs
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::app::state::AppState;
|
||||
use ratatui::{
|
||||
style::Style,
|
||||
layout::Rect,
|
||||
Frame,
|
||||
style::Style,
|
||||
text::{Line, Span},
|
||||
widgets::Paragraph,
|
||||
Frame,
|
||||
};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
use crate::config::colors::themes::Theme;
|
||||
use std::path::Path;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
pub fn render_status_line(
|
||||
f: &mut Frame,
|
||||
@@ -17,11 +18,24 @@ pub fn render_status_line(
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
current_fps: f64,
|
||||
app_state: &AppState,
|
||||
) {
|
||||
// --- START FIX ---
|
||||
// Ensure debug_text is always a &str, which implements UnicodeWidthStr.
|
||||
#[cfg(feature = "ui-debug")]
|
||||
let debug_text = app_state.debug_info.as_str();
|
||||
#[cfg(not(feature = "ui-debug"))]
|
||||
let debug_text = "";
|
||||
// --- END FIX ---
|
||||
|
||||
let debug_width = UnicodeWidthStr::width(debug_text);
|
||||
let debug_separator_width = if !debug_text.is_empty() { UnicodeWidthStr::width(" | ") } else { 0 };
|
||||
|
||||
let program_info = format!("multieko2 v{}", env!("CARGO_PKG_VERSION"));
|
||||
let mode_text = if is_edit_mode { "[EDIT]" } else { "[READ-ONLY]" };
|
||||
|
||||
let home_dir = dirs::home_dir().map(|p| p.to_string_lossy().into_owned()).unwrap_or_default();
|
||||
let home_dir =
|
||||
dirs::home_dir().map(|p| p.to_string_lossy().into_owned()).unwrap_or_default();
|
||||
let display_dir = if current_dir.starts_with(&home_dir) {
|
||||
current_dir.replacen(&home_dir, "~", 1)
|
||||
} else {
|
||||
@@ -37,23 +51,24 @@ pub fn render_status_line(
|
||||
let separator_width = UnicodeWidthStr::width(separator);
|
||||
|
||||
let fixed_width_with_fps = mode_width + separator_width + separator_width +
|
||||
program_info_width + separator_width + fps_width;
|
||||
let show_fps = fixed_width_with_fps <= available_width; // Use <= to show if it fits exactly
|
||||
program_info_width + separator_width + fps_width +
|
||||
debug_separator_width + debug_width;
|
||||
let show_fps = fixed_width_with_fps <= available_width;
|
||||
|
||||
let remaining_width_for_dir = available_width.saturating_sub(
|
||||
mode_width + separator_width + // after mode
|
||||
separator_width + program_info_width + // after program_info
|
||||
if show_fps { separator_width + fps_width } else { 0 } // after fps
|
||||
mode_width + separator_width +
|
||||
separator_width + program_info_width +
|
||||
(if show_fps { separator_width + fps_width } else { 0 }) +
|
||||
debug_separator_width + debug_width,
|
||||
);
|
||||
|
||||
// Original directory display logic
|
||||
let dir_display_text_str = if UnicodeWidthStr::width(display_dir.as_str()) <= remaining_width_for_dir {
|
||||
display_dir // display_dir is already a String here
|
||||
display_dir
|
||||
} else {
|
||||
let dir_name = Path::new(current_dir) // Use original current_dir for path logic
|
||||
let dir_name = Path::new(current_dir)
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or(current_dir); // Fallback to current_dir if no filename
|
||||
.unwrap_or(current_dir);
|
||||
if UnicodeWidthStr::width(dir_name) <= remaining_width_for_dir {
|
||||
dir_name.to_string()
|
||||
} else {
|
||||
@@ -61,10 +76,10 @@ pub fn render_status_line(
|
||||
}
|
||||
};
|
||||
|
||||
// Calculate current content width based on what will be displayed
|
||||
let mut current_content_width = mode_width + separator_width +
|
||||
UnicodeWidthStr::width(dir_display_text_str.as_str()) +
|
||||
separator_width + program_info_width;
|
||||
separator_width + program_info_width +
|
||||
debug_separator_width + debug_width;
|
||||
if show_fps {
|
||||
current_content_width += separator_width + fps_width;
|
||||
}
|
||||
@@ -82,12 +97,17 @@ pub fn render_status_line(
|
||||
line_spans.push(Span::styled(fps_text.as_str(), Style::default().fg(theme.secondary)));
|
||||
}
|
||||
|
||||
// Calculate padding
|
||||
#[cfg(feature = "ui-debug")]
|
||||
{
|
||||
line_spans.push(Span::styled(separator, Style::default().fg(theme.border)));
|
||||
line_spans.push(Span::styled(debug_text, Style::default().fg(theme.accent)));
|
||||
}
|
||||
|
||||
let padding_needed = available_width.saturating_sub(current_content_width);
|
||||
if padding_needed > 0 {
|
||||
line_spans.push(Span::styled(
|
||||
" ".repeat(padding_needed),
|
||||
Style::default().bg(theme.bg), // Ensure padding uses background color
|
||||
Style::default().bg(theme.bg),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user