Rename button-related enums (#3463)

This PR renames the `ButtonStyle2` and `ButtonSize2` enums to
`ButtonStyle` and `ButtonSize`, respectively.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-11-30 12:04:23 -05:00 committed by GitHub
parent b64fe04803
commit 0a8a84f656
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 70 deletions

View file

@ -37,7 +37,7 @@ use gpui::{
}; };
use project::Project; use project::Project;
use theme::ActiveTheme; use theme::ActiveTheme;
use ui::{h_stack, prelude::*, Avatar, Button, ButtonStyle2, IconButton, KeyBinding, Tooltip}; use ui::{h_stack, prelude::*, Avatar, Button, ButtonStyle, IconButton, KeyBinding, Tooltip};
use util::ResultExt; use util::ResultExt;
use workspace::{notifications::NotifyResultExt, Workspace}; use workspace::{notifications::NotifyResultExt, Workspace};
@ -154,7 +154,7 @@ impl Render for CollabTitlebarItem {
.id("project_owner_indicator") .id("project_owner_indicator")
.child( .child(
Button::new("player", "player") Button::new("player", "player")
.style(ButtonStyle2::Subtle) .style(ButtonStyle::Subtle)
.color(Some(Color::Player(0))), .color(Some(Color::Player(0))),
) )
.tooltip(move |cx| Tooltip::text("Toggle following", cx)), .tooltip(move |cx| Tooltip::text("Toggle following", cx)),
@ -167,7 +167,7 @@ impl Render for CollabTitlebarItem {
.id("titlebar_project_menu_button") .id("titlebar_project_menu_button")
.child( .child(
Button::new("project_name", "project_name") Button::new("project_name", "project_name")
.style(ButtonStyle2::Subtle), .style(ButtonStyle::Subtle),
) )
.tooltip(move |cx| Tooltip::text("Recent Projects", cx)), .tooltip(move |cx| Tooltip::text("Recent Projects", cx)),
) )
@ -179,7 +179,7 @@ impl Render for CollabTitlebarItem {
.id("titlebar_git_menu_button") .id("titlebar_git_menu_button")
.child( .child(
Button::new("branch_name", "branch_name") Button::new("branch_name", "branch_name")
.style(ButtonStyle2::Subtle) .style(ButtonStyle::Subtle)
.color(Some(Color::Muted)), .color(Some(Color::Muted)),
) )
.tooltip(move |cx| { .tooltip(move |cx| {

View file

@ -4,7 +4,7 @@ use gpui::{actions, Action, AppContext, IntoElement};
pub use mode::SearchMode; pub use mode::SearchMode;
use project::search::SearchQuery; use project::search::SearchQuery;
use ui::prelude::*; use ui::prelude::*;
use ui::{ButtonStyle2, Icon, IconButton}; use ui::{ButtonStyle, Icon, IconButton};
//pub use project_search::{ProjectSearchBar, ProjectSearchView}; //pub use project_search::{ProjectSearchBar, ProjectSearchView};
// use theme::components::{ // use theme::components::{
// action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle, // action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle,
@ -91,8 +91,8 @@ impl SearchOptions {
cx.dispatch_action(action.boxed_clone()); cx.dispatch_action(action.boxed_clone());
} }
}) })
.style(ButtonStyle2::Subtle) .style(ButtonStyle::Subtle)
.when(active, |button| button.style(ButtonStyle2::Filled)) .when(active, |button| button.style(ButtonStyle::Filled))
} }
} }
@ -103,8 +103,8 @@ fn toggle_replace_button(active: bool) -> impl IntoElement {
cx.dispatch_action(Box::new(ToggleReplace)); cx.dispatch_action(Box::new(ToggleReplace));
cx.notify(); cx.notify();
}) })
.style(ButtonStyle2::Subtle) .style(ButtonStyle::Subtle)
.when(active, |button| button.style(ButtonStyle2::Filled)) .when(active, |button| button.style(ButtonStyle::Filled))
} }
fn render_replace_button( fn render_replace_button(

View file

@ -1,7 +1,7 @@
use gpui::AnyView; use gpui::AnyView;
use crate::prelude::*; use crate::prelude::*;
use crate::{ButtonCommon, ButtonLike, ButtonSize2, ButtonStyle2, Label, LineHeightStyle}; use crate::{ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Label, LineHeightStyle};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct Button { pub struct Button {
@ -54,12 +54,12 @@ impl ButtonCommon for Button {
self.base.id() self.base.id()
} }
fn style(mut self, style: ButtonStyle2) -> Self { fn style(mut self, style: ButtonStyle) -> Self {
self.base = self.base.style(style); self.base = self.base.style(style);
self self
} }
fn size(mut self, size: ButtonSize2) -> Self { fn size(mut self, size: ButtonSize) -> Self {
self.base = self.base.size(size); self.base = self.base.size(size);
self self
} }

View file

@ -1,4 +1,4 @@
use gpui::{rems, AnyElement, AnyView, ClickEvent, Div, Hsla, Rems, Stateful}; use gpui::{rems, transparent_black, AnyElement, AnyView, ClickEvent, Div, Hsla, Rems, Stateful};
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::h_stack; use crate::h_stack;
@ -6,13 +6,13 @@ use crate::prelude::*;
pub trait ButtonCommon: Clickable + Disableable { pub trait ButtonCommon: Clickable + Disableable {
fn id(&self) -> &ElementId; fn id(&self) -> &ElementId;
fn style(self, style: ButtonStyle2) -> Self; fn style(self, style: ButtonStyle) -> Self;
fn size(self, size: ButtonSize2) -> Self; fn size(self, size: ButtonSize) -> Self;
fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self; fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self;
} }
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub enum ButtonStyle2 { pub enum ButtonStyle {
#[default] #[default]
Filled, Filled,
// Tinted, // Tinted,
@ -21,54 +21,57 @@ pub enum ButtonStyle2 {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ButtonStyle { pub(crate) struct ButtonLikeStyles {
pub background: Hsla, pub background: Hsla,
#[allow(unused)]
pub border_color: Hsla, pub border_color: Hsla,
#[allow(unused)]
pub label_color: Hsla, pub label_color: Hsla,
#[allow(unused)]
pub icon_color: Hsla, pub icon_color: Hsla,
} }
impl ButtonStyle2 { impl ButtonStyle {
pub fn enabled(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn enabled(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_background, background: cx.theme().colors().element_background,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_background, background: cx.theme().colors().ghost_element_background,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
} }
} }
pub fn hovered(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn hovered(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_hover, background: cx.theme().colors().element_hover,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_hover, background: cx.theme().colors().ghost_element_hover,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
// TODO: These are not great // TODO: These are not great
label_color: Color::Muted.color(cx), label_color: Color::Muted.color(cx),
// TODO: These are not great // TODO: These are not great
@ -77,23 +80,23 @@ impl ButtonStyle2 {
} }
} }
pub fn active(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn active(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_active, background: cx.theme().colors().element_active,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_active, background: cx.theme().colors().ghost_element_active,
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
// TODO: These are not great // TODO: These are not great
label_color: Color::Muted.color(cx), label_color: Color::Muted.color(cx),
// TODO: These are not great // TODO: These are not great
@ -102,22 +105,23 @@ impl ButtonStyle2 {
} }
} }
pub fn focused(self, cx: &mut WindowContext) -> ButtonStyle { #[allow(unused)]
pub(crate) fn focused(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_background, background: cx.theme().colors().element_background,
border_color: cx.theme().colors().border_focused, border_color: cx.theme().colors().border_focused,
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_background, background: cx.theme().colors().ghost_element_background,
border_color: cx.theme().colors().border_focused, border_color: cx.theme().colors().border_focused,
label_color: Color::Default.color(cx), label_color: Color::Default.color(cx),
icon_color: Color::Default.color(cx), icon_color: Color::Default.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: cx.theme().colors().border_focused, border_color: cx.theme().colors().border_focused,
label_color: Color::Accent.color(cx), label_color: Color::Accent.color(cx),
icon_color: Color::Accent.color(cx), icon_color: Color::Accent.color(cx),
@ -125,23 +129,23 @@ impl ButtonStyle2 {
} }
} }
pub fn disabled(self, cx: &mut WindowContext) -> ButtonStyle { pub(crate) fn disabled(self, cx: &mut WindowContext) -> ButtonLikeStyles {
match self { match self {
ButtonStyle2::Filled => ButtonStyle { ButtonStyle::Filled => ButtonLikeStyles {
background: cx.theme().colors().element_disabled, background: cx.theme().colors().element_disabled,
border_color: cx.theme().colors().border_disabled, border_color: cx.theme().colors().border_disabled,
label_color: Color::Disabled.color(cx), label_color: Color::Disabled.color(cx),
icon_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx),
}, },
ButtonStyle2::Subtle => ButtonStyle { ButtonStyle::Subtle => ButtonLikeStyles {
background: cx.theme().colors().ghost_element_disabled, background: cx.theme().colors().ghost_element_disabled,
border_color: cx.theme().colors().border_disabled, border_color: cx.theme().colors().border_disabled,
label_color: Color::Disabled.color(cx), label_color: Color::Disabled.color(cx),
icon_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx),
}, },
ButtonStyle2::Transparent => ButtonStyle { ButtonStyle::Transparent => ButtonLikeStyles {
background: gpui::transparent_black(), background: transparent_black(),
border_color: gpui::transparent_black(), border_color: transparent_black(),
label_color: Color::Disabled.color(cx), label_color: Color::Disabled.color(cx),
icon_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx),
}, },
@ -150,19 +154,19 @@ impl ButtonStyle2 {
} }
#[derive(Default, PartialEq, Clone, Copy)] #[derive(Default, PartialEq, Clone, Copy)]
pub enum ButtonSize2 { pub enum ButtonSize {
#[default] #[default]
Default, Default,
Compact, Compact,
None, None,
} }
impl ButtonSize2 { impl ButtonSize {
fn height(self) -> Rems { fn height(self) -> Rems {
match self { match self {
ButtonSize2::Default => rems(22. / 16.), ButtonSize::Default => rems(22. / 16.),
ButtonSize2::Compact => rems(18. / 16.), ButtonSize::Compact => rems(18. / 16.),
ButtonSize2::None => rems(16. / 16.), ButtonSize::None => rems(16. / 16.),
} }
} }
} }
@ -170,10 +174,10 @@ impl ButtonSize2 {
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct ButtonLike { pub struct ButtonLike {
id: ElementId, id: ElementId,
pub(super) style: ButtonStyle2, pub(super) style: ButtonStyle,
pub(super) disabled: bool, pub(super) disabled: bool,
pub(super) selected: bool, pub(super) selected: bool,
size: ButtonSize2, size: ButtonSize,
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>, tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>,
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>, on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
children: SmallVec<[AnyElement; 2]>, children: SmallVec<[AnyElement; 2]>,
@ -183,10 +187,10 @@ impl ButtonLike {
pub fn new(id: impl Into<ElementId>) -> Self { pub fn new(id: impl Into<ElementId>) -> Self {
Self { Self {
id: id.into(), id: id.into(),
style: ButtonStyle2::default(), style: ButtonStyle::default(),
disabled: false, disabled: false,
selected: false, selected: false,
size: ButtonSize2::Default, size: ButtonSize::Default,
tooltip: None, tooltip: None,
children: SmallVec::new(), children: SmallVec::new(),
on_click: None, on_click: None,
@ -220,12 +224,12 @@ impl ButtonCommon for ButtonLike {
&self.id &self.id
} }
fn style(mut self, style: ButtonStyle2) -> Self { fn style(mut self, style: ButtonStyle) -> Self {
self.style = style; self.style = style;
self self
} }
fn size(mut self, size: ButtonSize2) -> Self { fn size(mut self, size: ButtonSize) -> Self {
self.size = size; self.size = size;
self self
} }

View file

@ -1,7 +1,7 @@
use gpui::{Action, AnyView}; use gpui::{Action, AnyView};
use crate::prelude::*; use crate::prelude::*;
use crate::{ButtonCommon, ButtonLike, ButtonSize2, ButtonStyle2, Icon, IconElement, IconSize}; use crate::{ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconElement, IconSize};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct IconButton { pub struct IconButton {
@ -65,12 +65,12 @@ impl ButtonCommon for IconButton {
self.base.id() self.base.id()
} }
fn style(mut self, style: ButtonStyle2) -> Self { fn style(mut self, style: ButtonStyle) -> Self {
self.base = self.base.style(style); self.base = self.base.style(style);
self self
} }
fn size(mut self, size: ButtonSize2) -> Self { fn size(mut self, size: ButtonSize) -> Self {
self.base = self.base.size(size); self.base = self.base.size(size);
self self
} }

View file

@ -2,7 +2,7 @@ use gpui::{Div, Render};
use story::Story; use story::Story;
use crate::prelude::*; use crate::prelude::*;
use crate::{Button, ButtonStyle2}; use crate::{Button, ButtonStyle};
pub struct ButtonStory; pub struct ButtonStory;
@ -15,8 +15,8 @@ impl Render for ButtonStory {
.child(Story::label("Default")) .child(Story::label("Default"))
.child(Button::new("default_filled", "Click me")) .child(Button::new("default_filled", "Click me"))
.child(Story::label("Default (Subtle)")) .child(Story::label("Default (Subtle)"))
.child(Button::new("default_subtle", "Click me").style(ButtonStyle2::Subtle)) .child(Button::new("default_subtle", "Click me").style(ButtonStyle::Subtle))
.child(Story::label("Default (Transparent)")) .child(Story::label("Default (Transparent)"))
.child(Button::new("default_transparent", "Click me").style(ButtonStyle2::Transparent)) .child(Button::new("default_transparent", "Click me").style(ButtonStyle::Transparent))
} }
} }