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