fix: refine default and provider badges
This commit is contained in:
1 parent
a5fdbaf74a
commit
5853ce4fd3
2 files changed
+49
-6
No files matched your search
@@ -7,7 +7,7 @@ use crossterm::event::{KeyCode, KeyEvent};
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::Rect,
|
||||
style::{Modifier, Style},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Clear, ListItem, Paragraph},
|
||||
};
|
||||
@@ -33,6 +33,9 @@ use crate::{
|
||||
};
|
||||
|
||||
const FIELD_COUNT: usize = 24;
|
||||
const MODRINTH_COLOR: Color = Color::Rgb(0x1B, 0xD9, 0x6A);
|
||||
const CURSEFORGE_COLOR: Color = Color::Rgb(0xF1, 0x64, 0x36);
|
||||
const PROVIDER_BADGE_TEXT: Color = Color::Rgb(0x10, 0x10, 0x10);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum ChoicePicker {
|
||||
@@ -1111,10 +1114,7 @@ fn global_field_line(state: &State, index: usize, label: &str) -> Line<'static>
|
||||
}
|
||||
if index == 10 && !editing {
|
||||
spans.push(Span::raw(" "));
|
||||
spans.push(match state.config.content.preferred_provider {
|
||||
ContentProvider::Modrinth => status_badge("Modrinth", theme.success()),
|
||||
ContentProvider::CurseForge => status_badge("CurseForge", theme.warning()),
|
||||
});
|
||||
spans.push(provider_badge(state.config.content.preferred_provider));
|
||||
}
|
||||
if restart_required_for(state, index) {
|
||||
spans.extend([
|
||||
@@ -1138,6 +1138,20 @@ fn border_preview(style: &BorderStyle) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
fn provider_badge(provider: ContentProvider) -> Span<'static> {
|
||||
let (label, color) = match provider {
|
||||
ContentProvider::Modrinth => ("Modrinth", MODRINTH_COLOR),
|
||||
ContentProvider::CurseForge => ("CurseForge", CURSEFORGE_COLOR),
|
||||
};
|
||||
Span::styled(
|
||||
format!(" {label} "),
|
||||
Style::default()
|
||||
.fg(PROVIDER_BADGE_TEXT)
|
||||
.bg(color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
}
|
||||
|
||||
fn border_style_title(style: &BorderStyle) -> &'static str {
|
||||
match style {
|
||||
BorderStyle::Plain => "Plain",
|
||||
@@ -1322,6 +1336,18 @@ mod tests {
|
||||
assert_eq!(state.display_value(6), "Fullscreen");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_badges_use_fixed_brand_colors() {
|
||||
assert_eq!(
|
||||
provider_badge(ContentProvider::Modrinth).style.bg,
|
||||
Some(MODRINTH_COLOR)
|
||||
);
|
||||
assert_eq!(
|
||||
provider_badge(ContentProvider::CurseForge).style.bg,
|
||||
Some(CURSEFORGE_COLOR)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launcher_jvm_and_environment_defaults_share_tag_editing() {
|
||||
let mut state = State::new();
|
||||
|
||||
@@ -1048,7 +1048,7 @@ pub(crate) fn bundled_label() -> Span<'static> {
|
||||
}
|
||||
|
||||
pub(crate) fn default_label() -> Span<'static> {
|
||||
status_badge("Default", THEME.as_ref().success())
|
||||
status_badge("Default", THEME.as_ref().warning())
|
||||
}
|
||||
|
||||
pub(crate) fn render_settings_picker(
|
||||
@@ -1140,6 +1140,9 @@ pub(crate) fn resolution_items(
|
||||
theme.text()
|
||||
}),
|
||||
)];
|
||||
if is_default_resolution(choice.resolution()) {
|
||||
spans.extend([Span::raw(" "), default_label()]);
|
||||
}
|
||||
match choice {
|
||||
ResolutionChoice::Preset(_, _) => {}
|
||||
ResolutionChoice::Display(display) => {
|
||||
@@ -1188,6 +1191,20 @@ mod tests {
|
||||
assert_eq!(default_resolution(), (854, 480));
|
||||
assert!(is_default_resolution(Some((854, 480))));
|
||||
assert!(!is_default_resolution(Some((1440, 2560))));
|
||||
assert_eq!(default_label().style.bg, Some(THEME.as_ref().warning()));
|
||||
|
||||
let choices = resolution_choices(Some((854, 480)), &[]);
|
||||
let backend = ratatui::backend::TestBackend::new(40, 6);
|
||||
let mut terminal = ratatui::Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
frame.render_widget(
|
||||
ratatui::widgets::List::new(resolution_items(&choices, 0)),
|
||||
frame.area(),
|
||||
);
|
||||
})
|
||||
.unwrap();
|
||||
assert!(terminal.backend().to_string().contains("Default"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user