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