use gpui::{ rems, AnyElement, AnyView, ClickEvent, Div, Hsla, IntoElement, Rems, Stateful, StatefulInteractiveElement, WindowContext, }; use smallvec::SmallVec; use crate::{h_stack, prelude::*}; // 🚧 Heavily WIP 🚧 // #[derive(Default, PartialEq, Clone, Copy)] // pub enum ButtonType2 { // #[default] // DefaultButton, // IconButton, // ButtonLike, // SplitButton, // ToggleButton, // } #[derive(Default, PartialEq, Clone, Copy)] pub enum IconPosition2 { #[default] Before, After, } #[derive(Default, PartialEq, Clone, Copy)] pub enum ButtonStyle2 { #[default] Filled, // Tinted, Subtle, Transparent, } #[derive(Debug, Clone, Copy)] pub struct ButtonStyle { pub background: Hsla, pub border_color: Hsla, pub label_color: Hsla, pub icon_color: Hsla, } impl ButtonStyle2 { pub fn enabled(self, cx: &mut WindowContext) -> ButtonStyle { match self { ButtonStyle2::Filled => ButtonStyle { background: cx.theme().colors().element_background, border_color: gpui::transparent_black(), label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Subtle => ButtonStyle { background: cx.theme().colors().ghost_element_background, border_color: gpui::transparent_black(), label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Transparent => ButtonStyle { background: gpui::transparent_black(), border_color: gpui::transparent_black(), label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, } } pub fn hovered(self, cx: &mut WindowContext) -> ButtonStyle { match self { ButtonStyle2::Filled => ButtonStyle { background: cx.theme().colors().element_hover, border_color: gpui::transparent_black(), label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Subtle => ButtonStyle { background: cx.theme().colors().ghost_element_hover, border_color: gpui::transparent_black(), label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Transparent => ButtonStyle { background: gpui::transparent_black(), border_color: gpui::transparent_black(), // TODO: These are not great label_color: Color::Muted.color(cx), // TODO: These are not great icon_color: Color::Muted.color(cx), }, } } pub fn active(self, cx: &mut WindowContext) -> ButtonStyle { match self { ButtonStyle2::Filled => ButtonStyle { background: cx.theme().colors().element_active, border_color: gpui::transparent_black(), label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Subtle => ButtonStyle { background: cx.theme().colors().ghost_element_active, border_color: gpui::transparent_black(), label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Transparent => ButtonStyle { background: gpui::transparent_black(), border_color: gpui::transparent_black(), // TODO: These are not great label_color: Color::Muted.color(cx), // TODO: These are not great icon_color: Color::Muted.color(cx), }, } } pub fn focused(self, cx: &mut WindowContext) -> ButtonStyle { match self { ButtonStyle2::Filled => ButtonStyle { background: cx.theme().colors().element_background, border_color: cx.theme().colors().border_focused, label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Subtle => ButtonStyle { background: cx.theme().colors().ghost_element_background, border_color: cx.theme().colors().border_focused, label_color: Color::Default.color(cx), icon_color: Color::Default.color(cx), }, ButtonStyle2::Transparent => ButtonStyle { background: gpui::transparent_black(), border_color: cx.theme().colors().border_focused, label_color: Color::Accent.color(cx), icon_color: Color::Accent.color(cx), }, } } pub fn disabled(self, cx: &mut WindowContext) -> ButtonStyle { match self { ButtonStyle2::Filled => ButtonStyle { background: cx.theme().colors().element_disabled, border_color: cx.theme().colors().border_disabled, label_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx), }, ButtonStyle2::Subtle => ButtonStyle { background: cx.theme().colors().ghost_element_disabled, border_color: cx.theme().colors().border_disabled, label_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx), }, ButtonStyle2::Transparent => ButtonStyle { background: gpui::transparent_black(), border_color: gpui::transparent_black(), label_color: Color::Disabled.color(cx), icon_color: Color::Disabled.color(cx), }, } } } #[derive(Default, PartialEq, Clone, Copy)] pub enum ButtonSize2 { #[default] Default, Compact, None, } impl ButtonSize2 { fn height(self) -> Rems { match self { ButtonSize2::Default => rems(22. / 16.), ButtonSize2::Compact => rems(18. / 16.), ButtonSize2::None => rems(16. / 16.), } } } // pub struct Button { // id: ElementId, // icon: Option, // icon_color: Option, // icon_position: Option, // label: Option