Skip to main content

ui/
lib.rs

1//! ui — SwiftUI-flavored components for gpui. Reached as `bezel::ui`.
2//!
3//! Style flows through the environment, never through parameters: components
4//! read [`theme::Theme`] (a gpui `Global`) at paint time, the way
5//! SwiftUI views read `@Environment`. Motion comes from the named
6//! `motion` catalog.
7
8use std::borrow::Cow;
9
10use gpui::App;
11
12pub mod combobox;
13pub mod control_bar;
14pub mod date;
15pub mod floating;
16pub mod focus;
17pub mod hover_card;
18pub mod icons;
19pub mod input;
20pub mod list;
21pub mod loaders;
22pub mod menu;
23pub mod menubar;
24pub mod pagination;
25pub mod palette;
26pub mod popover;
27pub mod scroll;
28pub mod stack;
29pub mod stats;
30pub mod surface;
31pub mod table;
32pub mod titlebar;
33pub mod tooltip;
34pub mod tree;
35pub mod widgets;
36
37/// Embedded UI fonts — Geist and Geist Mono (variable), © Vercel Inc.,
38/// licensed under the SIL Open Font License 1.1 (https://openfontlicense.org).
39/// Bundled so the type ships with the binary instead of depending on what the
40/// host system happens to have installed.
41#[cfg(feature = "geist-sans")]
42static FONT_GEIST: &[u8] = include_bytes!("../assets/fonts/Geist.ttf");
43#[cfg(feature = "geist-mono")]
44static FONT_GEIST_MONO: &[u8] = include_bytes!("../assets/fonts/GeistMono.ttf");
45/// Static Geist weights alongside the variable file: gpui's cosmic-text path
46/// (Linux) rasterizes variable fonts at their default instance only — it never
47/// applies `wght` coordinates — so medium/semibold/bold text silently paints
48/// at 400 with just the variable TTF registered. The statics give the face
49/// matcher real 500/600/700 faces (macOS/CoreText applies the variable axis
50/// natively and simply never falls through to these).
51/// They cover the sans only — Geist Mono ships as the variable file alone, so
52/// the cosmic-text path paints every mono weight at 400.
53#[cfg(feature = "geist-weights")]
54static FONT_GEIST_MEDIUM: &[u8] = include_bytes!("../assets/fonts/Geist-Medium.ttf");
55#[cfg(feature = "geist-weights")]
56static FONT_GEIST_SEMIBOLD: &[u8] = include_bytes!("../assets/fonts/Geist-SemiBold.ttf");
57#[cfg(feature = "geist-weights")]
58static FONT_GEIST_BOLD: &[u8] = include_bytes!("../assets/fonts/Geist-Bold.ttf");
59
60/// Register the bundled fonts with the gpui text system. Failure is non-fatal:
61/// the theme's system fallbacks take over (same families the CSS stack names).
62///
63/// Your own fonts go through this same gpui API — `add_fonts` takes any bytes,
64/// and [`theme::Theme::font_sans`] / [`theme::Theme::font_mono`] name which
65/// family the components then paint with.
66pub fn register_fonts(cx: &App) -> gpui::Result<()> {
67    #[allow(unused_mut, reason = "every face below is behind a feature")]
68    let mut fonts: Vec<Cow<'static, [u8]>> = Vec::new();
69    #[cfg(feature = "geist-sans")]
70    fonts.push(Cow::Borrowed(FONT_GEIST));
71    #[cfg(feature = "geist-mono")]
72    fonts.push(Cow::Borrowed(FONT_GEIST_MONO));
73    #[cfg(feature = "geist-weights")]
74    fonts.extend([
75        Cow::Borrowed(FONT_GEIST_MEDIUM),
76        Cow::Borrowed(FONT_GEIST_SEMIBOLD),
77        Cow::Borrowed(FONT_GEIST_BOLD),
78    ]);
79    cx.text_system().add_fonts(fonts)
80}