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