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