fix: normalize settings popup styling

This commit is contained in:
objz committed 2026-09-04 15:22:52 +02:00
1 parent 5f99de36ba
commit 45d9b85abf
6 files changed
+32 -62

No files matched your search

+3 -10
View File
@@ -47,7 +47,6 @@ pub enum ConfirmTarget {
},
InstanceRuntime {
name: String,
to: String,
},
}
@@ -94,8 +93,8 @@ impl ConfirmTarget {
})
.collect::<Vec<_>>()
.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();
+4 -13
View File
@@ -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()
+15 -30
View File
@@ -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<InstanceConfig>, 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());
}
+7 -5
View File
@@ -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<String>, 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),
)
}