Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make tab close button square (#4052)
Marshall Bowersb136d21ebf13
diff --git a/crates/ui/src/components/button/button_like.rs b/crates/ui/src/components/button/button_like.rsindex 3e4b478a9a2..018d31dafdb 100644--- a/crates/ui/src/components/button/button_like.rs+++ b/crates/ui/src/components/button/button_like.rs@@ -300,6 +300,7 @@ pub struct ButtonLike {pub(super) selected: bool,pub(super) selected_style: Option<ButtonStyle>,pub(super) width: Option<DefiniteLength>,+ pub(super) height: Option<DefiniteLength>,size: ButtonSize,rounding: Option<ButtonLikeRounding>,tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>,@@ -317,6 +318,7 @@ impl ButtonLike {selected: false,selected_style: None,width: None,+ height: None,size: ButtonSize::Default,rounding: Some(ButtonLikeRounding::All),tooltip: None,@@ -325,6 +327,11 @@ impl ButtonLike {}}+ pub(crate) fn height(mut self, height: DefiniteLength) -> Self {+ self.height = Some(height);+ self+ }+pub(crate) fn rounding(mut self, rounding: impl Into<Option<ButtonLikeRounding>>) -> Self {self.rounding = rounding.into();self@@ -417,7 +424,7 @@ impl RenderOnce for ButtonLike {.id(self.id.clone()).group("").flex_none()- .h(self.size.height())+ .h(self.height.unwrap_or(self.size.height().into())).when_some(self.width, |this, width| this.w(width).justify_center()).when_some(self.rounding, |this, rounding| match rounding {ButtonLikeRounding::All => this.rounded_md(),diff --git a/crates/ui/src/components/button/icon_button.rs b/crates/ui/src/components/button/icon_button.rsindex 7c5313497c7..1e37a872922 100644--- a/crates/ui/src/components/button/icon_button.rs+++ b/crates/ui/src/components/button/icon_button.rs@@ -5,9 +5,17 @@ use crate::{ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, IconName, IconSizuse super::button_icon::ButtonIcon;+/// The shape of an [`IconButton`].+#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]+pub enum IconButtonShape {+ Square,+ Wide,+}+#[derive(IntoElement)]pub struct IconButton {base: ButtonLike,+ shape: IconButtonShape,icon: IconName,icon_size: IconSize,icon_color: Color,@@ -18,6 +26,7 @@ impl IconButton {pub fn new(id: impl Into<ElementId>, icon: IconName) -> Self {Self {base: ButtonLike::new(id),+ shape: IconButtonShape::Wide,icon,icon_size: IconSize::default(),icon_color: Color::Default,@@ -25,6 +34,11 @@ impl IconButton {}}+ pub fn shape(mut self, shape: IconButtonShape) -> Self {+ self.shape = shape;+ self+ }+pub fn icon_size(mut self, icon_size: IconSize) -> Self {self.icon_size = icon_size;self@@ -118,14 +132,21 @@ impl RenderOnce for IconButton {let is_selected = self.base.selected;let selected_style = self.base.selected_style;- self.base.child(- ButtonIcon::new(self.icon)- .disabled(is_disabled)- .selected(is_selected)- .selected_icon(self.selected_icon)- .when_some(selected_style, |this, style| this.selected_style(style))- .size(self.icon_size)- .color(self.icon_color),- )+ self.base+ .map(|this| match self.shape {+ IconButtonShape::Square => this+ .width(self.icon_size.rems().into())+ .height(self.icon_size.rems().into()),+ IconButtonShape::Wide => this,+ })+ .child(+ ButtonIcon::new(self.icon)+ .disabled(is_disabled)+ .selected(is_selected)+ .selected_icon(self.selected_icon)+ .when_some(selected_style, |this, style| this.selected_style(style))+ .size(self.icon_size)+ .color(self.icon_color),+ )}}diff --git a/crates/ui/src/components/stories/tab.rs b/crates/ui/src/components/stories/tab.rsindex bd7b6026209..9c5c694439f 100644--- a/crates/ui/src/components/stories/tab.rs+++ b/crates/ui/src/components/stories/tab.rs@@ -3,7 +3,7 @@ use std::cmp::Ordering;use gpui::Render;use story::Story;-use crate::{prelude::*, TabPosition};+use crate::{prelude::*, IconButtonShape, TabPosition};use crate::{Indicator, Tab};pub struct TabStory;@@ -28,6 +28,7 @@ impl Render for TabStory {Tab::new("tab_1").end_slot(IconButton::new("close_button", IconName::Close)+ .shape(IconButtonShape::Square).icon_color(Color::Muted).size(ButtonSize::None).icon_size(IconSize::XSmall),diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex 1b95671398a..90b27e094b6 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -32,8 +32,8 @@ use std::{use theme::ThemeSettings;use ui::{- prelude::*, right_click_menu, ButtonSize, Color, IconButton, IconName, IconSize, Indicator,- Label, Tab, TabBar, TabPosition, Tooltip,+ prelude::*, right_click_menu, ButtonSize, Color, IconButton, IconButtonShape, IconName,+ IconSize, Indicator, Label, Tab, TabBar, TabPosition, Tooltip,};use ui::{v_stack, ContextMenu};use util::{maybe, truncate_and_remove_front, ResultExt};@@ -1341,6 +1341,7 @@ impl Pane {.start_slot::<Indicator>(indicator).end_slot(IconButton::new("close tab", IconName::Close)+ .shape(IconButtonShape::Square).icon_color(Color::Muted).size(ButtonSize::None).icon_size(IconSize::XSmall)