Fix keyboard navigation and panel scrolling issues

- Remove Network panel from navigation cycle
- Fix system panel scrolling to work in both directions
- Add complete scroll support to Services and Backup panels
- Update panel cycling to System → Services → Backup only
- Enhance scroll indicators with proper bounds checking
- Clean up unused Network panel code and references

Resolves issues with non-functional up/down scrolling and
mystery network panel appearing during navigation.
This commit is contained in:
2025-10-23 21:01:11 +02:00
parent 1b46aa2f13
commit 6b18cdf562
4 changed files with 106 additions and 48 deletions

View File

@@ -325,6 +325,13 @@ impl Widget for BackupWidget {
}
fn render(&mut self, frame: &mut Frame, area: Rect) {
self.render_with_scroll(frame, area, 0);
}
}
impl BackupWidget {
/// Render with scroll offset support
pub fn render_with_scroll(&mut self, frame: &mut Frame, area: Rect, scroll_offset: usize) {
let mut lines = Vec::new();
// Latest backup section
@@ -422,8 +429,31 @@ impl Widget for BackupWidget {
]));
}
let paragraph = Paragraph::new(ratatui::text::Text::from(lines));
frame.render_widget(paragraph, area);
// Apply scroll offset
let total_lines = lines.len();
let available_height = area.height as usize;
// Calculate scroll boundaries
let max_scroll = if total_lines > available_height {
total_lines - available_height
} else {
total_lines.saturating_sub(1)
};
let effective_scroll = scroll_offset.min(max_scroll);
// Apply scrolling if needed
if scroll_offset > 0 || total_lines > available_height {
let visible_lines: Vec<_> = lines
.into_iter()
.skip(effective_scroll)
.take(available_height)
.collect();
let paragraph = Paragraph::new(ratatui::text::Text::from(visible_lines));
frame.render_widget(paragraph, area);
} else {
let paragraph = Paragraph::new(ratatui::text::Text::from(lines));
frame.render_widget(paragraph, area);
}
}
}

View File

@@ -313,8 +313,13 @@ impl Widget for ServicesWidget {
}
impl ServicesWidget {
/// Render with optional focus indicator
/// Render with optional focus indicator and scroll support
pub fn render_with_focus(&mut self, frame: &mut Frame, area: Rect, is_focused: bool) {
self.render_with_focus_and_scroll(frame, area, is_focused, 0);
}
/// Render with focus indicator and scroll offset
pub fn render_with_focus_and_scroll(&mut self, frame: &mut Frame, area: Rect, is_focused: bool, scroll_offset: usize) {
let services_block = if is_focused {
Components::focused_widget_block("services")
} else {
@@ -374,9 +379,26 @@ impl ServicesWidget {
}
}
// Render all lines within available space
// Apply scroll offset and render visible lines
let available_lines = content_chunks[1].height as usize;
let lines_to_show = available_lines.min(display_lines.len());
let total_lines = display_lines.len();
// Calculate scroll boundaries
let max_scroll = if total_lines > available_lines {
total_lines - available_lines
} else {
total_lines.saturating_sub(1)
};
let effective_scroll = scroll_offset.min(max_scroll);
// Get visible lines after scrolling
let visible_lines: Vec<_> = display_lines
.iter()
.skip(effective_scroll)
.take(available_lines)
.collect();
let lines_to_show = visible_lines.len();
if lines_to_show > 0 {
let service_chunks = Layout::default()
@@ -384,8 +406,7 @@ impl ServicesWidget {
.constraints(vec![Constraint::Length(1); lines_to_show])
.split(content_chunks[1]);
for (i, (line_text, line_status, is_sub, sub_info)) in
display_lines.iter().take(lines_to_show).enumerate()
for (i, (line_text, line_status, is_sub, sub_info)) in visible_lines.iter().enumerate()
{
let spans = if *is_sub && sub_info.is_some() {
// Use custom sub-service span creation
@@ -400,20 +421,31 @@ impl ServicesWidget {
}
}
// Show indicator if there are more services than we can display
if display_lines.len() > available_lines {
let more_count = display_lines.len() - available_lines;
if available_lines > 0 {
let last_line_area = Rect {
x: content_chunks[1].x,
y: content_chunks[1].y + (available_lines - 1) as u16,
width: content_chunks[1].width,
height: 1,
// Show scroll indicator if there are more services than we can display
if total_lines > available_lines {
let hidden_above = effective_scroll;
let hidden_below = total_lines.saturating_sub(effective_scroll + available_lines);
if hidden_above > 0 || hidden_below > 0 {
let scroll_text = if hidden_above > 0 && hidden_below > 0 {
format!("... {} above, {} below", hidden_above, hidden_below)
} else if hidden_above > 0 {
format!("... {} more above", hidden_above)
} else {
format!("... {} more below", hidden_below)
};
let more_text = format!("... and {} more services", more_count);
let more_para = Paragraph::new(more_text).style(Typography::muted());
frame.render_widget(more_para, last_line_area);
if available_lines > 0 && lines_to_show > 0 {
let last_line_area = Rect {
x: content_chunks[1].x,
y: content_chunks[1].y + (lines_to_show - 1) as u16,
width: content_chunks[1].width,
height: 1,
};
let scroll_para = Paragraph::new(scroll_text).style(Typography::muted());
frame.render_widget(scroll_para, last_line_area);
}
}
}
}

View File

@@ -520,9 +520,13 @@ impl SystemWidget {
let total_lines = lines.len();
let available_height = area.height as usize;
if total_lines > available_height {
// Content is larger than area, apply scrolling
let max_scroll = total_lines.saturating_sub(available_height);
// Always apply scrolling if scroll_offset > 0, even if content fits
if scroll_offset > 0 || total_lines > available_height {
let max_scroll = if total_lines > available_height {
total_lines - available_height
} else {
total_lines.saturating_sub(1)
};
let effective_scroll = scroll_offset.min(max_scroll);
// Take only the visible portion after scrolling
@@ -535,7 +539,7 @@ impl SystemWidget {
let paragraph = Paragraph::new(Text::from(visible_lines));
frame.render_widget(paragraph, area);
} else {
// All content fits, render normally
// All content fits and no scroll offset, render normally
let paragraph = Paragraph::new(Text::from(lines));
frame.render_widget(paragraph, area);
}