diff --git a/src/tui/widgets/account.rs b/src/tui/widgets/account.rs index 9c63e11..b0e9266 100644 --- a/src/tui/widgets/account.rs +++ b/src/tui/widgets/account.rs @@ -226,10 +226,13 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A .border_style(Style::default().fg(color)); if focused == FocusedArea::Account { - block = block.title_bottom( - super::popups::keybind_line(&[("⏎", " select"), ("a", " add"), ("d", " del")]) - .alignment(ratatui::layout::Alignment::Right), + let lines = super::popups::keybind_lines_wrapped( + &[("⏎", " select"), ("a", " add"), ("d", " del")], + area.width.saturating_sub(2), ); + for line in lines { + block = block.title_bottom(line); + } } let inner = block.inner(area); diff --git a/src/tui/widgets/content.rs b/src/tui/widgets/content.rs index e7a15fc..82a7a58 100644 --- a/src/tui/widgets/content.rs +++ b/src/tui/widgets/content.rs @@ -138,49 +138,65 @@ pub fn render( block = block.title_top(sl); } - if is_focused { - let kb: &[(&str, &str)] = match tab { + let kb: Option<&[(&str, &str)]> = if is_focused { + Some(match tab { ContentTab::Mods | ContentTab::ResourcePacks | ContentTab::Shaders => &[ - ("j/k", " nav"), + ("j/k", " navigate"), ("⏎", " toggle"), - ("S+⏎", " dir"), + ("Shift+⏎", " open dir"), ("h/l", " tabs"), ("/", " search"), ], ContentTab::Worlds => &[ - ("j/k", " nav"), - ("S+⏎", " dir"), + ("j/k", " navigate"), + ("Shift+⏎", " open dir"), ("h/l", " tabs"), ("/", " search"), ], ContentTab::Screenshots => &[ - ("S+HJKL", " grid"), + ("Shift+HJKL", " grid"), ("⏎", " open"), - ("S+⏎", " dir"), + ("Shift+⏎", " open dir"), ("h/l", " tabs"), ("/", " search"), ], ContentTab::Logs => { if logs_state.viewer_focused { &[ - ("S+JK", " scroll"), - ("g/G", " top/bot"), + ("j/k", " scroll"), + ("g/G", " top/bottom"), ("Esc", " back"), ("/", " search"), ] } else { &[ - ("S+JK", " nav"), + ("j/k", " navigate"), ("⏎", " view"), ("h/l", " tabs"), ("/", " search"), ] } } - }; - block = block.title_bottom( - super::popups::keybind_line(kb).alignment(ratatui::layout::Alignment::Right), - ); + }) + } else if focused == FocusedArea::Profiles { + Some(&[ + ("l", " launch"), + ("⏎", " content"), + ("Shift+⏎", " open dir"), + ("Esc", " kill"), + ("a", " add"), + ("d", " delete"), + ("/", " search"), + ]) + } else { + None + }; + + if let Some(kb) = kb { + let lines = super::popups::keybind_lines_wrapped(kb, area.width.saturating_sub(2)); + for line in lines { + block = block.title_bottom(line); + } } let content_area = block.inner(area); diff --git a/src/tui/widgets/details.rs b/src/tui/widgets/details.rs index 97655d4..7a8b4de 100644 --- a/src/tui/widgets/details.rs +++ b/src/tui/widgets/details.rs @@ -1,5 +1,5 @@ use ratatui::{ - layout::{Alignment, Rect}, + layout::Rect, style::Style, widgets::{Block, BorderType, Borders}, Frame, @@ -17,21 +17,25 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) { THEME.colors.border_unfocused }; - let block = Block::default() + let mut block = Block::default() .title(styled_title("Details", true)) - .title_bottom( - super::popups::keybind_line(&[ - ("P", " profiles"), - ("C", " content"), - ("A", " account"), - ("S", " logs"), - ("q", " quit"), - ]) - .alignment(Alignment::Right), - ) .borders(Borders::ALL) .border_type(BorderType::Rounded) .border_style(Style::default().fg(color)); + let lines = super::popups::keybind_lines_wrapped( + &[ + ("P", " profiles"), + ("C", " content"), + ("A", " account"), + ("S", " logs"), + ("q", " quit"), + ], + area.width.saturating_sub(2), + ); + for line in lines { + block = block.title_bottom(line); + } + frame.render_widget(block, area); } diff --git a/src/tui/widgets/popups/mod.rs b/src/tui/widgets/popups/mod.rs index 30e08b8..899e162 100644 --- a/src/tui/widgets/popups/mod.rs +++ b/src/tui/widgets/popups/mod.rs @@ -70,3 +70,49 @@ pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> { } Line::from(spans) } + +pub fn keybind_lines_wrapped( + binds: &[(&str, &str)], + max_width: u16, +) -> Vec> { + use ratatui::{style::{Modifier, Style}, text::{Line, Span}}; + use crate::tui::theme::THEME; + + let key_style = Style::default() + .fg(THEME.colors.border_focused) + .add_modifier(Modifier::BOLD); + let dim_style = Style::default().fg(THEME.colors.border_unfocused); + + let mut rows: Vec> = Vec::new(); + let mut current_spans: Vec> = Vec::new(); + let mut current_width: usize = 0; + + for (i, (key, label)) in binds.iter().enumerate() { + let sep_w = if i > 0 && !current_spans.is_empty() { 2 } else { 0 }; + let item_w = key.len() + 2 + label.len(); + let needed = sep_w + item_w; + + if !current_spans.is_empty() && current_width + needed > max_width as usize { + rows.push(Line::from(current_spans).right_aligned()); + current_spans = Vec::new(); + current_width = 0; + } + + if !current_spans.is_empty() { + current_spans.push(Span::styled(" ", dim_style)); + current_width += 2; + } + + current_spans.push(Span::styled(format!("[{}]", key), key_style)); + if !label.is_empty() { + current_spans.push(Span::styled(label.to_string(), dim_style)); + } + current_width += item_w; + } + + if !current_spans.is_empty() { + rows.push(Line::from(current_spans).right_aligned()); + } + + rows +} diff --git a/src/tui/widgets/profiles.rs b/src/tui/widgets/profiles.rs index 3b8ade9..c69f0d5 100644 --- a/src/tui/widgets/profiles.rs +++ b/src/tui/widgets/profiles.rs @@ -207,20 +207,6 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S block = block.title_top(search_line); } - if focused == FocusedArea::Profiles { - block = block.title_bottom( - super::popups::keybind_line(&[ - ("l", " launch"), - ("⏎", " content"), - ("a", " add"), - ("d", " del"), - ("/", " search"), - ("Esc", " kill"), - ]) - .alignment(ratatui::layout::Alignment::Right), - ); - } - let scrollbar_area = Rect { x: area.x + area.width.saturating_sub(1), y: area.y + 1, diff --git a/src/tui/widgets/status.rs b/src/tui/widgets/status.rs index 39f24b0..c31fa2a 100644 --- a/src/tui/widgets/status.rs +++ b/src/tui/widgets/status.rs @@ -25,19 +25,12 @@ pub fn render( THEME.colors.border_unfocused }; - let mut block = Block::default() + let block = Block::default() .title(styled_title("Status", true)) .borders(Borders::ALL) .border_type(BorderType::Rounded) .border_style(Style::default().fg(border_color)); - if focused == FocusedArea::Status { - block = block.title_bottom( - super::popups::keybind_line(&[("S", " expand")]) - .alignment(ratatui::layout::Alignment::Right), - ); - } - let state = match PROGRESS.lock() { Ok(s) => s.clone(), Err(_) => {