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