Expand description
shadcn-style components for GPUI, built on gpui-base.
gpui-cn depends on gpui-kit with the component layer off, so it adds
GPUI and gpui-base and nothing else.
Initialize gpui-base first (through gpui_kit::init), then call
init once before opening windows. gpui-cn adds itself to every
window whose first level is gpui-base’s Root, which
gpui_kit::open_window puts there:
use gpui_kit::*;
struct Hello;
impl Render for Hello {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
div().p_4().child(
gpui_cn::Button::new("save")
.primary()
.label("Save")
.on_click(|_, window, cx| {
let _ = window.prompt(PromptLevel::Info, "Saved", None, &["OK"], cx);
}),
)
}
}
fn main() {
gpui_kit::application().run(|cx| {
gpui_kit::init(cx);
gpui_cn::init(cx);
gpui_kit::open_window(WindowOptions::default(), cx, |_, cx| cx.new(|_| Hello))
.expect("failed to open window");
});
}Re-exports§
pub use dock::DockSkin;pub use theme::ActiveTheme;pub use theme::MetricTokens;pub use theme::ReduceMotion;pub use theme::Theme;pub use theme::ThemeConfig;pub use theme::ThemeMode;pub use theme::ThemeScope;pub use theme::ThemeTokens;pub use webview::BrowserEvent;pub use webview::BrowserState;pub use webview::WebFrame;pub use gpui_kit;
Modules§
- dock
- Panes that the user rearranges by dragging, as in Ghostty’s splits.
- fuzzy
- The fuzzy matcher every search in gpui-cn uses: the folder and file pickers, the model picker, the selects, the searchable status lists, and the palettes.
- prelude
- Everything an application normally imports from gpui-cn.
- remote
- Pickers over a machine that is not this one.
- shell
- The user’s shell, how a terminal starts it, and the environment it gives the program, resolved as Ghostty does.
- terminal
- A terminal on libghostty-vt, the terminal emulation library from
Ghostty, behind the
ghosttyfeature. - theme
- The theme: a small config per appearance, the tokens derived from it, and the preferences that shape motion and cursors.
- webview
- An embedded web page, on
gpui-webview.
Structs§
- Attachment
- A file in a composer: what the strip shows for it.
- Attachment
Strip - The row of tiles above a composer’s text: the attachments in order, wrapping onto further lines when they do not fit.
- Attachment
Tile - One tile of the attachment strip: an image thumbnail, or a bordered
file tile with a tinted kind icon and the name. A tile that uploads
draws a circular
Progressat its top left and a percent counter at its top right; when the upload ends, the counter and the ring fade out as the dismiss button fades in. - Avatar
- A shadcn-style avatar: a circle that shows an image, or the initials of a name, or an icon when there is no image.
- Avatar
Group - A row of overlapping avatars, shadcn’s
*:ring-2 -space-x-2, with a+Navatar for the ones past its limit. - Badge
- A count, a dot, or an icon at the corner of another element, such as
unread messages on an avatar. gpui-kit’s
Badge. - Button
- A shadcn-style button on
gpui_base::Button. - Command
- A command palette on a
CommandState, as shadcn’sCommand: the search field, a hairline, and the matching commands in a scroll region, drawn with a menu’s rows. - Command
Dialog - A
Commandpalette in aDialog, as shadcn’sCommandDialogand the palettes opened with Cmd+K. - Command
Group - Commands under a heading. A group with no command left after the query hides with its heading.
- Command
Item - One command: a key the palette reports it by, a label, and what it does.
- Command
Row - The state of a row a custom renderer draws; see
CommandItem::render. - Command
State - The commands of a
Commandpalette, its query, and its highlight. - Composer
- A prompt box: a card with the attachments above the text, and a row of controls under it. The row holds an add button, a permission menu, a space, a model picker, a microphone button, and a send button. An optional status tab sits behind the top of the card.
- Composer
Assets - An asset source for an application that uses the composer family: the
default
gpui_kit::assets::Assetsplus the Lucide icons the composer’s defaults draw, which the default set does not hold (the microphone, the shield, the file kinds, and the git branch). - Composer
State - The text, the attachments, the permission mode, and the model of a
Composer. - Composer
Status Tab - The strip behind the top of a composer’s card: any number of items
from the left, such as a folder, a device, and a branch, in the full
text color (each a
StatusSelectthat opens a menu), and optionally aContextMeteror any element at the far right. With no trailing element there is nothing at the right. - Context
Menu - A menu of commands that a right click on its content opens at the
pointer, as shadcn’s
ContextMenu. - Context
Meter - The context a conversation has used, as a ring and a percent: a
circular
Progressbeside the number, in the muted text color. - Dialog
- A modal window over the page, as shadcn’s
Dialog: a dimmed backdrop and a centered surface with a title, a description, a body, and a footer. - Dropdown
Menu - A menu of commands that opens under a trigger, as shadcn’s
DropdownMenu. - Effort
Menu - The effort of the chosen model as a small dropdown: the level’s name,
such as “Medium”, and a chevron. Its menu lists the state’s effort
levels,
EFFORT_LABELSunlesswith_effort_levelsset others, with a check on the current one, and choosing a level sets it on theModelPickerState, which reportsModelPickerEvent::EffortChanged. - Field
- A shadcn-style text field on
gpui_base’s editing engine, in the kindMnames:Inputfor one line,Textareafor many. - File
Entry - A file or a folder in a listing.
- File
Filter - Which files a picker shows. Folders always show, so the user can go through them to the files.
- File
Page - One page of a listing: entries, and where the next page starts.
- File
Picker - A dialog to choose files on a
FilePickerState: an Up button and the path field, a row with the filter and the “Show hidden” switch, a bordered list of the entries, and Cancel and “Open file” in the footer. - File
Picker State - The path text, the listings, the filtered rows, and the selection of a
FilePicker. - Folder
Entry - A folder in a listing.
- Folder
Page - One page of a listing: folders, and where the next page starts.
- Folder
Picker - A dialog to choose a folder on a
FolderPickerState, as in the reference app: an Up button and the path field, a row that chooses the folder shown, a bordered list of its folders, and Cancel and “Use folder” in the footer. - Folder
Picker State - The path text, the listings, and the filtered rows of a
FolderPicker. - Glide
- Lays a pane out at its slot and paints it gliding there from where it was, above the panes at rest and clipped to its parent.
- Glide
State - Where each
Glideof one layout is, by its key. The view that owns the layout keeps one and hands it to every glide. - Icon
- An SVG icon sized on the rem scale and painted with the text color.
- Label
- A shadcn-style form label: shadcn’s
text-sm font-medium leading-nonemoved to the theme’s 13px control text, in the foreground color, with no margin of its own. - Local
Files - The local file system, in one page. It reads on a background task,
counts a symlink to a folder as a folder, and lists in the order of
FileEntrysorting: folders first, then files. - Local
Folders - The local file system, in one page. It reads on a background task, counts a symlink to a folder as a folder, and puts the visible folders first and the hidden ones after, each in alphabetical order without regard to case.
- Memory
Files - A file system held in memory, for fixtures, demos, and tests. It lists
a directory the application named, in the order of
LocalFiles, fails withListError::NotFoundfor any other directory, and makes folders: a new one shows in its parent’s next listing and is an empty directory itself. Clones share the directories. - Memory
Folders - Folders held in memory, for fixtures, demos, and tests. It lists a
directory the application named, visible folders first and hidden ones
after, fails with
ListError::NotFoundfor any other, and makes folders: a new one shows in its parent’s next listing and is an empty directory itself. Clones share the folders. - MenuBar
- A row of menu titles in the window, as a desktop application’s menu bar, for a platform or a layout without the native one.
- Menu
BarMenu - One menu of a
MenuBar: its title and its rows. - Menu
BarState - The menus of a
MenuBarand the one open among them. - Menu
Item - A command in a menu.
- Menu
RowState - The state of a row a custom renderer draws; see
MenuItem::render. - Menu
State - The open menu of a
DropdownMenu, aContextMenu, or a text field. - Menu
Submenu - A row that opens a further menu beside it.
- Model
Entry - A model a
ModelPickeroffers. - Model
Picker - A picker for a model: a trigger pill that shows the chosen one, and a panel with a rail, a search field, and the list of models.
- Model
Picker State - The catalog, the chosen model and its effort, the favorites, the view
the rail shows, the search, and the open panel of a
ModelPicker. - Model
Provider - A maker of models, one mark in the picker’s rail and the models it owns.
- NavButtons
- Back and forward arrows for a
NavStackState. - NavPage
- One mounted view of a
NavStack, handed to the item renderer. - NavStack
- The pages of a
NavStackState, one visible at a time. - NavStack
State - A stack of views, one visible at a time, with the pages popped off it
kept for
forward. - Page
Token - Where the next page of a listing starts. The source makes it and reads it back, so it can hold anything: an offset, a cursor, a continuation token. The picker only stores it and hands it back.
- Path
Style - The rules of a source’s paths: which characters separate the parts, how a root looks, whether names differ by case, and which names are hidden.
- Permission
Menu - A picker for a
PermissionMode: a quiet trigger that shows the selected mode, and a menu of every mode with its description, the selected one checked, under a header with a “Learn more” row. - Permission
Mode - How much an agent may do without asking, as one entry of a
PermissionMenu: an id, a label, a line of description, and an icon. - Permission
State - The modes, the selected one, and the open menu of a
PermissionMenu. - Popover
- A panel of any content that opens under a trigger, as shadcn’s
Popover. - Progress
- A shadcn-style progress bar, or a circular progress indicator, on
gpui_base::Progress. - Radio
- A shadcn-style radio on
gpui_base::Radio: aRadioMarkwith an optional label beside it. - Radio
Group - The container of a set of
Radiovalues: the radio-group role with its orientation (base’sRadioGroupis only that, and an element that tests can find needs the id on the element itself), laid out as a column, or as a row forhorizontal. - Radio
Mark - The round indicator of a radio: a thin grey ring, or while checked a disc of the control accent with a white dot, as macOS paints it. The accent is the one a switch that is on uses. It paints only. A row that is already a button, such as a model in a list, draws it to show which one is on.
- Scroll
Area - A vertical scroll region with the overscroll bounce of a
UIScrollViewand an overlay scrollbar. - Select
- A shadcn-style select on
gpui_base::Select: a trigger that shows the selection and opens a menu of items. - Select
Item - One choice in a
Selectmenu. - Select
Row - The state of a row a custom item renderer draws; see
Select::render_item. - Select
State - The rows, the selection, and the open menu of a
Select. - Sidebar
- The sidebar surface: a header that stays put, content that scrolls, and a footer that stays put.
- Sidebar
Group - A run of rows under an optional label, with an optional action beside the label, and optionally collapsible.
- Sidebar
Layout - A
Sidebarbeside the main content. - Sidebar
Menu Button - A row in the sidebar: an icon, a label, a badge, an action that shows on hover, a selected state, and optionally nested rows it folds.
- Sidebar
Menu Skeleton - A placeholder row while rows load: a
Skeletonwhere the icon goes and one of a stable random width where the label goes, both pulsing in the sidebar’s hover fill. - Sidebar
Menu Sub - Rows nested under a row: indented, with a hairline down their left. Hidden in a sidebar collapsed to icons.
- Sidebar
Separator - A hairline between sections of the sidebar.
- Sidebar
State - Whether the sidebar is open, how wide it is, and how it collapses.
- Sidebar
Trigger - The button that opens and closes a sidebar.
- Skeleton
- A shadcn-style skeleton: a rounded block in the accent fill that pulses while content loads, so a list or a card keeps its shape before its data arrives.
- Slider
- A shadcn-style slider on
gpui_base::Slider: a rounded track, a filled range from the start to the thumb, and a round thumb. - Slider
State - State of the
Slider. - Source
Path - A path in a source’s own style: what a picker lists, what it asks a source for, and what it reports as chosen.
- Spinner
- A shadcn-style spinner: an arc turning in place, for work whose length
is not known. Use a circular
Progressfor a known percentage; this is that ring with no value. - Status
Option - One choice of a
StatusSelect: an id from the domain, a label, and optionally a leading icon, a line of description in a menu, and a short muted word at the right of a search list row, such as “current” or “remote”. - Status
Select - An item of a
ComposerStatusTabthat opens aSelect: a small ghost trigger with an icon, the chosen option’s label, and a chevron, over the select’s menu with a check on the chosen option. A list ofSEARCH_MIN_OPTIONSoptions or more has the select’s search field, which ranks what is typed fuzzily. - Status
Select State - The options of a status item and the chosen one.
- Switch
- A shadcn-style switch on
gpui_base::Switch: a pill track with a round thumb that slides to the right when checked. - Tab
- One tab in the strip. The id is the application’s key for the tab and must be unique in the strip; it never comes from a list index.
- Tabs
- A browser-style tab strip on
gpui_base::Tabsandgpui_base::Tab. - Tabs
State - The tabs, which one is selected, and the scroll position of the strip.
- Tag
- A small pill with a label and an optional icon, for a status or a
category. gpui-kit’s
Tag, drawn as shadcn’s badge. - Theme
Mode Picker - A choice of
ThemeModeongpui_base::RadioGroup: three cards, each a small picture of the appearance it stands for, with the chosen one ringed and its label in the foreground color. - Title
Bar - A title bar the application draws itself.
- Tooltip
- A short text tooltip, the content a trigger builds for the overlay.
- Tooltip
Host - The per-window registry of tooltip overlays.
- Tooltip
Trigger - The trigger side of a managed tooltip, for a component that owns its own hover listener (GPUI allows one per element).
Enums§
- Attachment
Kind - What kind of file an attachment is, which decides its icon.
- Attachment
Status - Where an attachment is in its life.
- Avatar
Size - The diameter of an
Avatar. - Button
Size - The size tier of a
Button. Height, text size, icon size, and padding change together. Heights are given at the default 16px rem and scale with the theme’s UI font size. - Button
Variant - The visual treatment of a
Button, by meaning. - Command
Entry - One entry of a palette.
- Command
Event - What a
CommandStatereports. - Composer
Event - What a
ComposerStatereports. - Create
Folder Error - Why a source could not make a folder. The picker shows the message under the row that names the folder, and keeps the row editable.
- File
Kind - What an entry of a listing is.
- File
Picker Event - What a
FilePickerStatereports. - Folder
Picker Event - What a
FolderPickerStatereports. - Icon
Source - Where an icon’s SVG comes from.
- Input
Event - List
Error - Why a source could not list a directory. The picker shows the message and, for a failure that waiting can fix, an action: Retry for a lost connection or an error, and “Sign in” for a source that needs the user to log in, which calls the application’s own handler.
- Menu
Anchor - What a menu opens from.
- Menu
Entry - One row of a menu.
- Menu
Event - What a
MenuStatereports. - Model
Picker Event - What a
ModelPickerStatereports. - Model
View - What the list of a
ModelPickershows: the favorites, or one provider’s models. A query overrides both and searches every provider. - More
State - Where the request for the next page of a listing stands.
- NavMotion
- Whether one change runs the
NavStack’s transition, as UIKit’sanimated:and Qt’sStackView.Immediatedecide per call. - NavOperation
- What a running transition is doing, in Qt’s terms.
- NavStack
Event - Emitted by
NavStackStateafter the stack changed. - Permission
Event - What a
PermissionStatereports. - Permission
Tone - How a permission mode reads: an ordinary choice, or a risky one that shows in the warning color.
- Select
Entry - A row of a select menu.
- Select
Event - What a
SelectStatereports. - Sidebar
Collapsible - What closing the sidebar does.
- Sidebar
Event - Emitted by
SidebarStateafter it changed. - Sidebar
Menu Size - The size tier of a
SidebarMenuButton. - Sidebar
Side - Which edge of the content the sidebar is on.
- Slider
Event - Events emitted by the
SliderState. - Slider
Value - The value of the slider, can be a single value or a range of values.
- Status
Select Event - What a
StatusSelectStatereports. - Tabs
Event - Emitted by
TabsStateafter it changed. - TagVariant
- The color of a
Tag, after gpui-kit’s tag variants.
Constants§
- EFFORT_
LABELS - The names of the six default effort levels, from the lowest to the highest.
- SEARCH_
MIN_ OPTIONS - How many options make a
StatusSelectsearchable when it is not told either way: three. A list of two, such as a device, is a plain menu; a list of three or more, such as projects and branches, has a search field and ranks what is typed.
Traits§
- File
Source - Where a
FilePickerlists entries from: the local disk, an SSH session, a bucket, an API. The picker never waits for a source. It callslistand awaits the task, and it drops the task to cancel it. - Folder
Source - Where a
FolderPickerlists folders from: the local disk, an SSH session, a bucket, an API. The picker never waits for a source. It callslistand awaits the task, and it drops the task to cancel it. - NavStack
Ext - Navigation that also frees pages.
- Select
Value - The value of a
SelectItem: the item’s identity in the menu. - Tooltip
Ext - Gives a stateful element a managed tooltip.
Functions§
- init
- Initializes gpui-cn. Call it once, after
gpui_base::init(normally throughgpui_kit::init) and before opening windows.
Type Aliases§
- Command
Search Handler - A search the application runs itself: given the query, it returns the
commands to show, when it has them. See
CommandState::with_search_handler. - File
Listing - What a
FilePickerStateknows about one directory. - File
Loaded - The files of a directory loaded so far, and whether more follow.
- Input
- A single-line text field on an
InputState. - Input
State - State for a single-line text input.
- Listing
- What a
FolderPickerStateknows about one directory. - Loaded
- The folders of a directory loaded so far, and whether more follow.
- Search
Handler - A search the application runs itself: given the query, it returns the
rows to show, when it has them. See
SelectState::with_search_handler. - Textarea
- A multi-line text field on a
TextareaState. - Textarea
State - State for editing ordinary multi-line text.