diff --git a/crates/app/assets/Unbounded-LICENSE.txt b/crates/app/assets/Unbounded-LICENSE.txt
new file mode 100644
index 0000000..deb478a
--- /dev/null
+++ b/crates/app/assets/Unbounded-LICENSE.txt
@@ -0,0 +1,93 @@
+Copyright 2022 The Unbounded Project Authors (https://github.com/googlefonts/unbounded)
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+https://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/crates/app/assets/Unbounded-SemiBold.ttf b/crates/app/assets/Unbounded-SemiBold.ttf
new file mode 100644
index 0000000..ade1608
Binary files /dev/null and b/crates/app/assets/Unbounded-SemiBold.ttf differ
diff --git a/crates/app/assets/crown.svg b/crates/app/assets/crown.svg
new file mode 100644
index 0000000..f262112
--- /dev/null
+++ b/crates/app/assets/crown.svg
@@ -0,0 +1,3 @@
+
diff --git a/crates/app/src/card.rs b/crates/app/src/card.rs
index 34259e4..a37b9a1 100644
--- a/crates/app/src/card.rs
+++ b/crates/app/src/card.rs
@@ -2,7 +2,7 @@
//! select. A `Card` is built once when the statistics change; `card` only lays it out.
use std::path::Path;
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
use arena_tracker_core::{ChampionRow, Marks, Unpickable};
use gpui_kit::component::{ActiveTheme as _, Icon, IconName, StyledExt as _};
@@ -18,16 +18,16 @@ 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 = 0xc4b3fc;
-const INK: u32 = 0x201732;
-const MARK_ON: u32 = 0xdfd4ff;
-const MARK_OFF: u32 = 0xcdccd4;
-const MARK_OFF_RING: u32 = 0xacaab7;
-const BADGE_BG: u32 = 0x202027ee;
-const BADGE_TEXT: u32 = 0xf0eff3;
+const ACCENT: u32 = 0xf5b83d;
+const INK: u32 = 0x161b2e;
+const MARK_ON: u32 = 0xffffff;
+const MARK_OFF: u32 = 0xd3d4db;
+const MARK_OFF_RING: u32 = 0xbfc1cd;
+const BADGE_BG: u32 = 0x11152aee;
+const BADGE_TEXT: u32 = 0xffa0a0;
// The sheet is dark in both themes, like the shade it replaces.
-const SHEET_BG: u32 = 0x16161ef5;
-const SHEET_LABEL: u32 = 0xb4b4c3;
+const SHEET_BG: u32 = 0x0d1021f5;
+const SHEET_LABEL: u32 = 0xc5cbe0;
// The sheet's lines, in order.
const PLAYED: &str = "Parties";
@@ -63,13 +63,22 @@ impl Reason {
}
}
- fn icon(self) -> IconName {
- match self {
- Reason::Completed => IconName::Check,
+ fn icon(self) -> AnyElement {
+ let icon = match self {
+ Reason::Completed => {
+ static CROWN: LazyLock> = LazyLock::new(|| {
+ Arc::new(Image::from_bytes(
+ ImageFormat::Svg,
+ include_bytes!("../assets/crown.svg").to_vec(),
+ ))
+ });
+ return img(CROWN.clone()).size(px(12.)).into_any_element();
+ }
Reason::Banned => IconName::Ban,
Reason::TakenByAlly => IconName::User,
Reason::NotOffered => IconName::EyeOff,
- }
+ };
+ Icon::new(icon).size(px(12.)).into_any_element()
}
}
@@ -271,8 +280,8 @@ fn sheet(card: &Card) -> Div {
/// Keeps the caption readable on any portrait.
fn shade() -> Div {
- let clear = hsla(240. / 360., 0.3, 0.06, 0.);
- let dark = hsla(240. / 360., 0.3, 0.06, 0.95);
+ let clear = rgba(0x090b1800);
+ let dark = rgba(0x090b18f2);
div()
.absolute()
.inset_0()
@@ -304,10 +313,13 @@ fn reasons(id: u32, reasons: &[Reason]) -> Div {
.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(Icon::new(reason.icon()).size(px(12.)))
+ .child(reason.icon())
.child(reason.label())
}))
}
diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs
index 6fa601d..2cda557 100644
--- a/crates/app/src/main.rs
+++ b/crates/app/src/main.rs
@@ -12,11 +12,12 @@ mod release;
mod settings;
mod single_instance;
mod text;
+mod theme;
mod title_bar;
mod tray;
mod worker;
-use std::{borrow::Cow, ops::ControlFlow, rc::Rc, sync::Arc};
+use std::{ops::ControlFlow, sync::Arc};
use arena_tracker_core::{
Config, DataDragon, LeagueClient, Preferences, RiotApi, Tracker, data_dir, default_seasons,
@@ -277,26 +278,6 @@ fn startup() -> Result, Preferences)> {
})
}
-/// DirectWrite exposes the variable font's text optical size as its own family.
-const INTER: &str = "Inter Variable Text";
-
-/// Sets Inter as the interface font and adjusts the theme colours. Needs `gpui_kit::init` first.
-fn init_theme(cx: &mut App) {
- let text = cx.text_system();
- let ttf = include_bytes!("../assets/InterVariable.ttf");
- if let Err(error) = text.add_fonts(vec![Cow::Borrowed(ttf)]) {
- eprintln!("Failed to load Inter: {error}");
- }
- // A family that falls back costs a font lookup on every text run: keep the system font then.
- let inter = font(INTER);
- if text.get_font_for_id(text.resolve_font(&inter)) == Some(inter) {
- Theme::update(cx, |theme| theme.font_family = INTER.into());
- }
- // The default dark table header text has low contrast against its background.
- let dark = Rc::make_mut(&mut Theme::global_mut(cx).dark_theme);
- dark.colors.table_head_foreground = dark.colors.muted_foreground.clone();
-}
-
fn main() {
release::handle_command();
let Some(single_instance::Primary {
@@ -314,7 +295,7 @@ fn main() {
app.run(move |cx| {
gpui_kit::init(cx);
card_grid::init(cx);
- init_theme(cx);
+ theme::init_theme(cx);
#[cfg(feature = "profile")]
profile::start(cx);
let options = WindowOptions {
@@ -369,46 +350,16 @@ mod tests {
use std::sync::Arc;
use arena_tracker_core::{ChampionSort, Config, RiotApi, Tracker, UpdateChannel};
- use gpui_kit::component::{Theme, ThemeMode};
use gpui_kit::{
- AppContext as _, Entity, FontWeight, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
- TestAppContext, VisualTestContext, WindowOptions, font, point, px,
+ AppContext as _, Entity, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, TestAppContext,
+ VisualTestContext, WindowOptions, point,
};
- use super::{INTER, KeyStore, RootView, Screen, Setup};
+ use super::{KeyStore, RootView, Screen, Setup};
use crate::card_images::tests::TestDir;
use crate::title_bar::{BAR_HEIGHT, BUTTON_WIDTH};
use crate::worker::UpdateChecked;
- // Not #[gpui::test]: its text system is a no-op, and this checks DirectWrite's real one.
- #[test]
- fn inter_is_used_in_both_themes() {
- let platform = gpui_kit::platform::current_platform(false);
- let cx = TestAppContext::build_with_text_system(
- gpui::TestDispatcher::new(0),
- None,
- platform.text_system(),
- );
- cx.update(|cx| {
- gpui_kit::init(cx);
- super::init_theme(cx);
- for mode in [ThemeMode::Light, ThemeMode::Dark] {
- Theme::change(mode, None, cx);
- assert_eq!(Theme::global(cx).font_family.as_str(), INTER);
- }
- // DirectWrite returns the nearest weight, so only a wider glyph proves a semibold face.
- let text = cx.text_system();
- let [regular, semibold] = [FontWeight::NORMAL, FontWeight::SEMIBOLD].map(|weight| {
- let mut requested = font(INTER);
- requested.weight = weight;
- let id = text.resolve_font(&requested);
- assert_eq!(text.get_font_for_id(id), Some(requested));
- text.advance(id, px(14.), 'm').unwrap().width
- });
- assert!(semibold > regular, "{semibold:?} <= {regular:?}");
- });
- }
-
/// A first launch: no key and nothing stored.
fn first_launch(cx: &mut TestAppContext) -> (VisualTestContext, Entity) {
cx.update(gpui_kit::init);
diff --git a/crates/app/src/page.rs b/crates/app/src/page.rs
index 249bf43..f7b53df 100644
--- a/crates/app/src/page.rs
+++ b/crates/app/src/page.rs
@@ -1200,7 +1200,9 @@ impl Page {
// Always bordered, so the focus ring does not shift the label.
.border_1()
.border_color(transparent_black())
- .focus_visible(|style| style.border_color(ring))
+ .focus_visible(|style| {
+ style.border_color(if current { active_foreground } else { ring })
+ })
.text_color(if current { active_foreground } else { muted })
.when(current, |button| button.bg(active))
.when(!current && !disabled, |button| {
diff --git a/crates/app/src/page/home.rs b/crates/app/src/page/home.rs
index f1902c4..aa52666 100644
--- a/crates/app/src/page/home.rs
+++ b/crates/app/src/page/home.rs
@@ -11,6 +11,7 @@ use gpui_kit::*;
use super::{Page, shown};
use crate::card_grid::{MAX_WIDTH, row_height};
+use crate::theme::heading;
/// The filters on offer, whatever the Season.
pub(super) const FILTERS: [(&str, StateFilter); 3] = [
@@ -201,12 +202,7 @@ impl Page {
.h_flex()
.items_center()
.gap(px(6.))
- .child(
- div()
- .text_xl()
- .font_weight(FontWeight::SEMIBOLD)
- .child("Champions de l'Enclume"),
- )
+ .child(heading(cx).text_xl().child("Champions de l'Enclume"))
.when(row.is_none(), |heading| {
heading.child(count_badge(self.anvil_count.clone(), muted, border))
}),
@@ -281,11 +277,10 @@ impl Page {
.focus_visible(|style| style.border_color(ring))
.hover(|style| style.bg(hover).text_color(hover_foreground))
.text_lg()
- .font_weight(FontWeight::SEMIBOLD)
.accessibility_label(title)
.debug_selector(|| "others-toggle".into())
.child(Icon::new(chevron).small().text_color(muted))
- .child(title)
+ .child(heading(cx).child(title))
.on_click(cx.listener(|this, _, _, cx| this.toggle_others(cx))),
)
.when(open, |section| {
@@ -330,12 +325,7 @@ impl Page {
.h_flex()
.items_center()
.gap(px(6.))
- .child(
- div()
- .text_xl()
- .font_weight(FontWeight::SEMIBOLD)
- .child("Mes champions"),
- )
+ .child(heading(cx).text_xl().child("Mes champions"))
.child(count_badge(self.home_shown_count.clone(), muted, border)),
)
.child(
@@ -351,7 +341,7 @@ impl Page {
)
.child(
TabBar::new("home-filter")
- .segmented()
+ .pill()
.selected_index(selected.unwrap_or(0))
.children(FILTERS.iter().map(|(label, _)| Tab::new().label(*label)))
.on_click(cx.listener(|this, ix: &usize, _, cx| {
@@ -369,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, foreground, fill) = (
+ let (muted, border, gold_ink, fill) = (
theme.muted_foreground,
theme.border,
- theme.foreground,
+ theme.link,
theme.progress_bar,
);
let counter = match &self.home_season {
@@ -391,9 +381,8 @@ impl Page {
.text_xs()
.text_color(muted)
.child(
- div()
- .font_weight(FontWeight::SEMIBOLD)
- .text_color(foreground)
+ heading(cx)
+ .text_color(gold_ink)
.child(self.home_count.clone()),
)
.child("champions validés"),
@@ -419,6 +408,8 @@ impl Page {
};
div()
.v_flex()
+ .bg(theme.title_bar)
+ .p_3()
.gap_1()
.children(
self.home_season
@@ -433,13 +424,11 @@ impl Page {
.justify_between()
.gap_x_4()
.gap_y_1()
- .child(div().text_3xl().font_weight(FontWeight::SEMIBOLD).child(
- if self.in_champ_select() {
- "Sélection des champions"
- } else {
- "Défi de saison"
- },
- ))
+ .child(heading(cx).text_3xl().child(if self.in_champ_select() {
+ "Sélection des champions"
+ } else {
+ "Défi de saison"
+ }))
.children(counter),
)
}
diff --git a/crates/app/src/page/statistics.rs b/crates/app/src/page/statistics.rs
index cd7da2d..3e7ebe3 100644
--- a/crates/app/src/page/statistics.rs
+++ b/crates/app/src/page/statistics.rs
@@ -5,11 +5,12 @@ use gpui_kit::component::chart::{AreaChart, BarChart};
use gpui_kit::component::input::Input;
use gpui_kit::component::select::Select;
use gpui_kit::component::tab::{Tab, TabBar};
-use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
+use gpui_kit::component::{ActiveTheme as _, StyledExt as _, Theme};
use gpui_kit::*;
use super::{Page, shown};
use crate::text::{decimal, official_note};
+use crate::theme::heading;
const NO_MATCH: &str = "Aucune Partie";
@@ -36,32 +37,41 @@ fn tile(
label: &'static str,
value: String,
note: Option,
- border: Hsla,
- muted: Hsla,
+ theme: &Theme,
) -> impl IntoElement {
div()
.v_flex()
.flex_1()
.gap_1()
.p_3()
+ .bg(theme.muted)
.border_1()
- .border_color(border)
+ .border_color(theme.border)
.rounded_md()
- .child(div().text_sm().text_color(muted).child(label))
+ .child(
+ div()
+ .text_sm()
+ .text_color(theme.muted_foreground)
+ .child(label),
+ )
.child(
div()
.text_xl()
.font_weight(FontWeight::SEMIBOLD)
.child(value),
)
- .children(note.map(|note| div().text_xs().text_color(muted).child(note)))
+ .children(note.map(|note| {
+ div()
+ .text_xs()
+ .text_color(theme.muted_foreground)
+ .child(note)
+ }))
}
fn challenge_tiles(
c: &ChallengeSummary,
official: Option<&ProgressCheck>,
- border: Hsla,
- muted: Hsla,
+ theme: &Theme,
) -> impl IntoElement {
let average = c.average_attempts.map_or("-".into(), |a| decimal(a, 2));
// Next to the count whether the app agrees or not; the banner covers the difference.
@@ -78,29 +88,15 @@ fn challenge_tiles(
"Champions validés",
format!("{} / {}", c.completed, c.total),
note,
- border,
- muted,
- ))
- .child(tile(
- "Tentatives",
- c.attempts.to_string(),
- None,
- border,
- muted,
- ))
- .child(tile(
- "Tentatives par champion validé",
- average,
- None,
- border,
- muted,
+ theme,
))
+ .child(tile("Tentatives", c.attempts.to_string(), None, theme))
+ .child(tile("Tentatives par champion validé", average, None, theme))
.child(tile(
"Du premier coup",
c.first_tries.to_string(),
None,
- border,
- muted,
+ theme,
))
}
@@ -109,16 +105,16 @@ fn card(
title: &'static str,
chart: Option,
empty: &'static str,
- border: Hsla,
- muted: Hsla,
+ cx: &App,
) -> impl IntoElement {
+ let theme = cx.theme();
let body = chart.unwrap_or_else(|| {
div()
.size_full()
.flex()
.items_center()
.justify_center()
- .text_color(muted)
+ .text_color(theme.muted_foreground)
.child(empty)
.into_any_element()
});
@@ -129,15 +125,11 @@ fn card(
.h_full()
.gap_2()
.p_3()
+ .bg(theme.muted)
.border_1()
- .border_color(border)
+ .border_color(theme.border)
.rounded_md()
- .child(
- div()
- .text_sm()
- .font_weight(FontWeight::SEMIBOLD)
- .child(title),
- )
+ .child(heading(cx).text_sm().child(title))
.child(div().flex_1().min_h_0().w_full().children(Some(body)))
}
@@ -184,10 +176,6 @@ impl Render for ChartsRow {
{
self.renders += 1;
}
- let (border, muted) = {
- let theme = cx.theme();
- (theme.border, theme.muted_foreground)
- };
let charts = &self.charts;
let mut cards = Vec::new();
// The curve first: it is the Season's story, the others detail it.
@@ -201,8 +189,7 @@ impl Render for ChartsRow {
Some(div().size_full().into_any_element())
},
"Aucun champion validé",
- border,
- muted,
+ cx,
)
.into_any_element(),
);
@@ -216,8 +203,7 @@ impl Render for ChartsRow {
Some(div().size_full().into_any_element())
},
NO_MATCH,
- border,
- muted,
+ cx,
)
.into_any_element(),
);
@@ -231,8 +217,7 @@ impl Render for ChartsRow {
Some(div().size_full().into_any_element())
},
"Aucun champion validé",
- border,
- muted,
+ cx,
)
.into_any_element(),
);
@@ -315,18 +300,19 @@ impl Page {
/// Under the banners: the Challenge tiles, the charts, the filters and the table.
pub(super) fn statistics_content(&self, cx: &mut Context) -> Vec {
- let (border, muted) = {
- let theme = cx.theme();
- (theme.border, theme.muted_foreground)
- };
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::new();
+ let mut content = vec![
+ heading(cx)
+ .text_3xl()
+ .child("Statistiques")
+ .into_any_element(),
+ ];
if shown("tiles")
&& let Some(c) = challenge
{
- content.push(challenge_tiles(c, self.official(), border, muted).into_any_element());
+ content.push(challenge_tiles(c, self.official(), cx.theme()).into_any_element());
}
content.push(
self.charts
@@ -343,7 +329,7 @@ impl Page {
.gap_3()
.child(
TabBar::new("state-filter")
- .segmented()
+ .pill()
.selected_index(selected.unwrap_or(0))
.children(options.iter().map(|(label, _)| Tab::new().label(*label)))
.on_click(cx.listener(|this, ix: &usize, _, cx| {
diff --git a/crates/app/src/theme.rs b/crates/app/src/theme.rs
new file mode 100644
index 0000000..586aa46
--- /dev/null
+++ b/crates/app/src/theme.rs
@@ -0,0 +1,204 @@
+//! Arena Tracker's two palettes and the fonts registered once at startup.
+
+use std::{borrow::Cow, rc::Rc};
+
+use gpui_kit::component::{ActiveTheme as _, Theme};
+use gpui_kit::*;
+
+/// DirectWrite exposes Inter's text optical size as its own family.
+const INTER: &str = "Inter Variable Text";
+const UNBOUNDED: &str = "Unbounded";
+
+struct HeadingFamily(SharedString);
+impl Global for HeadingFamily {}
+
+pub fn heading(cx: &App) -> Div {
+ let family = cx
+ .try_global::()
+ .map_or_else(|| &cx.theme().font_family, |heading| &heading.0);
+ div()
+ .font_family(family.clone())
+ .font_weight(FontWeight::SEMIBOLD)
+}
+
+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)]) {
+ eprintln!("Failed to load {family}: {error}");
+ return false;
+ }
+ // Naming a missing family incurs a fallback lookup on every text run.
+ let mut requested = font(family);
+ requested.weight = weight;
+ text.get_font_for_id(text.resolve_font(&requested)) == Some(requested)
+}
+
+pub fn init_theme(cx: &mut App) {
+ 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,
+ ) {
+ UNBOUNDED.into()
+ } else {
+ cx.theme().font_family.clone()
+ };
+ cx.set_global(HeadingFamily(heading));
+
+ let theme = Theme::global_mut(cx);
+ for config in [&mut theme.light_theme, &mut theme.dark_theme] {
+ let config = Rc::make_mut(config);
+ if inter {
+ config.font_family = Some(INTER.into());
+ }
+ // 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),+ ) => {{
+ let value = if config.mode.is_dark() { $dark } else { $light };
+ $(config.colors.$token = Some(value.into());)+
+ }};
+ }
+ 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,
+ list_hover, tab_bar, tab_bar_segmented);
+ role!("#283053", "#d2d7e9" => 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);
+ // Let the kit derive pressed and hovered primary buttons from our gold.
+ config.colors.primary_active = None;
+ config.colors.primary_hover = None;
+ }
+ Theme::change(theme.mode, None, cx);
+}
+
+#[cfg(test)]
+mod tests {
+ use super::INTER;
+ use gpui_kit::component::{Theme, ThemeMode};
+ use gpui_kit::{FontWeight, 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() {
+ let platform = gpui_kit::platform::current_platform(false);
+ let cx = TestAppContext::build_with_text_system(
+ gpui::TestDispatcher::new(0),
+ None,
+ platform.text_system(),
+ );
+ cx.update(|cx| {
+ gpui_kit::init(cx);
+ super::init_theme(cx);
+ assert_eq!(
+ Theme::global(cx).background,
+ if Theme::global(cx).mode.is_dark() {
+ gpui::rgb(0x11152a)
+ } else {
+ gpui::rgb(0xeef0f7)
+ }
+ .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,
+ ],
+ ),
+ ] {
+ Theme::change(mode, None, cx);
+ let theme = Theme::global(cx);
+ assert_eq!(theme.font_family.as_str(), INTER);
+ let family = &cx.global::().0;
+ assert_eq!(family.as_str(), "Unbounded");
+ let mut heading = font(family.clone());
+ heading.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!(theme.tab_active_foreground, gpui::rgb(0x161b2e).into());
+ 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:?}"
+ );
+ }
+ }
+ // DirectWrite returns the nearest weight, so only a wider glyph proves a semibold face.
+ let text = cx.text_system();
+ let [regular, semibold] = [FontWeight::NORMAL, FontWeight::SEMIBOLD].map(|weight| {
+ let mut requested = font(INTER);
+ requested.weight = weight;
+ let id = text.resolve_font(&requested);
+ assert_eq!(text.get_font_for_id(id), Some(requested));
+ text.advance(id, px(14.), 'm').unwrap().width
+ });
+ assert!(semibold > regular, "{semibold:?} <= {regular:?}");
+ });
+ }
+}
diff --git a/crates/app/src/title_bar.rs b/crates/app/src/title_bar.rs
index 84b0fc2..b7c9132 100644
--- a/crates/app/src/title_bar.rs
+++ b/crates/app/src/title_bar.rs
@@ -105,7 +105,7 @@ pub fn title_bar(
.child(settings)
.children(update)
.child(
- div()
+ crate::theme::heading(cx)
.h_flex()
.h_full()
.flex_1()