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