mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-02 21:40:41 +01:00
ui: Refactor the Button component icon methods (#51496)
Previously, if you wanted to have a button that contains icons on both
edges, you'd need to use a `ButtonLike` component, which takes any
children. Meanwhile, the `Button` would only take one icon, where you
could control its position through the `IconPosition` enum. This has
always felt unnecessarily limiting. So, this PR removes this limitation
by adding two new methods to the button: `start_icon` and `end_icon`.
In the meantime, I have also been bothered by the unnecessary
indirection in the `IconButton` due to the existence of the `ButtonIcon`
component. So I figured I could also completely eliminate that by adding
some of its methods directly to the `IconButton` and in the Button, just
using a regular `Icon` component.
---
## Before
```rust
Button::new("id", "Label")
.icon(IconName::Plus)
.icon_position(IconPosition::Start)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
```
## After
```rust
Button::new("id", "Label")
.start_icon(Icon::new(IconName::Check))
.end_icon(Icon::new(IconName::ChevronDown).size(IconSize::XSmall))
```
This should have no visual impact to the UI.
Release Notes:
- N/A
This commit is contained in:
@@ -1494,10 +1494,9 @@ impl GitGraph {
|
||||
|
||||
this.child(
|
||||
Button::new("author-email-copy", author_email.clone())
|
||||
.icon(icon)
|
||||
.icon_size(IconSize::Small)
|
||||
.icon_color(icon_color)
|
||||
.icon_position(IconPosition::Start)
|
||||
.start_icon(
|
||||
Icon::new(icon).size(IconSize::Small).color(icon_color),
|
||||
)
|
||||
.label_size(LabelSize::Small)
|
||||
.truncate(true)
|
||||
.color(Color::Muted)
|
||||
@@ -1542,10 +1541,9 @@ impl GitGraph {
|
||||
};
|
||||
|
||||
Button::new("sha-button", &full_sha)
|
||||
.icon(icon)
|
||||
.icon_size(IconSize::Small)
|
||||
.icon_color(icon_color)
|
||||
.icon_position(IconPosition::Start)
|
||||
.start_icon(
|
||||
Icon::new(icon).size(IconSize::Small).color(icon_color),
|
||||
)
|
||||
.label_size(LabelSize::Small)
|
||||
.truncate(true)
|
||||
.color(Color::Muted)
|
||||
@@ -1602,10 +1600,9 @@ impl GitGraph {
|
||||
"view-on-provider",
|
||||
format!("View on {}", provider_name),
|
||||
)
|
||||
.icon(icon)
|
||||
.icon_size(IconSize::Small)
|
||||
.icon_color(Color::Muted)
|
||||
.icon_position(IconPosition::Start)
|
||||
.start_icon(
|
||||
Icon::new(icon).size(IconSize::Small).color(Color::Muted),
|
||||
)
|
||||
.label_size(LabelSize::Small)
|
||||
.truncate(true)
|
||||
.color(Color::Muted)
|
||||
|
||||
Reference in New Issue
Block a user