mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-03 22:13:21 +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:
1 parent
a623dc3d1a
commit
4e8937b62d
64 files changed
+584
-847
No files matched your search
@@ -1592,8 +1592,11 @@ fn render_send_review_to_agent_button(review_count: usize, focus_handle: &FocusH
|
||||
"send-review",
|
||||
format!("Send Review to Agent ({})", review_count),
|
||||
)
|
||||
.icon(IconName::ZedAssistant)
|
||||
.icon_position(IconPosition::Start)
|
||||
.start_icon(
|
||||
Icon::new(IconName::ZedAssistant)
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Muted),
|
||||
)
|
||||
.tooltip(Tooltip::for_action_title_in(
|
||||
"Send all review comments to the Agent panel",
|
||||
&SendReviewToAgent,
|
||||
@@ -1686,10 +1689,11 @@ impl Render for BranchDiffToolbar {
|
||||
let focus_handle = focus_handle.clone();
|
||||
this.child(Divider::vertical()).child(
|
||||
Button::new("review-diff", "Review Diff")
|
||||
.icon(IconName::ZedAssistant)
|
||||
.icon_position(IconPosition::Start)
|
||||
.icon_size(IconSize::Small)
|
||||
.icon_color(Color::Muted)
|
||||
.start_icon(
|
||||
Icon::new(IconName::ZedAssistant)
|
||||
.size(IconSize::Small)
|
||||
.color(Color::Muted),
|
||||
)
|
||||
.key_binding(KeyBinding::for_action_in(&ReviewDiff, &focus_handle, cx))
|
||||
.tooltip(move |_, cx| {
|
||||
Tooltip::with_meta_in(
|
||||
|
||||
Reference in new issue
Block a user