u0ui 0.3.13

Carbon UI: IBM Carbon v11 visuals with a shadcn-style API for GPUI Kit
Documentation
//! Carbon UI for GPUI: IBM Carbon v11 visuals, shadcn/ui component API,
//! Material Symbols Sharp icons. Kit owns behavior; this crate owns appearance.
//!
//! Layers (each depends only on those above it):
//!
//! | Module | Role |
//! | --- | --- |
//! | [`tokens`] | Generated by `u0ui-codegen` from the design reference `tokens.json`: [`ColorRole`], [`TypeStyle`], spacing/size/radius |
//! | [`theme`] | Active [`CarbonTheme`], [`theme::color`], [`LayerLevel`], Kit theme bridge |
//! | [`typography`] | Bundled IBM Plex, [`TypeStyled::type_style`] |
//! | [`motion`] | Carbon curves and durations, reduced motion, state-change animation helpers |
//! | [`clock`] | Local wall-clock time (`new Date()`): toast captions, today |
//! | [`icons`] | Material Symbols Sharp [`Icon`], [`CarbonIcon`], asset source, Kit icon mapping |
//! | [`density`] | [`Density`] (compact desktop default / comfortable) |
//! | [`components`] | Carbon components ([`components::button`] is the reference) |
//! | [`t3`] | The T3 Code pattern library, composed from the components |
//! | [`u0`] | The u0 pattern library (`u0 · …` cards: foundations, primitives, …) |
//! | [`patterns`] | Building blocks of the Carbon pattern examples (`Carbon · Patterns` cards) |
//!
//! ```no_run
//! use gpui_kit::*;
//! use u0ui::prelude::*;
//!
//! struct App;
//! impl Render for App {
//!     fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
//!         div()
//!             .bg(color(ColorRole::Background))
//!             .child(Button::new("go", "Create project").icon(CarbonIcon::Add))
//!     }
//! }
//!
//! fn main() {
//!     gpui_kit::application().with_assets(u0ui::Assets::new()).run(|cx| {
//!         gpui_kit::init(cx);
//!         u0ui::init(cx);
//!         gpui_kit::open_window(WindowOptions::default(), cx, |_, cx| cx.new(|_| App)).unwrap();
//!     });
//! }
//! ```
#![warn(missing_docs)]

pub mod clock;
pub mod components;
pub mod density;
pub mod focus;
pub mod icons;
pub mod measure;
pub mod motion;
pub mod patterns;
pub mod t3;
pub mod theme;
pub mod tokens;
pub mod typography;
pub mod u0;

pub use density::Density;
pub use icons::{Assets, CarbonIcon, Icon, IconSize};
pub use theme::LayerLevel;
pub use tokens::{CarbonTheme, ColorRole, TypeStyle};
pub use typography::TypeStyled;

/// The README's Rust examples compile as doctests.
#[cfg(doctest)]
#[doc = include_str!("../../../README.md")]
struct ReadmeDoctests;

/// Everything a component or page usually needs.
pub mod prelude {
    pub use crate::components::{Button, ButtonKind, ButtonSize, ButtonVariant};
    pub use crate::density::{self, Density};
    pub use crate::icons::{CarbonIcon, Icon, IconSize};
    pub use crate::motion::{self, Curve, Motion, Speed};
    pub use crate::theme::{self, LayerLevel, color};
    pub use crate::tokens::{self, CarbonTheme, ColorRole, TypeStyle};
    pub use crate::typography::TypeStyled as _;
}

/// Initialize u0ui. Call once after `gpui_kit::init(cx)` and before opening a
/// window: registers the IBM Plex fonts, installs the active theme (White
/// unless [`theme::ActiveTheme`] was set) and projects it into Kit's theme, and
/// maps Kit's default icons to Material Symbols Sharp.
///
/// The application must also serve icon assets:
/// `gpui_kit::application().with_assets(u0ui::Assets::new())`.
pub fn init(cx: &mut gpui_kit::App) {
    typography::register_fonts(cx);
    theme::init(cx);
    icons::init(cx);
    focus::init(cx);
    components::tooltip::init(cx);
    components::menu::init(cx);
    components::navigation_menu::init(cx);
    components::date_picker::init(cx);
    components::overlay::init(cx);
    components::form::init(cx);
    u0::shell::filter_menu::init(cx);
    if cx.try_global::<density::ActiveDensity>().is_none() {
        cx.set_global(density::ActiveDensity(density::current()));
    }
}