Skip to main content

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