Skip to main content

gpui_kit/
lib.rs

1//! Product-neutral components and interaction primitives for GPUI.
2//!
3//! Components read [`gpui_kit_theme::Theme`] from the application context and
4//! caller-owned data. They do not know about transports, databases,
5//! credentials, or application hosts. Anything that has to survive a frame —
6//! a text field, a menu, a dialog — is a `Render` view; everything else is a
7//! `RenderOnce` builder.
8//!
9//! # Modules
10//!
11//! - [`foundation`] — the contracts every component implements:
12//!   [`Ident`](foundation::Ident), [`Disableable`](foundation::Disableable),
13//!   [`Sizable`](foundation::Sizable), [`Selectable`](foundation::Selectable),
14//!   and the one focus ring, [`FocusRing`](foundation::FocusRing).
15//! - [`content`] — rendered Markdown and a conversation, the two surfaces that
16//!   draw text nobody in this crate wrote. Nothing here executes HTML, opens a
17//!   link, or fetches an image.
18//! - [`controls`] — actions and editable fields.
19//! - [`display`] — status, grouping, and waiting vocabulary.
20//! - [`navigation`] — tabs, accordions, trails, rails, and pages.
21//! - [`data`] — list, table, and tree.
22//! - [`datetime`] — calendar, date field, range, and time, over a
23//!   host-supplied [`DateAdapter`](datetime::DateAdapter). This crate owns no
24//!   calendar.
25//! - [`layout`] — split panes, scroll areas, and toolbars.
26//! - [`media`] — an audio player, a video player, and a bounded 3D model
27//!   viewer, over a [`MediaTransport`](media::MediaTransport) this crate does
28//!   not implement and a glTF reader that refuses more than it accepts.
29//! - [`overlay`] — anchored and modal surfaces, menus, notifications.
30//! - [`interaction`] — drag and drop, the one gesture that starts in one
31//!   component and finishes in another.
32//! - [`motion`] — token-driven animation.
33//! - [`state`] — the explicit async states a truthful surface distinguishes.
34//! - [`strings`] — every word this library shows, and the host's right to
35//!   replace any of them without losing the English behind the rest.
36//! - [`scenes`] — one canonical rendering per component, shared by the gallery,
37//!   the capture task, and the headless audit.
38//!
39//! # Documentation
40//!
41//! - `docs/components.md` — every component and the rules it keeps.
42//! - `docs/coverage.md` — what is provided, and what is deliberately not.
43//! - `docs/truthful-ui.md` — why a refusal is never rendered as an absence.
44//! - `docs/semantic-automation.md` — the semantic tree and what a node reports.
45//! - `docs/token-model.md` — where visible values come from.
46//! - `docs/interaction.md` — the drag contract: what a drop reports, what a
47//!   drag publishes, and what the host has to do with it.
48//! - `docs/content.md` — what a rendered document is not allowed to do, and
49//!   what a conversation's five delivery states mean.
50//!
51//! ```no_run
52//! # use gpui_kit::prelude::*;
53//! # fn example() -> impl gpui::IntoElement {
54//! Button::new("settings.save")
55//!     .label("Save")
56//!     .primary()
57//!     .on_click(|_window, _cx| {})
58//! # }
59//! ```
60
61pub mod agent;
62pub mod canvas;
63pub mod content;
64pub mod controls;
65pub mod data;
66pub mod datetime;
67pub mod display;
68pub mod foundation;
69pub mod interaction;
70pub mod layout;
71pub mod media;
72pub mod motion;
73pub mod navigation;
74pub mod overlay;
75pub mod scenes;
76pub mod state;
77pub mod strings;
78pub mod structured;
79
80pub use gpui_kit_assets as assets;
81pub use gpui_kit_semantics as semantics;
82pub use gpui_kit_theme as theme;
83pub use gpui_kit_tokens as tokens;
84
85use gpui::App;
86
87/// Everything a view needs to build with this library.
88pub mod prelude {
89    pub use crate::agent::approval::{
90        AlwaysScope, ApprovalDecision, ApprovalEvent, ApprovalPrompt, ApprovalStatus,
91    };
92    pub use crate::agent::cost::{
93        Basis, ContextGauge, CostLine, CostMeter, LastVerified, Limit, Quantity, Reading,
94    };
95    pub use crate::agent::offering_catalog::{
96        OfferingCatalog, OfferingIdentity, OfferingSource, OfferingSourceState, SearchableOffering,
97    };
98    pub use crate::agent::permission::{
99        PermissionAction, PermissionChange, PermissionEntry, PermissionMatrix, PermissionSource,
100        PermissionState, PermissionSubject,
101    };
102    pub use crate::agent::server_list::{
103        Catalog, Offering, OfferingKind, ServerEntry, ServerList, ServerState,
104    };
105    pub use crate::agent::step_list::{RunLength, Step, StepList, StepState};
106    pub use crate::agent::thinking::{Reasoning, ThinkingBlock};
107    pub use crate::agent::tool_call::{Elapsed, ToolBody, ToolCallCard, ToolCallState, ToolOutput};
108    pub use crate::canvas::{
109        Diff, EdgeKind, GraphEdge, GraphEndpoint, GraphNode, GraphPort, GraphState, GraphViewport,
110        NodeGraph, NodeGraphEvent, NodeMetric, NodeState, Placed, PortDirection, PortSide,
111    };
112    pub use crate::content::{
113        Attachment, BrowserPanel, BufferedRange, CodeBlock, CodeLine, CodeSpan, CodeView,
114        DeliveryState, DiffFile, DiffHunk, DiffLine, DiffPresentation, DiffView, DiffViewEvent,
115        FitMode, ImageFrame, ImageRequest, ImageSize, ImageState, ImageViewer, ImageViewerEvent,
116        LineMark, LogEntry, LogStream, LogStreamState, Markdown, MarkdownEvent, Message,
117        MessageBody, MessageList, Reaction, TrackStep, TransportBar, TransportDuration,
118        TransportEvent, TransportState, ViewportState,
119    };
120    pub use crate::controls::auth::{
121        OneTimeCodeInput, OneTimeCodeInputEvent, PasswordInput, PasswordInputEvent,
122    };
123    pub use crate::controls::button::{
124        Button, ButtonGroup, ButtonJoin, ButtonVariant, IconButton, IconPosition,
125    };
126    pub use crate::controls::cascader::{Cascader, CascaderEvent, CascaderOption};
127    pub use crate::controls::combobox::{Combobox, ComboboxEvent};
128    pub use crate::controls::copy_button::{CopyButton, CopyEvent, CopyState};
129    pub use crate::controls::dropzone::{Dropzone, DropzoneState};
130    pub use crate::controls::field::{FieldState, field_shell};
131    pub use crate::controls::filter_bar::{FilterBar, FilterCondition, ResultCount};
132    pub use crate::controls::form_field::FormField;
133    pub use crate::controls::inline_edit::InlineEdit;
134    pub use crate::controls::input::{TextInput, TextInputEvent};
135    pub use crate::controls::keybinding_recorder::{KeybindingRecorder, KeybindingRecorderEvent};
136    pub use crate::controls::keymap_editor::{
137        KeymapBinding, KeymapCommand, KeymapEditor, KeymapEditorEvent,
138    };
139    pub use crate::controls::number_input::{NumberInput, NumberInputEvent};
140    pub use crate::controls::search::{
141        FindReplace, FindReplaceEvent, HitCount, SearchField, SearchFieldEvent,
142    };
143    pub use crate::controls::segmented::{Segment, SegmentedControl};
144    pub use crate::controls::select::{Select, SelectEvent, SelectOption};
145    pub use crate::controls::settings_row::{SettingsRow, SettingsSection};
146    pub use crate::controls::slider::Slider;
147    pub use crate::controls::split_button::SplitButton;
148    pub use crate::controls::tag_input::{TagInput, TagInputEvent};
149    pub use crate::controls::textarea::{TextArea, TextAreaEvent};
150    pub use crate::controls::toggle::{Checkbox, Radio, Switch};
151    pub use crate::controls::toggle_button::{Toggle, ToggleGroup, ToggleItem, ToggleSelection};
152    pub use crate::controls::upload_list::{OverallProgress, Upload, UploadList, UploadState};
153    pub use crate::data::{
154        Align, BulkBar, Cell, Column, ColumnWidth, DataGrid, Diagnostic, DiagnosticAction,
155        DiagnosticFilter, DiagnosticLocation, DiagnosticSeverity, DiagnosticsList, EditIntent,
156        EditOutcome, EditingCell, Expanded, GridColumn, GridLines, GridRow, List, ListItem, Row,
157        SelectionChange, SelectionMode, SortDirection, Table, Tree, TreeGrid, TreeGridRow,
158        TreeNode,
159    };
160    pub use crate::datetime::{
161        BlockedDay, BlockedReport, Calendar, CalendarEvent, Clock, DateAdapter, DateInput,
162        DateInputEvent, Day, DayMark, DayRange, MonthCell, MonthGrid, MonthKey, RangePicker,
163        RangePickerEvent, RangeState, Selectability, SharedDateAdapter, TimeInput, TimeInputEvent,
164        TimeOfDay, TimeSegment,
165    };
166    pub use crate::display::animated_number::{AnimatedNumber, grouped};
167    pub use crate::display::avatar::Avatar;
168    pub use crate::display::badge::{Badge, Tone};
169    pub use crate::display::card::{Card, ListRow};
170    pub use crate::display::description_list::{
171        DescriptionItem, DescriptionList, DescriptionValue,
172    };
173    pub use crate::display::empty::{Divider, EmptyKind, EmptyState};
174    pub use crate::display::failure_panel::FailurePanel;
175    pub use crate::display::highlight::HighlightedText;
176    pub use crate::display::icon::{Icon, IconTone};
177    pub use crate::display::loading::{GradientSpinner, PulseLoader, Skeleton};
178    pub use crate::display::progress::ProgressBar;
179    pub use crate::display::progress_circle::ProgressCircle;
180    pub use crate::display::sparkline::{
181        Sparkline, SparklinePoint, SparklineReading, SparklineState,
182    };
183    pub use crate::display::status::{Callout, StatusDot, StatusLine};
184    pub use crate::display::tag::Tag;
185    pub use crate::display::timeline::{EntryTime, Timeline, TimelineEntry, TimelineGroup};
186    pub use crate::foundation::direction::{
187        ActiveDirection, DirectionalExt, LayoutDirection, LogicalSide, PhysicalSide,
188        set_layout_direction,
189    };
190    pub use crate::foundation::{
191        ActiveTheme, ControlSize, Density, Disableable, Elevation, FocusRing, HoverLift, Ident,
192        Layer, Pressable, Selectable, Sizable, StyledExt, ThemeRegistry, activate_theme,
193        set_density, text,
194    };
195    pub use crate::interaction::dnd::{
196        ActiveDrag, DragItem, DropAxis, DropIntent, DropPosition, StagedDrag,
197    };
198    pub use crate::layout::{
199        AspectFit, AspectRatio, Dock, DockEvent, DockPanel, DockRegion, FadeEdges, ScrollArea,
200        ScrollAxis, ScrollFade, SplitAxis, SplitChange, SplitKind, SplitLayout, SplitPane,
201        SplitPaneSpec, SplitRecord, SplitRecordError, SplitSide, SplitTree, StatusBar, StatusGroup,
202        StatusItem, Toolbar, ToolbarItem, scroll_offset,
203    };
204    pub use crate::media::{
205        AudioPlayer, FixtureTransport, MediaAvailability, MediaCommand, MediaEvent, MediaOrigin,
206        MediaOutcome, MediaSnapshot, MediaTransport, ModelBounds, ModelDefect, ModelError,
207        ModelLimit, ModelMesh, ModelScene, ModelShading, ModelState, ModelViewer, ModelViewerEvent,
208        VideoPlayer,
209    };
210    pub use crate::motion::{
211        Flip, Flipping, Keyframe, Keyframes, Presence, ScrollLink, Transition, Velocity, flip,
212    };
213    pub use crate::navigation::{
214        Accordion, AccordionSection, Anchor, AnchorList, Breadcrumb, Collapsible, Crumb,
215        HistoryEntry, PageTotal, Pagination, SaveState, Sidebar, SidebarItem, SidebarSection,
216        StepStatus, TabItem, Tabs, UndoHistory, Wizard, WizardIntent, WizardLayout, WizardStep,
217    };
218    pub use crate::overlay::{
219        Command, CommandPalette, CommandPaletteEvent, ContextMenu, ContextMenuEvent, Dialog,
220        DialogEvent, Drawer, DrawerEvent, Edge, FocusTrap, Frost, HoverCard, HoverCardEvent, Kbd,
221        Menu, MenuEvent, MenuItem, Menubar, MenubarEvent, MenubarMenu, Notification,
222        NotificationCenter, NotificationCenterEvent, Overlay, Placement, Popover, PopoverEvent,
223        Toast, ToastCorner, ToastLayer, Tooltip, Tooltipped, UnreadCount,
224    };
225    pub use crate::state::{AsyncStatus, AsyncValue, Loadable};
226    pub use crate::strings::{ActiveStrings, StringKey, Strings, reset_strings, set_strings};
227    pub use crate::structured::{
228        FieldValue, JsonValue, JsonView, NumberBounds, Schema, SchemaChoice, SchemaField,
229        SchemaForm, SchemaFormEvent, SchemaKind, UnrenderableField, ValueKind,
230    };
231}
232
233/// Installs fonts, the theme global, and the semantic registry.
234pub fn install(cx: &mut App) {
235    gpui_kit_assets::register_fonts(cx);
236    gpui_kit_theme::Theme::install(cx);
237    gpui_kit_semantics::install(cx);
238    strings::install(cx);
239    foundation::direction::install(cx);
240    interaction::install(cx);
241    controls::input::install(cx);
242    controls::textarea::install(cx);
243    overlay::toast::install(cx);
244}