Skip to main content

gpui_m3/
lib.rs

1//! Material 3 Expressive components for GPUI.
2//!
3//! ```ignore
4//! Application::new().with_assets(gpui_m3::Assets).run(|cx| {
5//!     gpui_m3::init(cx);
6//!     // ...
7//! });
8//! ```
9
10mod assets;
11mod cache;
12pub mod components;
13pub mod interaction;
14pub mod motion;
15pub mod shapes;
16pub mod syntax;
17pub mod theme;
18
19use std::borrow::Cow;
20
21use gpui::App;
22
23pub use assets::{Assets, ICON_PREFIX};
24pub use components::*;
25pub use motion::{MotionSettings, Spring};
26pub use shapes::{Morph, ShapeName, Tone};
27pub use syntax::{SyntaxHighlighter, SyntaxLines, SyntaxPalette, TokenKind};
28pub use theme::{Elevation, Scheme, SchemeVariant, Theme, corner};
29
30/// Registers the typeface, the base (light) theme and the motion settings.
31pub fn init(cx: &mut App) {
32    let fonts: Vec<Cow<'static, [u8]>> = vec![
33        // Inter as static files: DirectWrite does not match the variable one (with an `opsz`
34        // axis) by family name and falls back to Segoe UI.
35        Cow::Borrowed(include_bytes!("../assets/fonts/Inter-Regular.ttf")),
36        Cow::Borrowed(include_bytes!("../assets/fonts/Inter-Medium.ttf")),
37        Cow::Borrowed(include_bytes!("../assets/fonts/Inter-SemiBold.ttf")),
38        Cow::Borrowed(include_bytes!("../assets/fonts/Inter-Bold.ttf")),
39        Cow::Borrowed(include_bytes!("../assets/fonts/Inter-Italic.ttf")),
40        Cow::Borrowed(include_bytes!("../assets/fonts/Roboto.ttf")),
41    ];
42    if let Err(err) = cx.text_system().add_fonts(fonts) {
43        log::warn!("gpui_m3: could not load Inter and Roboto: {err}");
44    }
45    if !cx.has_global::<Theme>() {
46        cx.set_global(Theme::new(false, None));
47    }
48    components::bind_text_field_keys(cx);
49    components::bind_text_area_keys(cx);
50    components::bind_code_editor_keys(cx);
51    components::bind_image_cropper_keys(cx);
52    components::bind_command_palette_keys(cx);
53    // After the text inputs, so open suggestion lists take the arrows, Enter, Tab and Escape.
54    components::bind_suggestion_keys(cx);
55    if !cx.has_global::<MotionSettings>() {
56        cx.set_global(MotionSettings::default());
57    }
58}