Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add `selected_label` to `Button` (#3478)
Marshall Bowers4b23c5c65835
diff --git a/crates/ui2/src/components/button/button.rs b/crates/ui2/src/components/button/button.rsindex ce26ee76a5d..7524a259872 100644--- a/crates/ui2/src/components/button/button.rs+++ b/crates/ui2/src/components/button/button.rs@@ -8,6 +8,7 @@ pub struct Button {base: ButtonLike,label: SharedString,label_color: Option<Color>,+ selected_label: Option<SharedString>,}impl Button {@@ -16,6 +17,7 @@ impl Button {base: ButtonLike::new(id),label: label.into(),label_color: None,+ selected_label: None,}}@@ -23,6 +25,11 @@ impl Button {self.label_color = label_color.into();self}++ pub fn selected_label<L: Into<SharedString>>(mut self, label: impl Into<Option<L>>) -> Self {+ self.selected_label = label.into().map(Into::into);+ self+ }}impl Selectable for Button {@@ -74,6 +81,11 @@ impl RenderOnce for Button {type Rendered = ButtonLike;fn render(self, _cx: &mut WindowContext) -> Self::Rendered {+ let label = self+ .selected_label+ .filter(|_| self.base.selected)+ .unwrap_or(self.label);+let label_color = if self.base.disabled {Color::Disabled} else if self.base.selected {@@ -83,7 +95,7 @@ impl RenderOnce for Button {};self.base.child(- Label::new(self.label)+ Label::new(label).color(label_color).line_height_style(LineHeightStyle::UILabel),)diff --git a/crates/ui2/src/components/stories/button.rs b/crates/ui2/src/components/stories/button.rsindex 17bcd8b2685..1a95aef6005 100644--- a/crates/ui2/src/components/stories/button.rs+++ b/crates/ui2/src/components/stories/button.rs@@ -16,6 +16,12 @@ impl Render for ButtonStory {.child(Button::new("default_filled", "Click me")).child(Story::label("Selected")).child(Button::new("selected_filled", "Click me").selected(true))+ .child(Story::label("Selected with `selected_label`"))+ .child(+ Button::new("selected_label_filled", "Click me")+ .selected(true)+ .selected_label("I have been selected"),+ ).child(Story::label("With `label_color`")).child(Button::new("filled_with_label_color", "Click me").color(Color::Created)).child(Story::label("Default (Subtle)"))