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