Commit Graph

60 Commits

Author SHA1 Message Date
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
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
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
Jason Lee
4f882a1b98 docs: Little adjust logo border and radius. (#1635) 2025-11-18 14:57:31 +08:00
Jason Lee
f8a7dd71bf dropdown_button: Add more button option methods to DropdownButton. (#1633)
- Fix to not handle `dropdown_menu` when Button is disabled.
- Split a single DropdownButtonStory.
2025-11-18 14:31:14 +08:00
Jason Lee
672a80dcd8 docs: Remove index page warrning. 2025-11-17 10:22:01 +08:00
Andreas Johansson
0e8b8761a4 docs: Fix theme_name type (#1614) 2025-11-17 09:56:24 +08:00
Jason Lee
7de69d1dd1 assets: Move assets files into crates/assets folder for crate publish. (#1609) 2025-11-14 19:00:29 +08:00
Jason Lee
ec3eda60e0 docs: Fix button gap. (#1608) 2025-11-14 18:46:23 +08:00
Jason Lee
2a98628b5e docs: Improve docs to use variable version from toml. (#1603) 2025-11-14 16:10:48 +08:00
Jason Lee
37d1678b6f assets: Add gpui-component-assets crate. (#1601) 2025-11-14 15:03:26 +08:00
Jason Lee
993f9b20ae example: Follow up #1594 missed changes. (#1595) 2025-11-14 11:22:55 +08:00
Jason Lee
a176408d81 Revert "root: Render overlays inside Root element by default. (#1570)" (#1584)
Revert #1573, #1570
2025-11-13 13:37:05 +08:00
Jason Lee
cbd4346b87 root: Impl Styled for Root. (#1573) 2025-11-12 17:57:15 +08:00
Jason Lee
f26f01909e root: Render overlays inside Root element by default. (#1570)
## Break Change

- The `Root::render_notification_layer`, `Root::render_sheet_layer`,
`Root::render_dialog_layer` has been removed, we don't need it now, the
Root element has default rendered them.
2025-11-12 08:04:54 +00:00
Jason Lee
f88b547b70 Bump v0.4.0-preview2 2025-11-12 15:16:49 +08:00
Jason Lee
214d3f6622 notification: Add &mut Self to content and action method. (#1569) 2025-11-12 15:10:42 +08:00
Jason Lee
3cd94ea0be popover: Fix click trigger to close popover. (#1559) 2025-11-11 21:14:56 +08:00
Jason Lee
2dbfba3490 popover: Improve Popover API. (#1545)
- Add `open`, `on_open_change` method to control open state.
- Add `default_open` method.

## Break Change

This PR to rewrite the API of Popover API to make it easy to use. 

- The `content` method now can receive an element directly.

```diff
- .content(|window, cx| {
-     cx.new(|cx| {
-         PopoverContent::new(window, cx, |_, _| {
-             div().child("This popover content.")
-         })
-     })
- })
+ .content(|state, window, cx| {
+     div().child("This popover content.")
+ })
```

- And you can also just use `child` and `children` to add child
elements.

```rs
Popover::new("my-popover")
    .trigger(Button::new("trigger").label("Open Popover"))
    .child("This popover content.")
```

- Removed `PopoverContent`, and changed `Popover` default paddings to
`p_3`.
2025-11-11 17:45:30 +08:00
Floyd Wang
74f23bfca8 tab: Refactor creation to use builder pattern (#1553)
## Breaking change

```diff
- Tab::new("Account")
+ Tab::new().label("Account")
```

We can currently create a tab item without a label, such as only an
icon.
2025-11-11 10:35:00 +08:00
Nico GrĂ¼ndel
2cba6e8be9 slider: Add option to choose between linear and logarithmic scale (#1543)
Adds the ability to choose between a linear and a logarithmic scale for
the slider. A logarithmic scale is the right and intuitive choice for
many different slider applications. Building this right into the
component has two advantages:
- The user doesn't have to convert at every point where they might use
or update the slider value
- On a logarithmic scale, the distance between steps varies over the
sliders range. This implementation respects that

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
2025-11-10 02:56:09 +00:00
Jason Lee
a2c55dda46 form: Rename FormField to Field. (#1539) 2025-11-07 18:43:01 +08:00
Jason Lee
945db0be56 dialog: Rename Modal to Dialog. (#1538)
## Break Change

- Renamed `Modal` to `Dialog`.

```diff
- window.open_modal(...)
+ window.open_dialog(...)

- window.close_modal(...);
+ window.close_dialog(...);
```

- Renamed `show_close` method to `close_button` in Dialog.
```diff
- .show_close(false)
+ .close_button(true)
```
2025-11-07 17:25:55 +08:00
Jason Lee
89041f9ab8 docs: Update version to v0.4.0-preview1 in docs. (#1534) 2025-11-06 22:35:38 +08:00
Jason Lee
80689264e2 sheet: Rename Drawer to Sheet. (#1527)
## Break Change

- Renamed `Drawer` to `Sheet`, also renamed relative method contains
`drawer` to `sheet`.
- Renamed `ContextModal` to `WindowExt`.

```diff
- use gpui_component::drawer::Drawer
+ use gpui_component::sheet::Sheet

- use gpui_component::ContextModal
+ use gpui_component::WindowExt
```
2025-11-06 07:19:10 +00:00