From 45d9b85abfca081d9ae859121bfa7167c824cf87 Mon Sep 17 00:00:00 2001 From: objz Date: Fri, 4 Sep 2026 15:22:52 +0200 Subject: [PATCH] fix: normalize settings popup styling --- src/tui/input.rs | 3 +- src/tui/tests/flows.rs | 4 +- src/tui/widgets/popups/confirm.rs | 13 ++---- src/tui/widgets/popups/global_settings.rs | 17 ++------ src/tui/widgets/popups/instance_settings.rs | 45 +++++++-------------- src/tui/widgets/popups/settings_controls.rs | 12 +++--- 6 files changed, 32 insertions(+), 62 deletions(-) diff --git a/src/tui/input.rs b/src/tui/input.rs index 2d3cda5..18eeca5 100644 --- a/src/tui/input.rs +++ b/src/tui/input.rs @@ -734,10 +734,9 @@ impl App { widgets::popups::instance_settings::Action::Save(updated, desktop) => { self.apply_instance_settings(*updated, desktop, false); } - widgets::popups::instance_settings::Action::ConfirmRuntime { name, to } => { + widgets::popups::instance_settings::Action::ConfirmRuntime { name } => { confirm_popup::set_pending(confirm_popup::ConfirmTarget::InstanceRuntime { name, - to, }); self.focused = FocusedArea::ConfirmDelete; } diff --git a/src/tui/tests/flows.rs b/src/tui/tests/flows.rs index c7b0b50..d6066f4 100644 --- a/src/tui/tests/flows.rs +++ b/src/tui/tests/flows.rs @@ -657,7 +657,7 @@ fn runtime_settings_use_the_shared_confirmation_popup() { )); ui.draw(); assert!(ui.screen().contains("Change runtime")); - assert!(ui.screen().contains("Target:")); + assert!(!ui.screen().contains("Target:")); assert!( ui.screen() .contains("Some installed mods may be incompatible") @@ -705,7 +705,7 @@ fn settings_use_java_memory_and_resolution_controls() { ui.draw(); assert!(ui.screen().contains("Java Runtime")); assert!(ui.screen().contains("auto")); - assert!(ui.screen().contains("custom")); + assert!(!ui.screen().contains("custom")); assert!(!ui.screen().contains("Automatic")); assert!(!ui.screen().contains("Custom path")); assert!(!ui.screen().contains("Manual")); diff --git a/src/tui/widgets/popups/confirm.rs b/src/tui/widgets/popups/confirm.rs index 4a74e1e..015f58a 100644 --- a/src/tui/widgets/popups/confirm.rs +++ b/src/tui/widgets/popups/confirm.rs @@ -47,7 +47,6 @@ pub enum ConfirmTarget { }, InstanceRuntime { name: String, - to: String, }, } @@ -94,8 +93,8 @@ impl ConfirmTarget { }) .collect::>() .join("\n"), - ConfirmTarget::InstanceRuntime { to, .. } => { - format!("Target: {to}\nSome installed mods may be incompatible") + ConfirmTarget::InstanceRuntime { .. } => { + "Some installed mods may be incompatible".to_owned() } } } @@ -182,7 +181,6 @@ pub struct ConfirmPopup { title: String, body: String, confirm_label: &'static str, - accent_border: bool, runtime_confirmation: bool, } @@ -192,7 +190,6 @@ impl ConfirmPopup { title: target.title(), body: target.body(), confirm_label: target.confirm_label(), - accent_border: matches!(target, ConfirmTarget::InstanceRuntime { .. }), runtime_confirmation: matches!(target, ConfirmTarget::InstanceRuntime { .. }), } } @@ -211,11 +208,7 @@ impl Widget for ConfirmPopup { )]); let kb = keybind_line(&[("Esc", " cancel"), ("Enter", self.confirm_label)]); - let border_color = if self.accent_border { - theme.accent() - } else { - theme.text_dim() - }; + let border_color = theme.text_dim(); let bg_color = theme.surface(); let accent = theme.accent(); let text = theme.text(); diff --git a/src/tui/widgets/popups/global_settings.rs b/src/tui/widgets/popups/global_settings.rs index 35f2f5c..6f70208 100644 --- a/src/tui/widgets/popups/global_settings.rs +++ b/src/tui/widgets/popups/global_settings.rs @@ -20,8 +20,8 @@ use crate::{ }, instance::models::normalize_memory_value, tui::widgets::popups::settings_controls::{ - JavaChoice, JavaPicker, adjust_memory, handle_text_area_input, memory_kib, - render_memory_gauge, subtle_tag, + JavaChoice, JavaPicker, adjust_memory, auto_label, handle_text_area_input, memory_kib, + render_memory_gauge, }, }; @@ -217,10 +217,6 @@ impl State { self.toggle_auto_java(); self.java_picker_open = false; } - KeyCode::Char('c') => { - self.java_picker_open = false; - self.editing = Some(new_text_area(vec![self.value(4)])); - } KeyCode::Char('j') | KeyCode::Down if count > 0 => { self.java_picker.selected = (self.java_picker.selected + 1).min(count - 1); } @@ -408,12 +404,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut State) { let keybinds = if state.editing.is_some() { super::keybind_line(&[("Enter", " apply"), ("Esc", " cancel")]) } else if state.java_picker_open { - super::keybind_line(&[ - ("a", " auto"), - ("c", " custom"), - ("h", " back"), - ("Enter", " select"), - ]) + super::keybind_line(&[("a", " auto"), ("h", " back"), ("Enter", " select")]) } else if state.theme_picker { super::keybind_line(&[("h", " back"), ("Enter", " select")]) } else if matches!(state.selected, 2 | 3) { @@ -580,7 +571,7 @@ fn global_field_line(state: &State, index: usize, label: &str) -> Line<'static> ), ]; if index == 4 && state.config.paths.java_path.is_none() && !editing { - spans.extend([Span::raw(" "), subtle_tag("Auto", theme.info())]); + spans.extend([Span::raw(" "), auto_label()]); } Line::from(spans).style(Style::default().bg(if selected { theme.stripe() diff --git a/src/tui/widgets/popups/instance_settings.rs b/src/tui/widgets/popups/instance_settings.rs index 02411d9..55af6b6 100644 --- a/src/tui/widgets/popups/instance_settings.rs +++ b/src/tui/widgets/popups/instance_settings.rs @@ -25,8 +25,8 @@ use crate::{ popups::{ LoadState, settings_controls::{ - DisplayResolution, JavaChoice, JavaPicker, adjust_memory, display_resolutions, - handle_text_area_input, memory_kib, render_memory_gauge, subtle_tag, + DisplayResolution, JavaChoice, JavaPicker, adjust_memory, auto_label, + display_resolutions, handle_text_area_input, memory_kib, render_memory_gauge, }, }, search::SearchState, @@ -106,7 +106,7 @@ pub enum Action { None, Save(Box, bool), Error(String), - ConfirmRuntime { name: String, to: String }, + ConfirmRuntime { name: String }, OpenRaw, Close, } @@ -286,10 +286,6 @@ impl State { self.toggle_auto_java(); self.choice_picker = None; } - KeyCode::Char('c') if self.choice_picker == Some(ChoicePicker::Java) => { - self.choice_picker = None; - self.editing = Some(new_text_area(vec![self.value(3)])); - } KeyCode::Char('d') if self.choice_picker == Some(ChoicePicker::Resolution) => { self.apply_default_resolution(); self.choice_picker = None; @@ -691,7 +687,6 @@ impl State { } return Action::ConfirmRuntime { name: self.draft.name.clone(), - to: runtime_label(&self.draft), }; } if self.validate_before_save() { @@ -777,19 +772,6 @@ impl State { } } -fn runtime_label(config: &InstanceConfig) -> String { - if config.loader == ModLoader::Vanilla { - format!("{} / Vanilla", config.game_version) - } else { - format!( - "{} / {} {}", - config.game_version, - config.loader, - config.loader_version.as_deref().unwrap_or("unknown") - ) - } -} - fn resolution_choices( current: Option<(u32, u32)>, displays: &[DisplayResolution], @@ -883,12 +865,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut State) { } else if state.picker.is_some() { super::keybind_line(&[("/", " search"), ("h", " back"), ("Enter", " select")]) } else if state.choice_picker == Some(ChoicePicker::Java) { - super::keybind_line(&[ - ("a", " auto"), - ("c", " custom"), - ("h", " back"), - ("Enter", " select"), - ]) + super::keybind_line(&[("a", " auto"), ("h", " back"), ("Enter", " select")]) } else if state.choice_picker == Some(ChoicePicker::Resolution) { super::keybind_line(&[("d", " default"), ("h", " back"), ("Enter", " select")]) } else if state.choice_picker.is_some() { @@ -1047,8 +1024,12 @@ fn field_line(state: &State, index: usize, label: &str) -> Line<'static> { Span::styled( value, Style::default() - .fg(if index == 8 && state.desktop { - theme.success() + .fg(if index == 8 { + if state.desktop { + theme.text() + } else { + theme.text_dim() + } } else if selected { theme.accent() } else { @@ -1062,7 +1043,7 @@ fn field_line(state: &State, index: usize, label: &str) -> Line<'static> { ), ]; if index == 3 && state.draft.java_path.is_none() && !editing { - spans.extend([Span::raw(" "), subtle_tag("Auto", theme.info())]); + spans.extend([Span::raw(" "), auto_label()]); } Line::from(spans) } @@ -1508,6 +1489,10 @@ mod tests { state.begin_edit(); assert_eq!(state.choice_picker, Some(ChoicePicker::Java)); state.handle_choice_key(&KeyEvent::from(KeyCode::Char('c'))); + assert_eq!(state.choice_picker, Some(ChoicePicker::Java)); + assert!(state.editing.is_none()); + state.handle_choice_key(&KeyEvent::from(KeyCode::Esc)); + state.handle_key(&KeyEvent::from(KeyCode::Char('c'))); assert!(state.editing.is_some()); } diff --git a/src/tui/widgets/popups/settings_controls.rs b/src/tui/widgets/popups/settings_controls.rs index dc52094..5b83ede 100644 --- a/src/tui/widgets/popups/settings_controls.rs +++ b/src/tui/widgets/popups/settings_controls.rs @@ -160,7 +160,7 @@ impl JavaPicker { Span::styled(format!(" {path}"), Style::default().fg(theme.text_dim())), ]; if self.current.is_none() && path == self.detected { - spans.extend([Span::raw(" "), subtle_tag("Auto", theme.info())]); + spans.extend([Span::raw(" "), auto_label()]); } ListItem::new(Line::from(spans)) } @@ -288,7 +288,7 @@ pub(crate) fn render_memory_gauge( Style::default().fg(theme.text()) }; frame.render_widget( - Paragraph::new(Line::from(Span::styled(format!(" {label} "), value_style))), + Paragraph::new(Line::from(Span::styled(label, value_style))), value_area, ); @@ -336,10 +336,12 @@ pub(crate) fn handle_text_area_input(input: &mut TextArea<'_>, key: &KeyEvent) { } } -pub(crate) fn subtle_tag(label: impl Into, color: ratatui::style::Color) -> Span<'static> { +pub(crate) fn auto_label() -> Span<'static> { Span::styled( - format!(" {} ", label.into()), - Style::default().fg(color).bg(THEME.as_ref().stripe()), + "Auto", + Style::default() + .fg(THEME.as_ref().text_dim()) + .add_modifier(Modifier::ITALIC), ) }