108 Commits

Author SHA1 Message Date
Floyd Wang
f939cf8215 switch: Add color option for custom checked background (#2178)
## Summary

Add `color(impl Into<Hsla>)` builder method to `Switch`, allowing
callers to customize the background color when the switch is checked.
Defaults to `theme.primary` to preserve existing behavior.

```rust
Switch::new("id")
    .checked(true)
    .color(cx.theme().success)  // green

Switch::new("id")
    .checked(true)
    .color(cx.theme().danger)   // red
```

## Preview
<img width="676" height="104" alt="image"
src="https://github.com/user-attachments/assets/b1422295-e463-4075-b2f2-475c71ef7ac9"
/>

## Changes

- `crates/ui/src/switch.rs`: Add `color` field and builder method
- `crates/story/src/stories/switch_story.rs`: Add "Custom Color" section
- `docs/docs/components/switch.md`: Document `color` method

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 13:56:28 +08:00
Floyd Wang
08b75a2c88 select: Add menu_max_h option (#2175)
## Summary

Add `menu_max_h(impl Into<Length>)` builder method to `Select`, allowing
callers to customize the dropdown menu's max height. Defaults to
`rems(20.)` to preserve existing behavior.

```rust
Select::new(&state).menu_max_h(rems(10.))
Select::new(&state).menu_max_h(px(300.))
```

## Changes

- `crates/ui/src/select.rs`: Add `menu_max_h` field to `SelectOptions`
and builder method
- `crates/story/src/stories/select_story.rs`: Add "Custom Menu Max
Height" section
- `docs/docs/components/select.md`: Document `menu_max_h` under Custom
Appearance

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 11:04:31 +00:00
Floyd Wang
311c7e0d10 setting: Add icon support (#2169)
| Before | After |
| - | - |
| <img width="1055" height="725" alt="Before"
src="https://github.com/user-attachments/assets/df016ac0-bdbe-446a-9b60-a38c29414140"
/> | <img width="1055" height="726" alt="After"
src="https://github.com/user-attachments/assets/db8389bd-26cb-4fb4-a464-aa194ed78772"
/> |
2026-03-19 03:52:15 +00:00
Floyd Wang
accce64cd1 context_menu: Ensure id uniqueness (#2166)
## Breaking Change
`ContextMenu` must be bound to elements that implement
`InteractiveElement` to avoid duplicate ID issues.

```diff
- div().context_menu()
+ div().id("foo").context_menu()
```

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 09:36:53 +00:00
Jason Lee
10165079b9 docs: Update to recommend to depends on git version. (#2148) 2026-03-13 02:44:50 +00:00
Jason Lee
bc31c867c4 docs: Update run app to avoid use anyhow. (#2126)
Closes #2124
2026-03-08 03:46:07 +00:00
mengh04
25befeecc2 docs: Fix code block syntax in settings.md (#2122)
## Before

<img width="1760" height="8020" alt="before"
src="https://github.com/user-attachments/assets/7d31377a-c91c-4baf-92cf-3814562895ed"
/>

## After
<img width="1602" height="7815" alt="after"
src="https://github.com/user-attachments/assets/6f5b736d-cc64-4524-8de5-b9a997f402be"
/>
2026-03-05 16:18:15 +08:00
Jason Lee
1614d3e144 web: Update to support web with WASM. (#2102)
Ref https://github.com/zed-industries/zed/pull/50228

## Summary
- Refactored to share Gallery component between native and web versions
- Fixed WASM compatibility issues with async/threading
- Added web version of the story gallery

## Show case

https://huacnlee.github.io/gpui-component-story-web/

## Key Changes

### 1. Shared Gallery Component
- Extracted Gallery to `crates/story/src/gallery.rs`
- Removed duplicate code (~570 lines) from `main.rs` and
`story-web/lib.rs`
- Both native and web versions now use the same Gallery implementation

### 2. WASM Async Architecture Improvements
**Problem:** WASM main thread cannot use blocking synchronization
primitives (`Mutex`, `RwLock`) that rely on `Atomics.wait`.

**Solution:** Redesigned the async architecture to avoid cross-thread
locks:
- Changed from `Arc<Mutex<ParsedContent>>` to direct storage in
`TextViewState`
- Backend tasks now use pure message-passing instead of shared locks
- All state updates happen on the main thread

**New workflow:**
1. User updates text → Send `UpdateOptions` to background task
2. Background task → Receives copy of current `ParsedContent`, parses
text, returns new `ParsedContent`
3. Main thread → Receives result, directly replaces `parsed_content`
4. Rendering → Reads `parsed_content`, no locks needed

### 3. Cross-platform Time APIs
- Replaced `std::time` with `instant` crate for cross-platform
compatibility
- Updated 11 files to use `instant::{Duration, Instant}`
- Fixed tracing-subscriber initialization for WASM (`.without_time()`)

## Technical Details

### Files Modified
- `crates/story/src/gallery.rs` - **New** shared Gallery module
- `crates/story/src/main.rs` - Simplified to use shared Gallery
- `crates/story-web/src/lib.rs` - Simplified to use shared Gallery (326
lines → 26 lines)
- `crates/ui/src/text/state.rs` - WASM async architecture improvements
- `crates/ui/src/async_util.rs` - Cross-platform async utilities
- `crates/ui/Cargo.toml` - Added `instant` and `parking_lot`
dependencies

### Key Architecture Changes
```rust
// Before: Shared mutable state with locks (blocked on WASM)
pub struct TextViewState {
    parsed_content: Arc<Mutex<ParsedContent>>,
}

// After: Direct storage with message-passing (WASM-compatible)
pub struct TextViewState {
    parsed_content: ParsedContent,
}
```

## Test Plan
- ✅ Native version compiles and runs
- ✅ WASM version builds successfully
- ✅ All components render correctly in both versions
- ✅ No "Atomics.wait cannot be called in this context" errors

## Benefits
- **Reduced code duplication**: Removed ~570 lines of duplicate code
- **Single source of truth**: Gallery updates only need to happen in one
place
- **WASM compatibility**: Proper async architecture that works on
single-threaded WASM
- **Cross-platform**: Native and Web use identical code paths

## TODO

- [ ] `gpui_web` not have implement the `set_menus`, app menu missing.
- [ ] `tree-sitter` can't compiled for wasm, disabled to without
highlight.
- [ ] Input can't handle any type events.
- [ ] Embed font for CJK.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-02 13:12:24 +00:00
RivTian
a4fa68aeeb docs: Fix functional usage in accordion.md example code (#2104)
## Before

According to the documentation, a compilation error occurred in version
0.5.1.

<img width="1974" height="652" alt="7c89ce4919f1360e3299cd630a2e397d"
src="https://github.com/user-attachments/assets/279b20c7-c434-4dc2-89c3-a2510185bf41"
/>

## After 

Fix functional usage in accordion.md example code

<img width="1678" height="750" alt="image"
src="https://github.com/user-attachments/assets/6c39ba02-3a80-4b35-96d8-f1d465aee34a"
/>
2026-03-02 13:51:08 +08:00
Jason Lee
010e1a97b5 table: Renamed Table to DataTable, added new Table element. (#2075)
## The new `Table` element

<img width="1369" height="1096" alt="image"
src="https://github.com/user-attachments/assets/2695cf1c-b08d-4e07-9a2d-a334c8de0538"
/>
2026-02-24 18:30:06 +08:00
Jason Lee
6ea87a9185 alert_dialog: Add AlertDialog. (#2069)
<img width="1417" height="909" alt="image"
src="https://github.com/user-attachments/assets/b371e700-1a65-432a-bab0-1b965bb57e40"
/>

## Breaking Changes

- The `confirm`, `alert` method has been removed from `Dialog`, please
use `AlertDialog` instead default has `ok` button, and `confirm` mode
exist in `AlertDialog` .

```diff
- window.open_dialog(cx, move |dialog, _, _| {
+ window.open_alert_dialog(cx, move |dialog, _, _| {
    dialog
-        .alert()
})
```

```diff
- window.open_dialog(cx, move |dialog, _, _| {
+ window.open_alert_dialog(cx, move |dialog, _, _| {
    dialog.confirm()
})
```


- The `footer` method has been removed from `Dialog`, use `AlertDialog`
if you wants use `ok`, `cancel` button, otherwice use `DialogFooter`.

```diff
window.open_dialog(cx, move |dialog, _, _| {
    dialog
-        .footer(|_, _, window, cx| {
+        .child(DialogFooter::new().children(
            vec![
                Button::new("cancel").label("Cancel"),
                Button::new("ok").label("Ok"),
            ]
-        })
+       ))
})
```

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-24 11:52:48 +08:00
Jason Lee
e5f5e7ae95 dialog: Improve declarative API for Dialog. (#2067)
## Summary

This PR improves the Dialog component's declarative API with trigger
support and a builder pattern for content.

<img width="1103" height="776" alt="image"
src="https://github.com/user-attachments/assets/4115ffc8-0490-464b-8823-b9d8dd3b616f"
/>

<img width="1103" height="776" alt="image"
src="https://github.com/user-attachments/assets/761f4144-8fc3-4c38-8391-0e1b303b7ff5"
/>

## Changes

- **Trigger API**: Add `trigger()` method to enable declarative dialog
opening with a trigger element
- **Content Builder**: Change `content()` to accept a builder function
instead of a pre-built `DialogContent`, allowing more flexible content
construction
- **DialogProps**: Extract dialog properties (width, margins, overlay
settings, etc.) into a `DialogProps` struct for better organization
- **Styling Improvements**: 
  - Add proper border radius to dialog content, header, and footer
  - Improve spacing and padding consistency
  - Update gap values for better visual hierarchy
- **Story Updates**: Update dialog story examples to demonstrate the new
trigger and builder pattern APIs

## Breaking Changes

- `Dialog::new()` now takes only `cx` parameter (removed `window`
parameter)
- The paddings of the Dialog changed from `24px` to `16px`.
- Default Dialog width changed from `480px` to `448px`.

## Example Usage

```rust
Dialog::new(cx)
    .trigger(Button::new("open-dialog").label("Open Dialog"))
    .content(|content, _, cx| {
        content
            .child(DialogHeader::new()
                .child(DialogTitle::new().child("Title"))
                .child(DialogDescription::new().child("Description")))
            .child(DialogFooter::new()
                .child(Button::new("ok").label("OK")))
    })
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-23 09:06:29 +00:00
Jason Lee
33476d0c27 chore: Upgrade GPUI with splitted gpui_platform crate. (#2054)
https://github.com/zed-industries/zed/pull/49277

## Breaking Changes

- Removed `PixelsExt` trait, the methods are already in GPUI.
2026-02-21 17:19:59 +08:00
Jason Lee
f13115baaa theme: Ensure apply rounded none when radius is zero. (#2033) 2026-02-14 06:20:01 +00:00
Floyd Wang
545c348826 table: Add ClearSelection event (#2032)
Closes #2019.
2026-02-14 10:14:09 +08:00
Jason Lee
9fb4473977 docs: Add comprehensive cell selection documentation for Table (#2009)
## Summary

Add comprehensive documentation for the new Table cell selection
feature, covering both code-level API documentation and user-facing
documentation.

## Changes

### Code Documentation

- **TableState**: Add extensive documentation explaining the three
selection modes (row, column, cell) with examples
- **cell_selectable**: Document the field and method with detailed
explanations of behavior and usage examples
- **selected_cell() / set_selected_cell()**: Add method documentation
with return value details and examples
- **TableEvent**: Document all cell-related events (SelectCell,
DoubleClickedCell, RightClickedCell) with use cases
- **Table struct**: Add feature overview highlighting cell selection
capabilities
- **Column::selectable**: Document how it affects both column and cell
selection modes

### User Documentation (docs/docs/components/table.md)

Added comprehensive sections:

1. **Key Features** - Overview of all major table capabilities
2. **Selection Modes** - Detailed explanation of row/column/cell
selection with code examples
3. **Cell Selection** - Complete guide including:
   - Configuration and event subscription
- Feature list (click to select, row selector column, keyboard
navigation, etc.)
   - Programmatic selection (get/set/clear methods)
   - Non-selectable columns for action columns
   - Custom rendering based on selection state
4. **Keyboard Shortcuts** - Separate sections for row and cell selection
modes
5. **API Reference** - Complete reference with:
   - Core types (Table, TableState, TableDelegate, Column, TableEvent)
   - All methods for TableState and Column
   - All event types with descriptions
   - Links to docs.rs for detailed API documentation

## Test Plan

- [x] Documentation follows existing patterns (button.md, accordion.md)
- [x] All code examples are syntactically correct
- [x] Links to docs.rs are properly formatted
- [x] Keyboard shortcuts are accurate and complete
- [x] API reference matches actual implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-10 16:11:15 +08:00
Andreas Johansson
e45280129e editor: Add show_whitespaces to option whether to show spaces and tabs (#1979)
## Description

This adds `.show_whitespace` and `.set_show_whitespace` to the
`InputState` to control whether or not to render spaces and tabs.

I've also updated all the themes with the new `editor.invisible` color,
this is the `comment` color with added opacity.

## Screenshot

<img width="823" height="661" alt="Screenshot From 2026-01-29 14-04-52"
src="https://github.com/user-attachments/assets/2f79f081-83bd-47ea-922c-01b9f22262cf"
/>

<img width="795" height="118" alt="Screenshot From 2026-01-29 14-05-14"
src="https://github.com/user-attachments/assets/b8e22080-a88e-44b7-abd8-4c8100b1a972"
/>

## How to Test

`cargo run --release --example editor`

Click on the "Show whitespace" button in the footer.

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [x] Tested macOS, ~~Windows~~ and Linux platforms performance (if the
change is platform-specific)

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-31 02:56:55 +00:00
Jason Lee
2a3c297d76 focus_trap: Add to support focus_trap. (#1977)
https://github.com/user-attachments/assets/fc0b992e-4b7b-4315-98de-df21a42029f7
2026-01-28 03:15:46 +00:00
fhluo
a93725f2d9 docs: Fix description list example (#1949)
Fix `DescriptionList` example to use the correct `item` method.
2026-01-16 09:44:16 +08:00
Floyd Wang
bc5745c5af sidebar: Add context menu support (#1934)
This pull request enhances the sidebar and context menu functionality
with improved right-click context menu support and better event
handling.

- Added context menu support to `SidebarMenuItem`.
- Enhanced popover overlay dismiss behavior to handle both left and
right mouse clicks.

## Preview
<img width="381" height="285" alt="image"
src="https://github.com/user-attachments/assets/f0f61465-2fcc-4f1e-9160-5af7af0884b3"
/>
2026-01-14 07:46:53 +00:00
Jason Lee
b86b3c753b hover_card: Add HoverCard component. (#1931)
https://github.com/user-attachments/assets/c3019ba5-a982-45ca-b1e4-8897b325f708
2026-01-14 03:38:44 +00:00
Floyd Wang
5a4026a567 sidebar: Add virtual list support (#1927)
This PR adds **virtual list support** to the `Sidebar` component,
significantly improving performance when rendering large numbers of menu
items. The implementation uses GPUI's `ListState` for virtualized
rendering, ensuring smooth scrolling even with hundreds of sidebar
items.

Additionally, this update refactors the `Sidebar` API to use a more
flexible builder pattern and introduces a new `SidebarItem` trait that
enables better composition of sidebar elements including `SidebarMenu`,
`SidebarMenuItem`, and `SidebarGroup`.

## Breaking changes
- An `id` is required when creating a `Sidebar`.
```diff
- Sidebar::new()
+ Sidebar::new("sidebar1")
``` 

- Removed the left and right methods; use side instead.
> Default is left.
```diff
- Sidebar::right()
+ Sidebar::new("sidebar1").side(Side::Right)
```

- Use the builder pattern for the `suffix` of `SidebarMenuItem`.
```diff
- this.suffix(IconName::Settings2)
+ this.suffix(|_, _| Icon::new(IconName::Settings2))
```
2026-01-14 03:15:03 +00:00
Jason Lee
19aa045325 popover: Add center anchor support for Popover. (#1929)
Closes #1688

<img width="1124" height="884" alt="image"
src="https://github.com/user-attachments/assets/176c77c7-38c0-4e4d-b9d3-651a04b5a5a5"
/>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-13 11:24:21 +00:00
Jason Lee
fef2f050eb docs: Add GPUI Skills. (#1923) 2026-01-12 22:31:40 +08:00
Jason Lee
2af1007a6d progress: Add ProgressCircle. (#1918)
## Break Changes

- Renamed `bg` method to `color` for Progress.

<img width="1174" height="987" alt="image"
src="https://github.com/user-attachments/assets/cc6066a7-42f8-4e2a-b47f-a39de768a5e9"
/>
2026-01-12 15:08:03 +08:00