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