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