summaryrefslogtreecommitdiffstats
path: root/src/canvas/widgets/disk_table.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/canvas/widgets/disk_table.rs')
-rw-r--r--src/canvas/widgets/disk_table.rs56
1 files changed, 47 insertions, 9 deletions
diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs
index 0fee787a..14cb4f60 100644
--- a/src/canvas/widgets/disk_table.rs
+++ b/src/canvas/widgets/disk_table.rs
@@ -42,7 +42,6 @@ impl DiskTableWidget for Painter {
) {
let recalculate_column_widths = app_state.should_get_widget_bounds();
if let Some(disk_widget_state) = app_state.disk_state.widget_states.get_mut(&widget_id) {
- let disk_data: &mut [Vec<String>] = &mut app_state.canvas_data.disk_data;
let table_gap = if draw_loc.height < TABLE_GAP_HEIGHT_LIMIT {
0
} else {
@@ -65,7 +64,7 @@ impl DiskTableWidget for Painter {
.current_scroll_position
.saturating_sub(start_position),
));
- let sliced_vec = &disk_data[start_position..];
+ let sliced_vec = &app_state.canvas_data.disk_data[start_position..];
// Calculate widths
let hard_widths = [None, None, Some(4), Some(6), Some(6), Some(7), Some(7)];
@@ -154,7 +153,6 @@ impl DiskTableWidget for Painter {
Row::Data(truncated_data)
});
- // TODO: This seems to be bugged? The selected text style gets "stuck"? I think this gets fixed with tui 0.10?
let (border_style, highlight_style) = if is_on_widget {
(
self.colours.highlighted_border_style,
@@ -164,22 +162,62 @@ impl DiskTableWidget for Painter {
(self.colours.border_style, self.colours.text_style)
};
+ let title_base = if app_state.app_config_fields.show_table_scroll_position {
+ let title_string = format!(
+ " Disk ({} of {}) ",
+ disk_widget_state
+ .scroll_state
+ .current_scroll_position
+ .saturating_add(1),
+ app_state.canvas_data.disk_data.len()
+ );
+
+ if title_string.len() <= draw_loc.width as usize {
+ title_string
+ } else {
+ " Disk ".to_string()
+ }
+ } else {
+ " Disk ".to_string()
+ };
+
let title = if app_state.is_expanded {
- const TITLE_BASE: &str = " Disk ── Esc to go back ";
+ const ESCAPE_ENDING: &str = "── Esc to go back ";
+
+ let (chosen_title_base, expanded_title_base) = {
+ let temp_title_base = format!("{}{}", title_base, ESCAPE_ENDING);
+
+ if temp_title_base.len() > draw_loc.width as usize {
+ (
+ " Disk ".to_string(),
+ format!("{}{}", " Disk ".to_string(), ESCAPE_ENDING),
+ )
+ } else {
+ (title_base, temp_title_base)
+ }
+ };
+
Spans::from(vec![
- Span::styled(" Disk ", self.colours.widget_title_style),
+ Span::styled(chosen_title_base, self.colours.widget_title_style),
Span::styled(
format!(
"─{}─ Esc to go back ",
- "─".repeat(usize::from(draw_loc.width).saturating_sub(
- UnicodeSegmentation::graphemes(TITLE_BASE, true).count() + 2
- ))
+ "─".repeat(
+ usize::from(draw_loc.width).saturating_sub(
+ UnicodeSegmentation::graphemes(
+ expanded_title_base.as_str(),
+ true
+ )
+ .count()
+ + 2
+ )
+ )
),
border_style,
),
])
} else {
- Spans::from(Span::styled(" Disk ", self.colours.widget_title_style))
+ Spans::from(Span::styled(title_base, self.colours.widget_title_style))
};
let disk_block = if draw_border {