From e75c37a1acaa9ec641789ba0a9a0694992206fa3 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 30 Oct 2025 15:19:39 +0800 Subject: [PATCH] chore: Update List, Tree, Kbd exports. (#1467) ## Break Change - Removed `Kbd` from root export, use `gpui_component::kbd::Kbd` instead. - Removed `List` from root export, use `gpui_component::list::*` instead. - Removed `Tree` from root export, use `gpui_component::tree:*` instead. --- crates/story/examples/editor.rs | 6 +- crates/story/src/kbd_story.rs | 2 +- crates/story/src/tree_story.rs | 9 ++- crates/story/src/virtual_list_story.rs | 8 +-- crates/ui/src/lib.rs | 20 +++--- crates/ui/src/list/list.rs | 6 +- crates/ui/src/menu/popup_menu.rs | 2 +- crates/ui/src/tooltip.rs | 2 +- crates/ui/src/tree.rs | 5 +- docs/docs/components/kbd.md | 28 +------- docs/docs/components/list.md | 67 ------------------- docs/docs/components/table.md | 92 -------------------------- docs/docs/components/tree.md | 2 +- docs/docs/components/virtual-list.md | 44 ------------ 14 files changed, 33 insertions(+), 260 deletions(-) diff --git a/crates/story/examples/editor.rs b/crates/story/examples/editor.rs index afa40a44..4139f747 100644 --- a/crates/story/examples/editor.rs +++ b/crates/story/examples/editor.rs @@ -10,7 +10,7 @@ use std::{ use autocorrect::ignorer::Ignorer; use gpui::{prelude::FluentBuilder, *}; use gpui_component::{ - ActiveTheme, ContextModal, IconName, ListItem, Sizable, TreeItem, TreeState, + ActiveTheme, ContextModal, IconName, Sizable, button::{Button, ButtonVariants as _}, h_flex, highlighter::{Diagnostic, DiagnosticSeverity, Language, LanguageConfig, LanguageRegistry}, @@ -18,8 +18,10 @@ use gpui_component::{ self, CodeActionProvider, CompletionProvider, DefinitionProvider, DocumentColorProvider, HoverProvider, Input, InputEvent, InputState, Position, Rope, RopeExt, TabSize, }, + list::ListItem, resizable::{h_resizable, resizable_panel}, - tree, v_flex, + tree::{TreeItem, TreeState, tree}, + v_flex, }; use lsp_types::{ CodeAction, CodeActionKind, CompletionContext, CompletionItem, CompletionResponse, diff --git a/crates/story/src/kbd_story.rs b/crates/story/src/kbd_story.rs index b185eda2..9d2fad1b 100644 --- a/crates/story/src/kbd_story.rs +++ b/crates/story/src/kbd_story.rs @@ -3,7 +3,7 @@ use gpui::{ Styled, Window, }; -use gpui_component::{h_flex, v_flex, Kbd}; +use gpui_component::{h_flex, kbd::Kbd, v_flex}; use crate::section; diff --git a/crates/story/src/tree_story.rs b/crates/story/src/tree_story.rs index 85e65123..05dc91b7 100644 --- a/crates/story/src/tree_story.rs +++ b/crates/story/src/tree_story.rs @@ -7,8 +7,13 @@ use gpui::{ }; use gpui_component::{ - ActiveTheme as _, IconName, ListItem, StyledExt as _, TreeItem, TreeState, dock::PanelControl, - h_flex, label::Label, tree, v_flex, + ActiveTheme as _, IconName, StyledExt as _, + dock::PanelControl, + h_flex, + label::Label, + list::ListItem, + tree::{TreeItem, TreeState, tree}, + v_flex, }; use crate::{Story, section}; diff --git a/crates/story/src/virtual_list_story.rs b/crates/story/src/virtual_list_story.rs index f49a44f1..ddf97b11 100644 --- a/crates/story/src/virtual_list_story.rs +++ b/crates/story/src/virtual_list_story.rs @@ -1,16 +1,16 @@ use std::{ops::Range, rc::Rc}; use gpui::{ - div, px, size, App, AppContext, Context, Div, Entity, FocusHandle, Focusable, - InteractiveElement, IntoElement, ParentElement, Pixels, Render, ScrollStrategy, Size, Styled, - Window, + App, AppContext, Context, Div, Entity, FocusHandle, Focusable, InteractiveElement, IntoElement, + ParentElement, Pixels, Render, ScrollStrategy, Size, Styled, Window, div, px, size, }; use gpui_component::{ + ActiveTheme as _, Selectable, Sizable, VirtualListScrollHandle, button::{Button, ButtonGroup}, divider::Divider, h_flex, scroll::{Scrollbar, ScrollbarAxis, ScrollbarState}, - v_flex, v_virtual_list, ActiveTheme as _, Selectable, Sizable, VirtualListScrollHandle, + v_flex, v_virtual_list, }; pub struct VirtualListStory { diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 7fe0cda2..1a1bde95 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -1,15 +1,16 @@ +use gpui::{App, SharedString}; +use std::ops::Deref; + mod event; mod global_state; mod icon; mod index_path; #[cfg(any(feature = "inspector", debug_assertions))] mod inspector; -mod kbd; mod root; mod styled; mod time; mod title_bar; -mod tree; mod virtual_list; mod window_border; @@ -36,6 +37,7 @@ pub mod highlighter; pub mod history; pub mod indicator; pub mod input; +pub mod kbd; pub mod label; pub mod link; pub mod list; @@ -59,36 +61,30 @@ pub mod tag; pub mod text; pub mod theme; pub mod tooltip; +pub mod tree; +pub use time::{calendar, date_picker}; #[cfg(feature = "webview")] pub mod webview; -use gpui::{App, SharedString}; // re-export #[cfg(feature = "webview")] pub use wry; pub use crate::Disableable; pub use event::InteractiveElementExt; +pub use icon::*; pub use index_path::IndexPath; pub use input::{Rope, RopeExt, RopeLines}; #[cfg(any(feature = "inspector", debug_assertions))] pub use inspector::*; -pub use list::*; pub use root::{ContextModal, Root}; pub use styled::*; -pub use time::*; +pub use theme::*; pub use title_bar::*; -pub use tree::*; pub use virtual_list::{h_virtual_list, v_virtual_list, VirtualList, VirtualListScrollHandle}; pub use window_border::{window_border, window_paddings, WindowBorder}; -pub use icon::*; -pub use kbd::*; -pub use theme::*; - -use std::ops::Deref; - rust_i18n::i18n!("locales", fallback = "en"); /// Initialize the components. diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 8809fbfc..0ff31a73 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -4,15 +4,13 @@ use std::time::Duration; use crate::actions::{Cancel, Confirm, SelectDown, SelectUp}; use crate::input::InputState; use crate::list::cache::{MeasuredEntrySize, RowEntry, RowsCache}; -use crate::list::ListDelegate; use crate::{ input::{Input, InputEvent}, scroll::{Scrollbar, ScrollbarState}, v_flex, ActiveTheme, IconName, Size, }; -use crate::{ - v_virtual_list, Icon, IndexPath, Selectable, Sizable as _, StyledExt, VirtualListScrollHandle, -}; +use crate::{list::ListDelegate, v_virtual_list, VirtualListScrollHandle}; +use crate::{Icon, IndexPath, Selectable, Sizable as _, StyledExt}; use gpui::{ div, prelude::FluentBuilder, AppContext, Entity, FocusHandle, Focusable, InteractiveElement, IntoElement, KeyBinding, Length, MouseButton, ParentElement, Render, Styled, Task, Window, diff --git a/crates/ui/src/menu/popup_menu.rs b/crates/ui/src/menu/popup_menu.rs index 44153726..e0051135 100644 --- a/crates/ui/src/menu/popup_menu.rs +++ b/crates/ui/src/menu/popup_menu.rs @@ -3,7 +3,7 @@ use crate::actions::{SelectLeft, SelectRight}; use crate::menu::menu_item::MenuItemElement; use crate::scroll::{Scrollbar, ScrollbarState}; use crate::{h_flex, v_flex, ActiveTheme, Icon, IconName, Sizable as _}; -use crate::{Kbd, Side, Size, StyledExt}; +use crate::{kbd::Kbd, Side, Size, StyledExt}; use gpui::{ anchored, canvas, div, prelude::FluentBuilder, px, rems, Action, AnyElement, App, AppContext, Bounds, Context, Corner, DismissEvent, Edges, Entity, EventEmitter, FocusHandle, Focusable, diff --git a/crates/ui/src/tooltip.rs b/crates/ui/src/tooltip.rs index 435973a9..765c1312 100644 --- a/crates/ui/src/tooltip.rs +++ b/crates/ui/src/tooltip.rs @@ -3,7 +3,7 @@ use gpui::{ IntoElement, ParentElement, Render, SharedString, StyleRefinement, Styled, Window, }; -use crate::{h_flex, text::Text, ActiveTheme, Kbd, StyledExt}; +use crate::{h_flex, kbd::Kbd, text::Text, ActiveTheme, StyledExt}; enum TooltipContext { Text(Text), diff --git a/crates/ui/src/tree.rs b/crates/ui/src/tree.rs index eef038d0..5ba97d89 100644 --- a/crates/ui/src/tree.rs +++ b/crates/ui/src/tree.rs @@ -9,8 +9,9 @@ use gpui::{ use crate::{ actions::{Confirm, SelectDown, SelectLeft, SelectRight, SelectUp}, + list::ListItem, scroll::{Scrollbar, ScrollbarState}, - ListItem, StyledExt, + StyledExt, }; const CONTEXT: &str = "Tree"; @@ -450,7 +451,7 @@ impl RenderOnce for Tree { mod tests { use indoc::indoc; - use crate::TreeState; + use super::TreeState; use gpui::AppContext as _; fn assert_entries(entries: &Vec, expected: &str) { diff --git a/docs/docs/components/kbd.md b/docs/docs/components/kbd.md index 6fc1233b..2f36e42a 100644 --- a/docs/docs/components/kbd.md +++ b/docs/docs/components/kbd.md @@ -10,7 +10,7 @@ A component for displaying keyboard shortcuts and key combinations with proper p ## Import ```rust -use gpui_component::Kbd; +use gpui_component::kbd::Kbd; use gpui::Keystroke; ``` @@ -130,32 +130,6 @@ The Kbd component automatically formats shortcuts according to platform conventi | `enter` | ⏎ | Enter | | `left` | ← | Left | -## API Reference - -### Kbd - -| Method | Description | -| ----------------------------------------------------- | ------------------------------------------- | -| `new(keystroke)` | Create a new Kbd component from a keystroke | -| `appearance(bool)` | Show/hide visual styling (default: true) | -| `binding_for_action(action, context, window)` | Get keybinding for action in context | -| `binding_for_action_in(action, focus_handle, window)` | Get keybinding for action in focus | -| `format(keystroke)` | Static method to format keystroke as string | - -### Static Methods - -| Method | Description | -| ------------------------- | ---------------------------------------------- | -| `Kbd::format(&keystroke)` | Format a keystroke as platform-specific string | - -### Trait Implementations - -| Trait | Description | -| ----------------- | --------------------------------- | -| `From` | Convert keystroke directly to Kbd | -| `Styled` | Apply styling refinements | -| `IntoElement` | Render as UI element | - ## Examples ### Keyboard Shortcut Help diff --git a/docs/docs/components/list.md b/docs/docs/components/list.md index 2df57ba3..ffb97da7 100644 --- a/docs/docs/components/list.md +++ b/docs/docs/components/list.md @@ -353,73 +353,6 @@ list.update(cx, |list, cx| { }); ``` -## API Reference - -### List - -| Method | Description | -| ------------------------------------------ | ------------------------------- | -| `new(delegate, window, cx)` | Create a new list with delegate | -| `max_h(height)` | Set maximum height | -| `scrollbar_visible(bool)` | Show/hide scrollbar | -| `no_query()` | Remove search input | -| `selectable(bool)` | Enable/disable selection | -| `paddings(edges)` | Set internal padding | -| `set_selected_index(ix, window, cx)` | Set selected item | -| `scroll_to_item(ix, strategy, window, cx)` | Scroll to specific item | -| `scroll_to_selected_item(window, cx)` | Scroll to selected item | - -### ListDelegate - -| Method | Description | -| -------------------------------------------- | ---------------------------------- | -| `sections_count(cx)` | Number of sections (default: 1) | -| `items_count(section, cx)` | Number of items in section | -| `render_item(ix, window, cx)` | Render list item | -| `render_section_header(section, window, cx)` | Render section header | -| `render_section_footer(section, window, cx)` | Render section footer | -| `render_empty(window, cx)` | Render empty state | -| `render_initial(window, cx)` | Render initial state | -| `render_loading(window, cx)` | Render loading state | -| `perform_search(query, window, cx)` | Handle search query | -| `set_selected_index(ix, window, cx)` | Update selection | -| `confirm(secondary, window, cx)` | Handle item confirmation | -| `cancel(window, cx)` | Handle selection cancel | -| `loading(cx)` | Return loading state | -| `is_eof(cx)` | Return if more data available | -| `load_more_threshold()` | Threshold for triggering load more | -| `load_more(window, cx)` | Load more data | - -### ListItem - -| Method | Description | -| -------------------- | --------------------------------- | -| `new(id)` | Create new list item | -| `selected(bool)` | Set selected state | -| `confirmed(bool)` | Set confirmed state (shows check) | -| `disabled(bool)` | Set disabled state | -| `check_icon(icon)` | Set check icon | -| `suffix(fn)` | Add suffix element | -| `on_click(fn)` | Click handler | -| `on_mouse_enter(fn)` | Mouse enter handler | - -### ListEvent - -| Variant | Description | -| -------------------- | ---------------------------------- | -| `Select(IndexPath)` | Item was selected | -| `Confirm(IndexPath)` | Item was confirmed (clicked/Enter) | -| `Cancel` | Selection was cancelled (Escape) | - -### IndexPath - -| Method | Description | -| ------------------ | --------------------- | -| `new(row)` | Create new index path | -| `section(section)` | Set section index | -| `row` | Row index | -| `section` | Section index | - ## Examples ### File Browser List diff --git a/docs/docs/components/table.md b/docs/docs/components/table.md index 06fbbeb1..c89bf63a 100644 --- a/docs/docs/components/table.md +++ b/docs/docs/components/table.md @@ -401,98 +401,6 @@ table.update(cx, |table, cx| { }); ``` -## API Reference - -### Table - -| Method | Description | -| --------------------------- | --------------------------------------------- | -| `new(delegate, window, cx)` | Create a new table with delegate | -| `stripe(bool)` | Enable alternating row colors | -| `border(bool)` | Show table border | -| `loop_selection(bool)` | Enable looping selection with keyboard | -| `col_movable(bool)` | Allow column reordering | -| `col_resizable(bool)` | Allow column resizing | -| `sortable(bool)` | Enable column sorting | -| `row_selectable(bool)` | Allow row selection | -| `col_selectable(bool)` | Allow column selection | -| `col_fixed(bool)` | Enable fixed columns feature | -| `scrollbar_visible(v, h)` | Set scrollbar visibility | -| `set_size(size, cx)` | Set table size (Small, Medium, Large, XSmall) | -| `scroll_to_row(ix, cx)` | Scroll to specific row | -| `scroll_to_col(ix, cx)` | Scroll to specific column | -| `set_selected_row(ix, cx)` | Select specific row | -| `set_selected_col(ix, cx)` | Select specific column | -| `clear_selection(cx)` | Clear all selections | -| `refresh(cx)` | Refresh table after data changes | - -### Column - -| Method | Description | -| -------------------------- | --------------------------------------- | -| `new(key, name)` | Create column with key and display name | -| `width(pixels)` | Set column width | -| `sortable()` | Enable sorting with default order | -| `ascending()` | Set default ascending sort | -| `descending()` | Set default descending sort | -| `text_right()` | Right-align column content | -| `fixed(ColumnFixed::Left)` | Pin column to left side | -| `fixed_left()` | Pin column to left side (shorthand) | -| `resizable(bool)` | Allow column resizing | -| `movable(bool)` | Allow column moving | -| `selectable(bool)` | Allow column selection | -| `paddings(edges)` | Set custom cell padding | -| `p_0()` | Remove cell padding | - -### TableDelegate - -Required methods to implement: - -| Method | Description | -| ---------------------------------------------- | ------------------------ | -| `columns_count(&self, cx)` | Return number of columns | -| `rows_count(&self, cx)` | Return number of rows | -| `column(&self, col_ix, cx)` | Get column definition | -| `render_td(&self, row_ix, col_ix, window, cx)` | Render table cell | - -Optional methods: - -| Method | Description | -| ------------------------------------------------------- | -------------------------------- | -| `render_th(&self, col_ix, window, cx)` | Custom header cell rendering | -| `render_tr(&self, row_ix, window, cx)` | Custom row rendering | -| `render_empty(&self, window, cx)` | Empty state content | -| `render_loading(&self, size, window, cx)` | Loading state content | -| `context_menu(&self, row_ix, menu, window, cx)` | Row context menu | -| `perform_sort(&mut self, col_ix, sort, window, cx)` | Handle column sorting | -| `move_column(&mut self, col_ix, to_ix, window, cx)` | Handle column reordering | -| `load_more(&mut self, window, cx)` | Load more data | -| `loading(&self, cx)` | Return loading state | -| `is_eof(&self, cx)` | Return if no more data | -| `load_more_threshold(&self)` | Rows from bottom to trigger load | -| `visible_rows_changed(&mut self, range, window, cx)` | Visible range changed | -| `visible_columns_changed(&mut self, range, window, cx)` | Visible columns changed | - -### TableEvent - -Events emitted by the table: - -| Event | Description | -| ---------------------------------- | ----------------------- | -| `SelectRow(usize)` | Row selected | -| `DoubleClickedRow(usize)` | Row double-clicked | -| `SelectColumn(usize)` | Column selected | -| `ColumnWidthsChanged(Vec)` | Column widths changed | -| `MoveColumn(usize, usize)` | Column moved (from, to) | - -### ColumnSort - -| Value | Description | -| ------------ | ------------------ | -| `Default` | No sorting applied | -| `Ascending` | Sort ascending | -| `Descending` | Sort descending | - ## Examples ### Financial Data Table diff --git a/docs/docs/components/tree.md b/docs/docs/components/tree.md index c5e92fec..3d19481e 100644 --- a/docs/docs/components/tree.md +++ b/docs/docs/components/tree.md @@ -10,7 +10,7 @@ A versatile tree component for displaying hierarchical data with expand/collapse ## Import ```rust -use gpui_component::{tree, TreeState, TreeItem, TreeEntry}; +use gpui_component::tree::{tree, TreeState, TreeItem, TreeEntry}; ``` ## Usage diff --git a/docs/docs/components/virtual-list.md b/docs/docs/components/virtual-list.md index a3d0307c..5ef7617e 100644 --- a/docs/docs/components/virtual-list.md +++ b/docs/docs/components/virtual-list.md @@ -356,50 +356,6 @@ impl MyView { } ``` -## API Reference - -### Virtual List Functions - -| Function | Description | -| -------------------------------------------- | ------------------------------ | -| `v_virtual_list(view, id, sizes, render_fn)` | Create vertical virtual list | -| `h_virtual_list(view, id, sizes, render_fn)` | Create horizontal virtual list | - -### VirtualList Methods - -| Method | Description | -| -------------------------------- | -------------------------------- | -| `track_scroll(handle)` | Attach scroll handle for control | -| `with_sizing_behavior(behavior)` | Set list sizing behavior | - -### VirtualListScrollHandle - -| Method | Description | -| --------------------------------- | ------------------------- | -| `new()` | Create new scroll handle | -| `scroll_to_item(index, strategy)` | Scroll to specific item | -| `scroll_to_bottom()` | Scroll to the bottom | -| `offset()` | Get current scroll offset | -| `set_offset(point)` | Set scroll position | -| `content_size()` | Get total content size | - -### ScrollStrategy - -| Strategy | Description | -| -------- | -------------------------------- | -| `Top` | Align item to top of viewport | -| `Center` | Center item in viewport | -| `Bottom` | Align item to bottom of viewport | - -### Parameters - -| Parameter | Type | Description | -| ------------ | ----------------------- | -------------------------------- | -| `view` | `Entity` | View entity containing the data | -| `id` | `impl Into` | Unique identifier for the list | -| `item_sizes` | `Rc>>` | Size of each item | -| `render_fn` | Closure | Function to render visible items | - ## Examples ### File Explorer with Virtual Scrolling