Strengthen theme contrast and cover the heading font fallback (#82)
CI / core (pull_request) Successful in 1m31s
CI / core (pull_request) Successful in 1m31s
This commit is contained in:
1 parent
bfb29e02fe
commit
eb21db17ad
7 files changed
+202
-161
No files matched your search
@@ -1,3 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="48 48 160 160" width="48" height="48">
|
||||
<path fill="#161b2e" d="M68 186 L52 86 L98 126 L128 66 L158 126 L204 86 L188 186 Z"/>
|
||||
<path fill="currentColor" d="M68 186 L52 86 L98 126 L128 66 L158 126 L204 86 L188 186 Z"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 183 B After Width: | Height: | Size: 188 B |
+35
-36
@@ -10,6 +10,7 @@ use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::text::{ordinal, thousands};
|
||||
use crate::theme::{LOGO_GOLD, ON_GOLD, surface};
|
||||
|
||||
/// Width over height: the ratio the stored portraits are cropped to.
|
||||
pub const ASPECT: f32 = arena_tracker_core::CARD_ASPECT as f32;
|
||||
@@ -18,8 +19,6 @@ const RADIUS: f32 = 10.;
|
||||
const INNER_RADIUS: f32 = RADIUS - 1.;
|
||||
|
||||
// The caption and badges sit on the dark shade, in both themes: their colours are fixed.
|
||||
const ACCENT: u32 = 0xf5b83d;
|
||||
const INK: u32 = 0x161b2e;
|
||||
const MARK_ON: u32 = 0xffffff;
|
||||
const MARK_OFF: u32 = 0xd3d4db;
|
||||
const MARK_OFF_RING: u32 = 0xbfc1cd;
|
||||
@@ -63,22 +62,40 @@ impl Reason {
|
||||
}
|
||||
}
|
||||
|
||||
fn icon(self) -> AnyElement {
|
||||
let icon = match self {
|
||||
fn badge(self, id: u32) -> Div {
|
||||
let badge = div()
|
||||
.h_flex()
|
||||
.items_center()
|
||||
.gap(px(4.))
|
||||
.px(px(6.))
|
||||
.py(px(3.))
|
||||
.rounded(px(4.))
|
||||
.text_size(px(10.))
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.debug_selector(move || format!("reason-{id}-{}", self.label()));
|
||||
let ordinary = |badge: Div, icon: IconName| {
|
||||
badge
|
||||
.bg(rgba(BADGE_BG))
|
||||
.text_color(rgb(BADGE_TEXT))
|
||||
.child(Icon::new(icon).size(px(12.)))
|
||||
};
|
||||
let badge = match self {
|
||||
Reason::Completed => {
|
||||
static CROWN: LazyLock<Arc<Image>> = LazyLock::new(|| {
|
||||
Arc::new(Image::from_bytes(
|
||||
ImageFormat::Svg,
|
||||
include_bytes!("../assets/crown.svg").to_vec(),
|
||||
))
|
||||
let svg = include_str!("../assets/crown.svg")
|
||||
.replace("currentColor", &format!("#{ON_GOLD:06x}"));
|
||||
Arc::new(Image::from_bytes(ImageFormat::Svg, svg.into_bytes()))
|
||||
});
|
||||
return img(CROWN.clone()).size(px(12.)).into_any_element();
|
||||
badge
|
||||
.bg(rgb(LOGO_GOLD))
|
||||
.text_color(rgb(ON_GOLD))
|
||||
.child(img(CROWN.clone()).size(px(12.)))
|
||||
}
|
||||
Reason::Banned => IconName::Ban,
|
||||
Reason::TakenByAlly => IconName::User,
|
||||
Reason::NotOffered => IconName::EyeOff,
|
||||
Reason::Banned => ordinary(badge, IconName::Ban),
|
||||
Reason::TakenByAlly => ordinary(badge, IconName::User),
|
||||
Reason::NotOffered => ordinary(badge, IconName::EyeOff),
|
||||
};
|
||||
Icon::new(icon).size(px(12.)).into_any_element()
|
||||
badge.child(self.label())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +210,7 @@ fn sheet_lines(row: &ChampionRow) -> Vec<(&'static str, SharedString)> {
|
||||
/// stop with an accent border while the keyboard is on it. The caller adds its own listeners.
|
||||
pub fn card(card: &Card, state: CardState<'_>, cx: &App) -> Stateful<Div> {
|
||||
let theme = cx.theme();
|
||||
let (border, ring, background) = (theme.border, theme.ring, theme.muted);
|
||||
let (border, ring, background) = (theme.border, theme.ring, surface(theme));
|
||||
let greyed = card.greyed();
|
||||
let id = card.id;
|
||||
div()
|
||||
@@ -303,25 +320,7 @@ fn reasons(id: u32, reasons: &[Reason]) -> Div {
|
||||
.items_start()
|
||||
.flex_wrap()
|
||||
.gap(px(3.))
|
||||
.children(reasons.iter().map(|reason| {
|
||||
div()
|
||||
.h_flex()
|
||||
.items_center()
|
||||
.gap(px(4.))
|
||||
.px(px(6.))
|
||||
.py(px(3.))
|
||||
.rounded(px(4.))
|
||||
.bg(rgba(BADGE_BG))
|
||||
.text_color(rgb(BADGE_TEXT))
|
||||
.when(*reason == Reason::Completed, |badge| {
|
||||
badge.bg(rgb(ACCENT)).text_color(rgb(INK))
|
||||
})
|
||||
.text_size(px(10.))
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.debug_selector(|| format!("reason-{id}-{}", reason.label()))
|
||||
.child(reason.icon())
|
||||
.child(reason.label())
|
||||
}))
|
||||
.children(reasons.iter().map(|reason| reason.badge(id)))
|
||||
}
|
||||
|
||||
fn caption(card: &Card) -> Div {
|
||||
@@ -369,10 +368,10 @@ fn mark(label: &'static str, on: bool) -> Div {
|
||||
.size(px(11.))
|
||||
.rounded_full()
|
||||
.border_1()
|
||||
.border_color(rgb(if on { ACCENT } else { MARK_OFF_RING }))
|
||||
.border_color(rgb(if on { LOGO_GOLD } else { MARK_OFF_RING }))
|
||||
.when(on, |dot| {
|
||||
dot.bg(rgb(ACCENT))
|
||||
.text_color(rgb(INK))
|
||||
dot.bg(rgb(LOGO_GOLD))
|
||||
.text_color(rgb(ON_GOLD))
|
||||
.child(Icon::new(IconName::Check).size(px(8.)))
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -295,7 +295,7 @@ fn main() {
|
||||
app.run(move |cx| {
|
||||
gpui_kit::init(cx);
|
||||
card_grid::init(cx);
|
||||
theme::init_theme(cx);
|
||||
theme::init(cx);
|
||||
#[cfg(feature = "profile")]
|
||||
profile::start(cx);
|
||||
let options = WindowOptions {
|
||||
|
||||
@@ -11,7 +11,7 @@ use gpui_kit::*;
|
||||
|
||||
use super::{Page, shown};
|
||||
use crate::card_grid::{MAX_WIDTH, row_height};
|
||||
use crate::theme::heading;
|
||||
use crate::theme::{banner_band, gold_ink, heading};
|
||||
|
||||
/// The filters on offer, whatever the Season.
|
||||
pub(super) const FILTERS: [(&str, StateFilter); 3] = [
|
||||
@@ -359,10 +359,10 @@ impl Page {
|
||||
/// The Season, the title and, beside it, the champions Completed out of the Challenge's total.
|
||||
fn home_header(&self, cx: &App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (muted, border, gold_ink, fill) = (
|
||||
let (muted, border, ink, fill) = (
|
||||
theme.muted_foreground,
|
||||
theme.border,
|
||||
theme.link,
|
||||
gold_ink(theme),
|
||||
theme.progress_bar,
|
||||
);
|
||||
let counter = match &self.home_season {
|
||||
@@ -380,11 +380,7 @@ impl Page {
|
||||
.whitespace_nowrap()
|
||||
.text_xs()
|
||||
.text_color(muted)
|
||||
.child(
|
||||
heading(cx)
|
||||
.text_color(gold_ink)
|
||||
.child(self.home_count.clone()),
|
||||
)
|
||||
.child(heading(cx).text_color(ink).child(self.home_count.clone()))
|
||||
.child("champions validés"),
|
||||
)
|
||||
.child(
|
||||
@@ -408,7 +404,7 @@ impl Page {
|
||||
};
|
||||
div()
|
||||
.v_flex()
|
||||
.bg(theme.title_bar)
|
||||
.bg(banner_band(theme))
|
||||
.p_3()
|
||||
.gap_1()
|
||||
.children(
|
||||
|
||||
@@ -10,7 +10,7 @@ use gpui_kit::*;
|
||||
|
||||
use super::{Page, shown};
|
||||
use crate::text::{decimal, official_note};
|
||||
use crate::theme::heading;
|
||||
use crate::theme::{heading, surface};
|
||||
|
||||
const NO_MATCH: &str = "Aucune Partie";
|
||||
|
||||
@@ -44,7 +44,7 @@ fn tile(
|
||||
.flex_1()
|
||||
.gap_1()
|
||||
.p_3()
|
||||
.bg(theme.muted)
|
||||
.bg(surface(theme))
|
||||
.border_1()
|
||||
.border_color(theme.border)
|
||||
.rounded_md()
|
||||
@@ -102,12 +102,11 @@ fn challenge_tiles(
|
||||
|
||||
/// A titled card holding a chart, or `empty` in its place.
|
||||
fn card(
|
||||
title: &'static str,
|
||||
title: Div,
|
||||
chart: Option<AnyElement>,
|
||||
empty: &'static str,
|
||||
cx: &App,
|
||||
theme: &Theme,
|
||||
) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let body = chart.unwrap_or_else(|| {
|
||||
div()
|
||||
.size_full()
|
||||
@@ -125,11 +124,11 @@ fn card(
|
||||
.h_full()
|
||||
.gap_2()
|
||||
.p_3()
|
||||
.bg(theme.muted)
|
||||
.bg(surface(theme))
|
||||
.border_1()
|
||||
.border_color(theme.border)
|
||||
.rounded_md()
|
||||
.child(heading(cx).text_sm().child(title))
|
||||
.child(title.text_sm())
|
||||
.child(div().flex_1().min_h_0().w_full().children(Some(body)))
|
||||
}
|
||||
|
||||
@@ -176,48 +175,49 @@ impl Render for ChartsRow {
|
||||
{
|
||||
self.renders += 1;
|
||||
}
|
||||
let theme = cx.theme();
|
||||
let charts = &self.charts;
|
||||
let mut cards = Vec::new();
|
||||
// The curve first: it is the Season's story, the others detail it.
|
||||
if self.in_season {
|
||||
cards.push(
|
||||
card(
|
||||
"Champions validés au fil de la Saison",
|
||||
heading(cx).child("Champions validés au fil de la Saison"),
|
||||
if shown("completed") {
|
||||
completed_chart(charts)
|
||||
} else {
|
||||
Some(div().size_full().into_any_element())
|
||||
},
|
||||
"Aucun champion validé",
|
||||
cx,
|
||||
theme,
|
||||
)
|
||||
.into_any_element(),
|
||||
);
|
||||
}
|
||||
cards.push(
|
||||
card(
|
||||
"Répartition des Placements",
|
||||
heading(cx).child("Répartition des Placements"),
|
||||
if shown("placements") {
|
||||
placements_chart(charts)
|
||||
} else {
|
||||
Some(div().size_full().into_any_element())
|
||||
},
|
||||
NO_MATCH,
|
||||
cx,
|
||||
theme,
|
||||
)
|
||||
.into_any_element(),
|
||||
);
|
||||
if self.in_season {
|
||||
cards.push(
|
||||
card(
|
||||
"Tentatives pour valider",
|
||||
heading(cx).child("Tentatives pour valider"),
|
||||
if shown("attempts") {
|
||||
attempts_chart(charts)
|
||||
} else {
|
||||
Some(div().size_full().into_any_element())
|
||||
},
|
||||
"Aucun champion validé",
|
||||
cx,
|
||||
theme,
|
||||
)
|
||||
.into_any_element(),
|
||||
);
|
||||
@@ -303,12 +303,15 @@ impl Page {
|
||||
let options = filters(self.in_season());
|
||||
let selected = options.iter().position(|(_, f)| *f == self.filter);
|
||||
let challenge = self.stats.as_ref().and_then(|s| s.challenge.as_ref());
|
||||
let mut content = vec![
|
||||
heading(cx)
|
||||
.text_3xl()
|
||||
.child("Statistiques")
|
||||
.into_any_element(),
|
||||
];
|
||||
let mut content = Vec::new();
|
||||
if shown("statistics-title") {
|
||||
content.push(
|
||||
heading(cx)
|
||||
.text_3xl()
|
||||
.child("Statistiques")
|
||||
.into_any_element(),
|
||||
);
|
||||
}
|
||||
if shown("tiles")
|
||||
&& let Some(c) = challenge
|
||||
{
|
||||
|
||||
+137
-94
@@ -9,9 +9,25 @@ use gpui_kit::*;
|
||||
const INTER: &str = "Inter Variable Text";
|
||||
const UNBOUNDED: &str = "Unbounded";
|
||||
|
||||
pub const LOGO_GOLD: u32 = 0xf5b83d;
|
||||
pub const ON_GOLD: u32 = 0x161b2e;
|
||||
|
||||
pub fn surface(theme: &Theme) -> Hsla {
|
||||
theme.muted
|
||||
}
|
||||
|
||||
pub fn banner_band(theme: &Theme) -> Hsla {
|
||||
theme.title_bar
|
||||
}
|
||||
|
||||
pub fn gold_ink(theme: &Theme) -> Hsla {
|
||||
theme.link
|
||||
}
|
||||
|
||||
struct HeadingFamily(SharedString);
|
||||
impl Global for HeadingFamily {}
|
||||
|
||||
/// Builds a semibold heading with the family selected at startup.
|
||||
pub fn heading(cx: &App) -> Div {
|
||||
let family = cx
|
||||
.try_global::<HeadingFamily>()
|
||||
@@ -21,6 +37,7 @@ pub fn heading(cx: &App) -> Div {
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
}
|
||||
|
||||
/// Registers the embedded face and checks that the platform resolves the requested weight.
|
||||
fn load_font(cx: &App, bytes: &'static [u8], family: &'static str, weight: FontWeight) -> bool {
|
||||
let text = cx.text_system();
|
||||
if let Err(error) = text.add_fonts(vec![Cow::Borrowed(bytes)]) {
|
||||
@@ -33,19 +50,19 @@ fn load_font(cx: &App, bytes: &'static [u8], family: &'static str, weight: FontW
|
||||
text.get_font_for_id(text.resolve_font(&requested)) == Some(requested)
|
||||
}
|
||||
|
||||
pub fn init_theme(cx: &mut App) {
|
||||
/// Sets up the app palettes and fonts after `gpui_kit::init`.
|
||||
pub fn init(cx: &mut App) {
|
||||
init_with_heading_font(cx, include_bytes!("../assets/Unbounded-SemiBold.ttf"));
|
||||
}
|
||||
|
||||
fn init_with_heading_font(cx: &mut App, heading_bytes: &'static [u8]) {
|
||||
let inter = load_font(
|
||||
cx,
|
||||
include_bytes!("../assets/InterVariable.ttf"),
|
||||
INTER,
|
||||
FontWeight::NORMAL,
|
||||
);
|
||||
let heading = if load_font(
|
||||
cx,
|
||||
include_bytes!("../assets/Unbounded-SemiBold.ttf"),
|
||||
UNBOUNDED,
|
||||
FontWeight::SEMIBOLD,
|
||||
) {
|
||||
let heading = if load_font(cx, heading_bytes, UNBOUNDED, FontWeight::SEMIBOLD) {
|
||||
UNBOUNDED.into()
|
||||
} else {
|
||||
cx.theme().font_family.clone()
|
||||
@@ -61,28 +78,36 @@ pub fn init_theme(cx: &mut App) {
|
||||
// Several kit tokens share each palette role. Register them on the saved configs
|
||||
// so changing appearance reapplies the same palette as startup.
|
||||
macro_rules! role {
|
||||
($dark:literal, $light:literal => $($token:ident),+ ) => {{
|
||||
($dark:expr, $light:expr => $($token:ident),+ ) => {{
|
||||
let value = if config.mode.is_dark() { $dark } else { $light };
|
||||
$(config.colors.$token = Some(value.into());)+
|
||||
let hex = SharedString::from(format!("#{value:06x}"));
|
||||
$(config.colors.$token = Some(hex.clone());)+
|
||||
}};
|
||||
}
|
||||
role!("#11152a", "#eef0f7" => background);
|
||||
role!("#151a33", "#e5e8f3" => title_bar, table_head, list_head);
|
||||
role!("#181e38", "#ffffff" => table, list, popover, muted, button, list_even, table_even);
|
||||
role!("#20274a", "#e4e8f4" => secondary, secondary_hover, accent, button_hover, table_hover,
|
||||
role!(0x11152a, 0xeef0f7 => background);
|
||||
role!(0x151a33, 0xe5e8f3 => title_bar, table_head, list_head);
|
||||
role!(0x181e38, 0xffffff => table, list, popover, muted, button, list_even, table_even);
|
||||
role!(0x20274a, 0xe4e8f4 => secondary, secondary_hover, accent, button_hover, table_hover,
|
||||
list_hover, tab_bar, tab_bar_segmented);
|
||||
role!("#283053", "#d2d7e9" => border, input, title_bar_border, window_border, table_row_border,
|
||||
role!(0x283053, 0xd2d7e9 => border, input, title_bar_border, window_border, table_row_border,
|
||||
chart_grid, secondary_active, button_active);
|
||||
role!("#edeaf7", "#161b2e" => foreground, popover_foreground, accent_foreground, secondary_foreground);
|
||||
role!("#8b91b1", "#596082" => muted_foreground, tab_foreground, table_head_foreground, scrollbar_thumb_hover);
|
||||
role!("#3a4166", "#c5cbe0" => switch, scrollbar_thumb);
|
||||
role!("#f5b83d", "#e3a21a" => primary, tab_active, chart_2, ring, progress_bar, list_active_border, table_active_border);
|
||||
role!("#f5b83d", "#8f5d00" => link, link_hover, link_active, caret, warning);
|
||||
role!("#ff7a7a", "#c62f2f" => danger);
|
||||
role!("#67e8f9", "#11667b" => info);
|
||||
role!("#4ade80", "#196638" => success);
|
||||
role!("#161b2e", "#161b2e" => primary_foreground, tab_active_foreground);
|
||||
role!("#f5b83d38", "#e3a21a38" => selection, list_active, table_active);
|
||||
role!(0xedeaf7, ON_GOLD => foreground, popover_foreground, accent_foreground, secondary_foreground);
|
||||
role!(0x8b91b1, 0x596082 => muted_foreground, tab_foreground, table_head_foreground, scrollbar_thumb_hover);
|
||||
role!(0x3a4166, 0xc5cbe0 => switch, scrollbar_thumb);
|
||||
role!(LOGO_GOLD, 0xe3a21a => primary, tab_active, chart_1, chart_2, chart_3, chart_4, chart_5, slider_bar, progress_bar);
|
||||
role!(LOGO_GOLD, 0x8f5d00 => link, link_hover, link_active, caret, warning, ring, drag_border, list_active_border, table_active_border);
|
||||
role!(0xff7a7a, 0xc62f2f => danger);
|
||||
role!(0x67e8f9, 0x11667b => info);
|
||||
role!(0x4ade80, 0x196638 => success);
|
||||
role!(ON_GOLD, ON_GOLD => primary_foreground, tab_active_foreground);
|
||||
let selection = config
|
||||
.colors
|
||||
.primary
|
||||
.as_ref()
|
||||
.map(|gold| SharedString::from(format!("{gold}38")));
|
||||
config.colors.selection = selection.clone();
|
||||
config.colors.list_active = selection.clone();
|
||||
config.colors.table_active = selection;
|
||||
// Let the kit derive pressed and hovered primary buttons from our gold.
|
||||
config.colors.primary_active = None;
|
||||
config.colors.primary_hover = None;
|
||||
@@ -92,22 +117,60 @@ pub fn init_theme(cx: &mut App) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::INTER;
|
||||
use super::{INTER, UNBOUNDED, banner_band, gold_ink, heading, surface};
|
||||
use gpui_kit::component::{Theme, ThemeMode};
|
||||
use gpui_kit::{FontWeight, TestAppContext, font, px};
|
||||
use gpui_kit::{FontWeight, Hsla, Styled as _, TestAppContext, font, px};
|
||||
|
||||
// Not #[gpui::test]: its text system is a no-op, and this checks DirectWrite's real one.
|
||||
#[test]
|
||||
fn identity_fonts_and_colors_are_used_in_both_themes() {
|
||||
// GPUI's usual test text system is a no-op. These tests exercise DirectWrite.
|
||||
fn windows_context() -> TestAppContext {
|
||||
let platform = gpui_kit::platform::current_platform(false);
|
||||
let cx = TestAppContext::build_with_text_system(
|
||||
TestAppContext::build_with_text_system(
|
||||
gpui::TestDispatcher::new(0),
|
||||
None,
|
||||
platform.text_system(),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unreadable_unbounded_keeps_the_system_heading_in_both_themes() {
|
||||
windows_context().update(|cx| {
|
||||
gpui_kit::init(cx);
|
||||
let system = Theme::global(cx).font_family.clone();
|
||||
super::init_with_heading_font(cx, b"invalid font file");
|
||||
for mode in [ThemeMode::Dark, ThemeMode::Light] {
|
||||
Theme::change(mode, None, cx);
|
||||
assert_eq!(Theme::global(cx).font_family.as_str(), INTER);
|
||||
assert_eq!(heading(cx).text_style().font_family.as_ref(), Some(&system));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn assert_contrast(ink: Hsla, background: Hsla, minimum: f32) {
|
||||
let [a, b] = [ink, background].map(|color| {
|
||||
let rgb = color.to_rgb();
|
||||
let [r, g, b] = [rgb.r, rgb.g, rgb.b].map(|v| {
|
||||
if v <= 0.04045 {
|
||||
v / 12.92
|
||||
} else {
|
||||
((v + 0.055) / 1.055).powf(2.4)
|
||||
}
|
||||
});
|
||||
0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
});
|
||||
let ratio = (a.max(b) + 0.05) / (a.min(b) + 0.05);
|
||||
assert!(
|
||||
ratio >= minimum,
|
||||
"{ink:?} on {background:?}: {ratio:.2}:1 < {minimum}:1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn identity_fonts_and_colors_are_used_in_both_themes() {
|
||||
let cx = windows_context();
|
||||
cx.update(|cx| {
|
||||
gpui_kit::init(cx);
|
||||
super::init_theme(cx);
|
||||
super::init(cx);
|
||||
assert_eq!(
|
||||
Theme::global(cx).background,
|
||||
if Theme::global(cx).mode.is_dark() {
|
||||
@@ -117,76 +180,56 @@ mod tests {
|
||||
}
|
||||
.into()
|
||||
);
|
||||
for (mode, palette) in [
|
||||
(
|
||||
ThemeMode::Light,
|
||||
[
|
||||
0xeef0f7, 0xe5e8f3, 0xffffff, 0xe4e8f4, 0xd2d7e9, 0x161b2e, 0x596082,
|
||||
0xc5cbe0, 0xe3a21a, 0x8f5d00,
|
||||
],
|
||||
),
|
||||
(
|
||||
ThemeMode::Dark,
|
||||
[
|
||||
0x11152a, 0x151a33, 0x181e38, 0x20274a, 0x283053, 0xedeaf7, 0x8b91b1,
|
||||
0x3a4166, 0xf5b83d, 0xf5b83d,
|
||||
],
|
||||
),
|
||||
] {
|
||||
for mode in [ThemeMode::Light, ThemeMode::Dark] {
|
||||
Theme::change(mode, None, cx);
|
||||
let theme = Theme::global(cx);
|
||||
assert_eq!(theme.font_family.as_str(), INTER);
|
||||
let family = &cx.global::<super::HeadingFamily>().0;
|
||||
assert_eq!(family.as_str(), "Unbounded");
|
||||
let mut heading = font(family.clone());
|
||||
heading.weight = FontWeight::SEMIBOLD;
|
||||
let style = heading(cx).text_style().clone();
|
||||
let family = style.font_family.unwrap();
|
||||
assert_eq!(family.as_str(), UNBOUNDED);
|
||||
let mut face = font(family);
|
||||
face.weight = style.font_weight.unwrap();
|
||||
assert_eq!(face.weight, FontWeight::SEMIBOLD);
|
||||
let text = cx.text_system();
|
||||
assert_eq!(
|
||||
text.get_font_for_id(text.resolve_font(&heading)),
|
||||
Some(heading)
|
||||
);
|
||||
assert_eq!(
|
||||
[
|
||||
theme.background,
|
||||
theme.title_bar,
|
||||
theme.table,
|
||||
theme.secondary,
|
||||
theme.border,
|
||||
theme.foreground,
|
||||
theme.muted_foreground,
|
||||
theme.switch,
|
||||
theme.primary,
|
||||
theme.link
|
||||
],
|
||||
palette.map(|color| gpui::rgb(color).into())
|
||||
);
|
||||
for accent in [
|
||||
theme.tab_active,
|
||||
theme.ring,
|
||||
theme.chart_2,
|
||||
theme.progress_bar,
|
||||
] {
|
||||
assert_eq!(accent, theme.primary);
|
||||
assert_eq!(text.get_font_for_id(text.resolve_font(&face)), Some(face));
|
||||
|
||||
macro_rules! colors {
|
||||
($dark:literal, $light:literal => $($token:ident),+) => {{
|
||||
let expected: Hsla = gpui::rgb(if mode.is_dark() { $dark } else { $light }).into();
|
||||
$(assert_eq!(theme.colors.$token, expected, "{} {mode:?}", stringify!($token));)+
|
||||
}};
|
||||
}
|
||||
assert_eq!(theme.tab_active_foreground, gpui::rgb(0x161b2e).into());
|
||||
colors!(0x11152a, 0xeef0f7 => background);
|
||||
colors!(0x151a33, 0xe5e8f3 => title_bar, table_head, list_head);
|
||||
colors!(0x181e38, 0xffffff => table, list, popover, muted, button, list_even, table_even);
|
||||
colors!(0x20274a, 0xe4e8f4 => secondary, secondary_hover, accent, button_hover, table_hover,
|
||||
list_hover, tab_bar, tab_bar_segmented);
|
||||
colors!(0x283053, 0xd2d7e9 => border, input, title_bar_border, window_border, table_row_border,
|
||||
chart_grid, secondary_active, button_active);
|
||||
colors!(0xedeaf7, 0x161b2e => foreground, popover_foreground, accent_foreground, secondary_foreground);
|
||||
colors!(0x8b91b1, 0x596082 => muted_foreground, tab_foreground, table_head_foreground, scrollbar_thumb_hover);
|
||||
colors!(0x3a4166, 0xc5cbe0 => switch, scrollbar_thumb);
|
||||
colors!(0xf5b83d, 0xe3a21a => primary, tab_active, chart_1, chart_2, chart_3, chart_4, chart_5, slider_bar, progress_bar);
|
||||
colors!(0xf5b83d, 0x8f5d00 => link, link_hover, link_active, warning, caret, ring, drag_border, list_active_border, table_active_border);
|
||||
colors!(0xff7a7a, 0xc62f2f => danger);
|
||||
colors!(0x67e8f9, 0x11667b => info);
|
||||
colors!(0x4ade80, 0x196638 => success);
|
||||
colors!(0x161b2e, 0x161b2e => primary_foreground, button_primary_foreground, tab_active_foreground);
|
||||
let selection: Hsla = gpui::rgba(if mode.is_dark() { 0xf5b83d38 } else { 0xe3a21a38 }).into();
|
||||
assert_eq!(theme.selection, selection);
|
||||
// The kit caps selected rows at 20% opacity.
|
||||
assert_eq!(theme.list_active, theme.primary.opacity(0.2));
|
||||
assert_eq!(theme.table_active, theme.primary.opacity(0.2));
|
||||
for bg in [theme.background, banner_band(theme), surface(theme), theme.secondary] {
|
||||
for ink in [theme.foreground, theme.muted_foreground, gold_ink(theme)] {
|
||||
assert_contrast(ink, bg, 4.5);
|
||||
}
|
||||
assert_contrast(theme.ring, bg, 3.);
|
||||
}
|
||||
assert_contrast(theme.primary_foreground, theme.primary, 4.5);
|
||||
for ink in [theme.warning, theme.danger, theme.info, theme.success] {
|
||||
// Alert paints its text over a 4% tint of the same colour.
|
||||
let background = theme.background.blend(ink.opacity(0.04));
|
||||
let [a, b] = [ink, background].map(|color| {
|
||||
let rgb = color.to_rgb();
|
||||
let [r, g, b] = [rgb.r, rgb.g, rgb.b].map(|v| {
|
||||
if v <= 0.04045 {
|
||||
v / 12.92
|
||||
} else {
|
||||
((v + 0.055) / 1.055).powf(2.4)
|
||||
}
|
||||
});
|
||||
0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
});
|
||||
assert!(
|
||||
(a.max(b) + 0.05) / (a.min(b) + 0.05) >= 4.5,
|
||||
"{mode:?} alert {ink:?}"
|
||||
);
|
||||
assert_contrast(ink, theme.background.blend(ink.opacity(0.04)), 4.5);
|
||||
}
|
||||
}
|
||||
// DirectWrite returns the nearest weight, so only a wider glyph proves a semibold face.
|
||||
|
||||
Reference in new issue
Block a user