Commit graph

1268 commits

Author SHA1 Message Date
Floyd Wang
e2f022cb59
divider: Add support for dashed divider (#1730)
## Description

1. Add support for dashed divider.
2. Add divider story.

## Screenshot

<img width="1139" height="859" alt="SCR-20251203-nueg"
src="https://github.com/user-attachments/assets/3f2dafd9-f808-4315-bf58-c0380798eb66"
/>
2025-12-03 16:22:36 +08:00
Floyd Wang
e43662190a Bump v0.5.0-preview2 2025-12-02 17:12:49 +08:00
Jason Lee
8abaa82233
list: Fix list item may overflow. (#1726)
Closes #1692
2025-12-02 13:33:47 +08:00
Jason Lee
64aa975c77
title_bar: Remove window control bg color in normal mode. (#1720)
Fix #1710 introduced bug.
2025-12-01 13:56:15 +00:00
Jason Lee
43e1029b9f
dock: Improve Panel trait changed title to return impl IntoElement. (#1719) 2025-12-01 18:13:23 +08:00
Jason Lee
d92e3a3222
dock: Fix title method missed thing in PR #1716 (#1718)
Continue #1716
2025-12-01 18:03:29 +08:00
Jason Lee
4ded78ed30
dock: Refactor Panel trait to has &mut self and &mut Context<Self>. (#1716)
Continue #1712, #1713

## Description

Also change the `Panel` trait to has `&mut self` and `&mut
Context<Self>`.

## Break Changes

The methods `title`, `title_prefix`, `set_zoomed`, `set_active`,
`dropdown_menu`, `toolbar_buttons`, `on_added_to`, `on_removed` has
changed `&self` to `&mut self`, and `cx: &App` to `cx: &mut
Context<Self>`.

```diff
- fn title(&self, window: &Window, cx: &App) -> AnyElement
+ fn title(&mut self, window: &Window, cx: &mut Context<Self>) -> AnyElement
```
2025-12-01 17:57:18 +08:00
Jason Lee
c0f801dd8c
list: Refactor ListDelegate to easy access delegate. (#1713)
Continue #1712

## Break Changes

- The argument type of `render_item`, `render_section_header`,
`render_section_footer`, `render_empty`, `render_initial`,
`render_loading` in `ListDelegate` has been changed to has `&mut self`
and `&mut Context<ListState<Self>>`.

```diff
- fn render_item(&self, ix: IndexPath, window: &mut Window, cx: &mut App) -> Option<Self::Item>
+ fn render_item(&mut self, ix: IndexPath, window: &mut Window, cx: &mut Context<ListState<Self>>) -> Option<Self::Item>
```
2025-12-01 17:42:44 +08:00
Jason Lee
001b1795f1
table: Refactor TableDelegate to easy to access delegate. (#1712)
Closes #1610, #1583

Closes https://github.com/longbridge/gpui-component/discussions/1707

## Description

This change to improve the `TableDelegate` to have `&mut self` and
`Context<TableState<Self>>` to easy access delegate.

## Break Changes

- The argument types of `render_tr`, `render_td`, `render_th`,
`context_menu`, `render_loading`, `render_empty`,
`render_last_empty_col` in `TableDelegate` has been changed.

```diff
- fn render_th(&self, col_ix: usize, _: &mut Window, _: &mut App) -> impl IntoElement
+ fn render_th(&mut self, col_ix: usize, _: &mut Window, _: &mut Context<TableState<Self>>) -> impl IntoElement
```
2025-12-01 17:20:52 +08:00
Andreas Johansson
0126f1b036
input: Fix wrong font being used in Input. (#1706)
Closes #1665

## Description

When `Input::new().font_family("font")` is used, the font hasn't been
applied yet in `Input::render`, therefore the `text_wrapper` will
calculate using the wrong font. This is why it's working when the font
is added to the parent element.

The fix moves the state update to `element` prepaint, where
`window.text_style()` has the correct styles. The only downside is that
there are now one additional state update.

## Screenshot

| Before                       | After                       |
| ---------------------------- | --------------------------- |
| <img width="1125" height="246" alt="Screenshot From 2025-11-30
20-03-11"
src="https://github.com/user-attachments/assets/1fa798a7-0b9c-4386-8940-ad5f6734b8a0"
/> | <img width="1125" height="246" alt="Screenshot From 2025-11-30
20-00-23"
src="https://github.com/user-attachments/assets/e970e7bc-1bfa-4a55-a342-3381d1684526"
/> |

## How to Test

Use some wide font, like `IBM Plex Mono`. Apply it to
`Input::new(&some_state).font_family("IBM Plex Mono")` where the input
state has `soft_wrap`. Here is a diff for `textarea_story.rs`.

```diff
diff --git a/crates/story/src/textarea_story.rs b/crates/story/src/textarea_story.rs
index f2c63d44..bd5cbb31 100644
--- a/crates/story/src/textarea_story.rs
+++ b/crates/story/src/textarea_story.rs
@@ -77,9 +77,9 @@ impl TextareaStory {
 
         let textarea_no_wrap = cx.new(|cx| {
             InputState::new(window, cx)
-                .multi_line(true)
                 .rows(6)
-                .soft_wrap(false)
+                .multi_line(true)
+                .soft_wrap(true)
                 .default_value("This is a very long line of text to test if the horizontal scrolling function is working properly, and it should not wrap automatically but display a horizontal scrollbar.\nThe second line is also very long text, used to test the horizontal scrolling effect under multiple lines, and you can input more content to test.\nThe third line: Here you can input other long text content that requires horizontal scrolling.\n")
         });
 
@@ -195,7 +185,7 @@ impl Render for TextareaStory {
             .child(
                 section("Auto Grow")
                     .max_w_md()
-                    .child(Input::new(&self.textarea_auto_grow)),
+                    .child(Input::new(&self.textarea_auto_grow).font_family("IBM Plex Mono")),
             )
             .child(
                 section("Auto Grow with No Wrap")
```


## 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.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-12-01 09:05:34 +00:00
Jason Lee
0f655314c9
title_bar: Fix TitleBar drag area on macOS, and only handle show window menu when it supports. (#1710)
Closes #1528

- Fix the TitleBar drag area on macOS.
- Update Window Control Icon to use theme color.
2025-12-01 16:07:18 +08:00
Jason Lee
4e0f9af789
story: Use uniform_list for scroll example. (#1709)
Ref #1621

Update scrollable story to use `UniformList` to avoid performance issue
in story.

And also renamed it to `ScrollbarStory`.
2025-12-01 11:07:29 +08:00
FlyingYu
a792719dbe
editor: Fix cursor direction not resetting after mouse up (#1708)
## Description

This PR fixes an issue where the editor's "reverse cursor" state was not
reset
after completing a text selection. Because the flag remained `true`, the
cursor
could appear on the wrong side of the selection when the next
interaction
started.

## Screenshot

| Before | After |
|--------|--------|
| <video
src="https://github.com/user-attachments/assets/308c5119-52da-4bdb-9a94-36617d957c63"
controls width="360"></video> | <video
src="https://github.com/user-attachments/assets/bf9328b4-96d8-48df-9cc0-99fccaced7c5"
controls width="360"></video> |

## How to Test

`cargo run --example editor`

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [ ] 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.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)
2025-12-01 11:06:40 +08:00
Andreas Johansson
7e479aa7f2
input: Add to support CodeEditor as single line mode. (#1696)
## Screenshot

From `input_story`:

<img width="1069" height="122" alt="Screenshot From 2025-11-28 09-14-03"
src="https://github.com/user-attachments/assets/f14ef2fc-4939-4ceb-be3e-bede492f8602"
/>

## Breaking Changes

- `.multi_line()` was changed to `.multi_line(bool)`.  
- Removed pub `InputMode`, this should only for internal.

```diff
InputState::new(window, cx)
-    .multi_line()
+    .multi_line(true)
```

## 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.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)

Use cases,

1) In my API client, I have a tree sitter language for the URL input,

<img width="1001" height="162" alt="Image"
src="https://github.com/user-attachments/assets/9771decf-b0b7-4230-8ed6-784a95b72af1"
/>

2) In my SQL editor I want to be able to allow JSON syntax highlighting
for inline editing of json columns,

<img width="501" height="130" alt="Image"
src="https://github.com/user-attachments/assets/f0f879cc-841f-49d2-a23a-2effc3747f38"
/>

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-28 19:51:40 +08:00
Jason Lee
1ce09cc1d1
sidebar: Fix Sidebar group and items gap. (#1705) 2025-11-28 09:56:39 +00:00
Jason Lee
df9655e80a
input: Adjust blink cursor height. (#1704) 2025-11-28 09:54:48 +00:00
Jason Lee
6505be409b
input: Change to input text size to smaller. (#1703)
Use `text_sm` for text size for Input.

Ref https://ui.shadcn.com/docs/components/input

## Screenshot

## Before

<img width="1143" height="1034" alt="image"
src="https://github.com/user-attachments/assets/17a8731e-9977-4beb-89d0-e2460f3823fd"
/>

## After

<img width="1218" height="974" alt="image"
src="https://github.com/user-attachments/assets/cca684d0-c86b-440f-bd30-cff7a4f444c4"
/>
2025-11-28 09:37:43 +00:00
Jason Lee
04abdbe771
theme: Fix some dropdown to use popover for bg, and improve macos-cla… (#1702)
<img width="1136" height="859" alt="image"
src="https://github.com/user-attachments/assets/16764390-2089-43b9-bb96-77912263f07e"
/>

<img width="1136" height="859" alt="image"
src="https://github.com/user-attachments/assets/c2cb7e4f-76d6-458e-8ff9-2734d4944008"
/>
2025-11-28 08:57:13 +00:00
Floyd Wang
d7ff792cf4
dock: Use visible_panels method (#1698)
Improve #1697.
2025-11-28 03:18:09 +00:00
Floyd Wang
37326819af
dock: Render title bar based on visible panels (#1697)
Display the title when only one panel is visible.

## Breaking change
```diff
pub enum PanelStyle {
-   Default,
+   #[default]
+   Auto,
    TabBar,
}

- dock_area.panel_style(PanelStyle::Default)
+ dock_area.panel_style(PanelStyle::Auto)
```
2025-11-28 03:01:31 +00:00
Jason Lee
36b229068d
chore: Fix dialog scroll by #1694 change. (#1695) 2025-11-27 21:11:20 +08:00
Jason Lee
118a0f500e
scrollbar: Introduce overflow_scrollbar to adds Scrollbars to elements. (#1694)
## Description

1. Add `overflow_scrollbar`, `overflow_y_scrollbar`, `overflow_x_scroll`
to GPUI elements to let them has scrollbars. It is almost like the
`overscroll` but adds the Scrollbar.
2. And adjust the display scrollbar of margining 4px of the container.
3. Add `scrollbar`, `vertical_scrollbar`, `horizontal_scrollbar` with
your own scroll handle.

<img width="1181" height="911" alt="image"
src="https://github.com/user-attachments/assets/8b02cd54-d527-4f22-b9be-f762ede22122"
/>

## Break Changes

- There `Scrollable` trait and it `scrollable` method has been removed.

```diff
- div().id("contents").scrollable(Axis::Vertical)
+ div().id("contents").overflow_y_scrollbar()
```
2025-11-27 11:29:50 +00:00
Jason Lee
e38f784219
title_bar: Improve Styled support to TitleBar. (#1693) 2025-11-27 16:25:36 +08:00
Jason Lee
740d59d280 Bump v0.5.0-preview0 2025-11-27 14:49:36 +08:00
Jason Lee
4a3f520c5f
scrollbar: Manage ScrollbarState in Scrollbar internal. (#1690)
This PR to improve the Scrollbar API to manage the state in the
internal.

## Break Changes

Describe any breaking changes introduced by this pull request. If none,
remove this section.

- Removed `scrollbar_state` argument from `Scrollbar::new`,
`Scrollbar::both`, `Scrollbar::vertical` and `Scrollbar::horizontal`.

```diff
- Scrollbar::horizontal(&self.scrollbar_state, &self.scroll_handle)
+ Scrollbar::horizontal(&self.scroll_handle)

- Scrollbar::vertical(&self.scrollbar_state, &self.scroll_handle)
+ Scrollbar::vertical(&self.scroll_handle)
```

- Change `struct ScrollbarState` to private, we not need this not.

```diff
- pub struct ScrollbarState {
+ struct ScrollbarState {
```

- Renamed `trait ScrollHandleOffsetable` to `trait ScrollbarHanle`.

```diff
- pub trait ScrollHandleOffsetable {
+ pub trait ScrollbarHanle {
```

- Removed `Scrollbar::both`, now use `Scrollbar::new` instead.

```diff
- Scrollbar::both(&scroll_handle)
+ Scrollbar::new(&scroll_handle)
```
2025-11-27 11:39:58 +08:00
Floyd Wang
0d167f61e5
plot: Add support for stacked chart (#1681)
## Description

- Add `stack` shape.
- Add `ordinal` scale.
- Add plot docs.

<img width="337" height="424" alt="SCR-20251126-puzm"
src="https://github.com/user-attachments/assets/eff9e2d0-c13a-449a-b717-9568e0c2f88d"
/>

## Breaking change
The bar shape `y0` value is now returned for each data item.

```diff
- Bar::new().y0(height)
+ Bar::new().y0(move |_| height)
+ Bar::new().y0(move |d| d.height)
```
2025-11-26 10:24:57 +00:00
Jason Lee
55da14edb2
theme: Use difference color like the window background for TitleBar. (#1686) 2025-11-26 11:54:28 +08:00
han
e5fa0709d1
theme: Add switch.thumb.background theme config support (#1685)
## Description:
This PR adds support for customizing the Switch component's thumb color.

- Changes:
•  Added switch_thumb field to ThemeColor and ThemeConfig.
•  Updated Switch component to use cx.theme().switch_thumb.
• Config key: switch.thumb.background (falls back to background color if
not set).

Co-authored-by: hl <hl@nmcsoft.com>
2025-11-26 10:25:35 +08:00
Floyd Wang
9d02133977
color_picker: Only change value when it's confirmed (#1682) 2025-11-25 10:05:43 +00:00
Jason Lee
e70d072b88
menu: Add check_side to PopupMenu to support display check at right side. (#1677)
<img width="507" height="511" alt="image"
src="https://github.com/user-attachments/assets/2d89381a-2acb-49d8-be69-8cb6ab211f41"
/>
2025-11-25 15:30:36 +08:00
Jason Lee
5672c6065f
chore: Split some feature into geometry.rs (#1676) 2025-11-25 02:07:31 +00:00
Jason Lee
dae5fcd8aa
editor: Improve scroll to support position at the edge of the editor on click. (#1672)
But if we use `Up`, `Down` to move the cursor, it still will keep 3
lines.

https://github.com/user-attachments/assets/4310a4cc-3829-4190-9be9-e7159c688884
2025-11-24 09:37:59 +00:00
Jason Lee
8144085077
input: Fix scroll to offset to support soft wrap mode. (#1671)
Close #1655

https://github.com/user-attachments/assets/ea7032d0-d15a-4127-9b0b-b035e2c835fe
2025-11-24 09:14:39 +00:00
Jason Lee
f2cbc16655
chore: Update to use Rust edition 2024. (#1669) 2025-11-24 14:38:43 +08:00
Jason Lee
fc36451a27
setting: Add scrollbar to SettingPage. (#1660) 2025-11-21 23:04:56 +08:00
Jason Lee
857f7973e3
scrollbar: Remove Scrollbar::uniform_scroll, use Scrollbar::vertical instead. (#1659)
## Break Change

- Remove `Scrollbar::uniform_scroll`, use `Scrollbar::vertical` instead.

```diff
- Scrollbar::uniform_scroll(&scroll_state, &scroll_handle)
+ Scrollbar::vertical(&scroll_state, &scroll_handle)
```
2025-11-21 22:53:33 +08:00
Jason Lee
c523b3485b
sidebar: Refactor Sidebar to support Styled. (#1658)
## Break Change

- The `width`, `border_width` method has been removed from Sidebar, use
`Styled` trait to use `w`, `border` method from GPUI instead.

```diff
Sidebar::left()
-   .width(relative(1.))
-   .border_width(px(0.))
+   .w(relative(1.))
+   .border_0()
    .collapsed(false)
```
2025-11-21 22:44:35 +08:00
Jason Lee
44829a05e4
setting: Add SettingFieldElement trait. (#1657)
Co-authored-by: Sunli <scott_s829@163.com>
2025-11-21 10:48:29 +00:00
Andreas Johansson
ffeeee5d12
docs: Fix minor docs issues (#1656)
Fixes #1643 by removing invalid docs
2025-11-21 17:34:30 +08:00
obito
c91d806057
tab: Allow tab item to fill remaining space. (#1654)
<img width="2766" height="1818" alt="image"
src="https://github.com/user-attachments/assets/f5c275f7-1165-4a0d-a24d-d35cefb64e2d"
/>
2025-11-21 11:49:30 +08:00
Floyd Wang
41d2b9808b
color_picker: Add radius on focus border (#1652)
| Before | After |
| - | - |
| <img width="143" height="51" alt="SCR-20251121-jwmj"
src="https://github.com/user-attachments/assets/69693a83-dbf8-44ea-b46e-bd88c3c2f1f3"
/> | <img width="135" height="45" alt="SCR-20251121-jvol"
src="https://github.com/user-attachments/assets/177a90fc-8400-4df7-9ee2-3b4f32633c4b"
/> |
2025-11-21 02:53:14 +00:00
Andreas Johansson
b6bf2d8c5e
menu: Use defer to avoid race conditions with click listeners (#1651)
When using `.context_menu` on a parent element, the
`window.on_mouse_event` would fire before, for example, the tables
`on_mouse_down` so it'd be like this:
1. First right click = no context menu, right_clicked_row is set
2. Second right click = context menu, but with the row from the first
click

Before: (Look at `Selected row`)  


https://github.com/user-attachments/assets/5eb89a00-f1ce-4423-b8d7-3ec61b848b83

After:


https://github.com/user-attachments/assets/10033ca4-4c2c-47b5-ace5-6ba745fcfee5

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-21 02:27:21 +00:00
Jason Lee
c8652f9010
setting: Add Settings component. (#1632)
https://github.com/user-attachments/assets/3c6315d9-1183-419c-bb17-a8f7ac0cf25c
2025-11-20 13:51:44 +00:00
Jason Lee
0a24925a7f Bump v0.4.1 2025-11-20 17:26:14 +08:00
Floyd Wang
d55125149b
list: Fix incorrect selected item background color (#1648)
It will mix `accent` and `list_active` before.
2025-11-20 16:46:57 +08:00
grubby
d251a9b08b
icon: Rework icons to make use of the IconNamed trait (#1640)
This makes use of the `IconNamed` trait and a blanked implementation to
convert anything that implements this to an `Icon`.

This allows for easily defined custom versions of `IconName`, while
minimally changing existing code (essentially only if you previously
made use of the `.path()` method on the `IconName` enum; this now
requires an import of the `IconNamed` trait).

# Example
```rust
use gpui_component::IconNamed;

pub enum IconName {
    Encounters,
    Monsters,
    Spells,
}

impl IconNamed for IconName {
    fn path(self) -> gpui::SharedString {
        match self {
            IconName::Encounters => "icons/encounters.svg",
            IconName::Monsters => "icons/monsters.svg",
            IconName::Spells => "icons/spells.svg",
        }
        .into()
    }
}

// this allows for the following interactions (works with anything that has the `.icon(icon)` method
Button::new("my-button").icon(IconName::Spells);
Icon::new(IconName::Monsters); 
```

If you want to directly "render" a custom `IconName` you must implement
the `RenderOnce` trait and derive `IntoElement` on the `IconName`.

```rust
use gpui::{IntoElement, RenderOnce};
use gpui_component::IconNamed;

#[derive(IntoElement)]
pub enum IconName {
    // The same as before
}

impl IconNamed for IconName {
    // The same as before
}

impl RenderOnce for IconName {
    fn render(self, _: &mut gpui::Window, _: &mut gpui::App) -> impl gpui::IntoElement {
        gpui_component::Icon::empty().path(self.path())
    }
}

// this allows for the following interaction
div()
    .child(IconName::Monsters)
```

Overall I think is an improvement to the existing way to do custom
`IconName` implementations.

I am unsure if this change should also be reflected in the documentation
on the section with "Icons & Assets", though I personally think it would
make sense to highlight this way to do custom versions of `IconName` as
it is considerably less involved than the current approach.

Closes #1627.

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-20 02:30:08 +00:00
Adriano Tumino
2e3387a76f
sidebar: Add to support disable state to sidebar item. (#1645)
Hello,
I added a disabled flag to turn off the SidebarmenuItem

<img width="735" height="528" alt="image"
src="https://github.com/user-attachments/assets/47f60476-004c-4fe5-9baf-519d16b93f93"
/>

---------

Co-authored-by: TUMINOA <adriano.tumino@leonardocompany.com>
Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-20 02:16:41 +00:00
Jason Lee
96c34a9fb0
sidebar: Improve Sidebar to allows caret icon to expand submenu. (#1642)
https://github.com/user-attachments/assets/7cd4ef52-e633-4db4-bdba-2912bba2120d
2025-11-19 05:39:24 +00:00
obito
9d11418bd1
select: Add render prop to customize item title display. (#1638)
Fixes #1410

## Problem

The `display_title` prop was overriding the default way dropdown option
titles are displayed, causing incorrect rendering of option titles.

**Expected behavior:**
<img width="716" height="944" alt="Expected dropdown display"
src="https://github.com/user-attachments/assets/38926731-32dd-4a16-9d08-7f2eed2c99a4"
/>

**Actual behavior:**
<img width="580" height="974" alt="image"
src="https://github.com/user-attachments/assets/d96b935a-ce4d-462c-a9ce-4995f5c8eeb5"
/>

## Solution

- Revert the `display_title` change that was causing the issue
- Add a `render` function to allow custom rendering of option titles
instead

This approach provides more flexibility for customizing option display
while preserving the default behavior.

cc @stippi
2025-11-18 20:30:37 +08:00
Jason Lee
01082f11d2
button: Add dropdown_caret option to show a caret icon to end of button. (#1637)
<img width="658" height="162" alt="image"
src="https://github.com/user-attachments/assets/7c233982-04c3-408c-8ae4-f672f8b135a3"
/>
2025-11-18 16:41:16 +08:00