Skip to main content

gpui_macos/
lib.rs

1//! macOS's presentation language on gpui-base's interaction primitives.
2//!
3//! Call [`init`] once, then use the constructors in [`controls`] and [`surface`]
4//! inside `Render`. They retain base builder APIs; Button adds disabled-state style gating.
5#![doc = include_str!("../README.md")]
6
7// GPUI macros expand through the canonical `gpui` crate path.
8extern crate gpui_kit as gpui;
9
10pub mod button;
11pub mod button_group;
12pub mod calendar;
13pub mod catalog;
14pub mod chart;
15pub mod chrome;
16pub mod color_picker;
17pub mod controls;
18pub mod date_picker;
19pub mod dialog;
20pub mod dock;
21pub mod fields;
22pub mod focus;
23pub mod hover_card;
24pub mod icon;
25pub mod input;
26pub mod interpretation;
27pub mod link;
28pub mod list;
29pub mod loading;
30pub mod menu;
31mod motion;
32pub mod native;
33pub mod native_assets;
34#[cfg(target_os = "macos")]
35mod native_symbols;
36pub mod navigation;
37pub mod otp_input;
38pub mod plot;
39pub mod popover;
40pub mod resizable;
41pub mod select;
42pub mod sheet;
43pub mod slider;
44pub mod surface;
45mod switch_motion;
46mod system_theme;
47pub mod table;
48pub mod text;
49pub mod theme;
50pub mod tooltip;
51pub mod tree;
52pub mod window;
53
54pub use button::Button;
55pub use button_group::{button_group, tab_list};
56pub use calendar::calendar;
57pub use chart::{
58    AreaChart, BarChart, CandlestickChart, LineChart, PieChart, RadarChart, SankeyChart,
59};
60pub use chrome::*;
61pub use color_picker::color_picker;
62pub use controls::*;
63pub use date_picker::{DatePickerState, date_picker};
64pub use dialog::*;
65pub use dock::dock_area;
66pub use fields::{search_field, secure_field};
67pub use focus::focus_scope;
68pub use hover_card::hover_card;
69pub use icon::{Icon, IconName, icon};
70pub use input::{Input, input, number_input, textarea};
71pub use link::Link;
72pub use list::{inset_list, inset_list_row, scrollbar, virtual_list};
73pub use loading::native_spinner;
74pub use menu::{MenuItem, menu};
75pub use native_assets::NativeAssets;
76pub use navigation::*;
77pub use otp_input::{OtpInput, otp_input};
78pub use popover::{popover, popover_surface};
79pub use resizable::{resizable, resizable_panel};
80pub use select::{ChoiceItem, ChoiceState, combobox, select};
81pub use sheet::{sheet, sheet_surface};
82pub use slider::slider;
83pub use surface::*;
84
85#[doc(hidden)]
86pub use gpui_kit;
87
88/// Create an application using the current desktop platform.
89pub use gpui_kit::application;
90pub use system_theme::{observe_window, refresh_accessibility};
91pub use table::*;
92pub use text::{html, markdown, text_view_style};
93pub use theme::{ActiveTheme, Theme};
94pub use tooltip::{tooltip, with_tooltip};
95pub use tree::tree;
96pub use window::{set_zoom, zoom_percent};
97
98/// Complete GPUI Kit components, styled by the same macOS palette and geometry.
99/// Advanced stateful controls require a `gpui_kit::base::Root` window root.
100pub use gpui_kit::component as kit;
101
102// Advanced components keep their full upstream state and builder APIs.
103pub use button_group::button_group as segmented_control;
104pub use kit::time_field;
105pub use kit::{
106    attachment, breadcrumb, bubble, carousel, clipboard, command, description_list, diff, form,
107    group_box, label, marker, message, message_scroller, notification, questionnaire, rating,
108    setting, shimmer, skeleton, speech, spinner, tag,
109};
110
111/// Native window settings with real system traffic lights and a blurred backdrop.
112/// Place a [`title_bar`] at the top of the content when using this configuration.
113pub fn window_options(
114    title: impl Into<gpui_kit::SharedString>,
115    cx: &gpui_kit::App,
116) -> gpui_kit::WindowOptions {
117    use gpui_kit::*;
118    WindowOptions {
119        titlebar: Some(TitlebarOptions {
120            title: Some(title.into()),
121            appears_transparent: true,
122            traffic_light_position: Some(point(px(16.), px(16.))),
123        }),
124        window_background: if cx.macos().reduce_transparency {
125            WindowBackgroundAppearance::Opaque
126        } else {
127            WindowBackgroundAppearance::Blurred
128        },
129        window_min_size: Some(size(px(640.), px(480.))),
130        ..Default::default()
131    }
132}
133
134/// Window settings for an AppKit toolbar and native glass underlays.
135/// Use with [`native::install_native_toolbar`]. AppKit places the traffic lights;
136/// transparent renderer regions reveal system glass without a legacy blur layer.
137pub fn native_window_options(
138    title: impl Into<gpui_kit::SharedString>,
139    cx: &gpui_kit::App,
140) -> gpui_kit::WindowOptions {
141    let mut options = window_options(title, cx);
142    if let Some(titlebar) = &mut options.titlebar {
143        titlebar.traffic_light_position = None;
144    }
145    options.window_background = if cx.macos().reduce_transparency {
146        gpui_kit::WindowBackgroundAppearance::Opaque
147    } else {
148        gpui_kit::WindowBackgroundAppearance::Transparent
149    };
150    options
151}
152
153/// Open a Root-hosted window and install appearance observation automatically.
154/// Root provides the overlay, notification, focus and text-selection services.
155pub fn open_window<V: gpui_kit::Render + 'static>(
156    options: gpui_kit::WindowOptions,
157    cx: &mut gpui_kit::App,
158    build: impl FnOnce(&mut gpui_kit::Window, &mut gpui_kit::App) -> gpui_kit::Entity<V>,
159) -> anyhow::Result<(gpui_kit::AnyWindowHandle, gpui_kit::Entity<V>)> {
160    gpui_kit::open_window(options, cx, |window, cx| {
161        observe_window(window, cx);
162        build(window, cx)
163    })
164}
165
166/// Initialize all behavior, native adapters, and system appearance once at startup.
167pub fn init(cx: &mut gpui_kit::App) {
168    gpui_kit::init(cx);
169    window::init(cx);
170    focus::init(cx);
171    button_group::init(cx);
172    popover::init(cx);
173    date_picker::init(cx);
174    native::install_glass_popup_presenter(cx);
175    #[cfg(not(target_family = "wasm"))]
176    Theme::follow_system(cx);
177    #[cfg(target_family = "wasm")]
178    Theme::dark().apply(cx);
179}