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