From 56d45e72cd9ee08d9803e6e0f00b746b96eabeb3 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Tue, 21 Nov 2023 00:59:29 -0500 Subject: [PATCH] Add Shape enum to avatar component, refactor UITextSize to styles/typography.rs --- crates/ui2/src/components/avatar.rs | 7 ++ crates/ui2/src/prelude.rs | 140 ---------------------------- crates/ui2/src/styles.rs | 2 + crates/ui2/src/styles/typography.rs | 27 ++++++ 4 files changed, 36 insertions(+), 140 deletions(-) create mode 100644 crates/ui2/src/styles/typography.rs diff --git a/crates/ui2/src/components/avatar.rs b/crates/ui2/src/components/avatar.rs index f4b9006457ce5529e6979ac843ee752bbd527329..364a1454946d51970723938da672b21993f9484f 100644 --- a/crates/ui2/src/components/avatar.rs +++ b/crates/ui2/src/components/avatar.rs @@ -1,6 +1,13 @@ use crate::prelude::*; use gpui::{img, Img, RenderOnce}; +#[derive(Debug, Default, PartialEq, Clone)] +pub enum Shape { + #[default] + Circle, + RoundedRectangle, +} + #[derive(RenderOnce)] pub struct Avatar { src: SharedString, diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index a06b9b0a144e011542063621af43d039ea2436f2..fdd8af74dae6f8a32c66b6e5bc410b3455e90932 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -1,5 +1,3 @@ -use gpui::rems; -use gpui::Rems; pub use gpui::{ div, Component, Element, ElementId, InteractiveElement, ParentElement, SharedString, Styled, ViewContext, WindowContext, @@ -9,107 +7,8 @@ pub use crate::StyledExt; pub use crate::{ButtonVariant, TextColor}; pub use theme2::ActiveTheme; -use gpui::Hsla; use strum::EnumIter; -#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum UITextSize { - /// The default size for UI text. - /// - /// `0.825rem` or `14px` at the default scale of `1rem` = `16px`. - /// - /// Note: The absolute size of this text will change based on a user's `ui_scale` setting. - #[default] - Default, - /// The small size for UI text. - /// - /// `0.75rem` or `12px` at the default scale of `1rem` = `16px`. - /// - /// Note: The absolute size of this text will change based on a user's `ui_scale` setting. - Small, -} - -impl UITextSize { - pub fn rems(self) -> Rems { - match self { - Self::Default => rems(0.875), - Self::Small => rems(0.75), - } - } -} - -#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum FileSystemStatus { - #[default] - None, - Conflict, - Deleted, -} - -impl std::fmt::Display for FileSystemStatus { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - match self { - Self::None => "None", - Self::Conflict => "Conflict", - Self::Deleted => "Deleted", - } - ) - } -} - -#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum GitStatus { - #[default] - None, - Created, - Modified, - Deleted, - Conflict, - Renamed, -} - -impl GitStatus { - pub fn hsla(&self, cx: &WindowContext) -> Hsla { - match self { - Self::None => cx.theme().system().transparent, - Self::Created => cx.theme().status().created, - Self::Modified => cx.theme().status().modified, - Self::Deleted => cx.theme().status().deleted, - Self::Conflict => cx.theme().status().conflict, - Self::Renamed => cx.theme().status().renamed, - } - } -} - -impl std::fmt::Display for GitStatus { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - match self { - Self::None => "None", - Self::Created => "Created", - Self::Modified => "Modified", - Self::Deleted => "Deleted", - Self::Conflict => "Conflict", - Self::Renamed => "Renamed", - } - ) - } -} - -#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum DiagnosticStatus { - #[default] - None, - Error, - Warning, - Info, -} - #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] pub enum IconSide { #[default] @@ -117,45 +16,6 @@ pub enum IconSide { Right, } -#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum OrderMethod { - #[default] - Ascending, - Descending, - MostRecent, -} - -#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum Shape { - #[default] - Circle, - RoundedRectangle, -} - -#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum DisclosureControlVisibility { - #[default] - OnHover, - Always, -} - -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum DisclosureControlStyle { - /// Shows the disclosure control only when hovered where possible. - /// - /// More compact, but not available everywhere. - ChevronOnHover, - /// Shows an icon where possible, otherwise shows a chevron. - /// - /// For example, in a file tree a folder or file icon is shown - /// instead of a chevron - Icon, - /// Always shows a chevron. - Chevron, - /// Completely hides the disclosure control where possible. - None, -} - #[derive(Debug, PartialEq, Eq, Clone, Copy, EnumIter)] pub enum OverflowStyle { Hidden, diff --git a/crates/ui2/src/styles.rs b/crates/ui2/src/styles.rs index 8f2e97f22aed9ba4a06acea606a90947c85bfbff..210cb79b1396b16410e7986624d0a3316f88770b 100644 --- a/crates/ui2/src/styles.rs +++ b/crates/ui2/src/styles.rs @@ -1,2 +1,4 @@ mod elevation; +mod typography; pub use elevation::*; +pub use typography::*; diff --git a/crates/ui2/src/styles/typography.rs b/crates/ui2/src/styles/typography.rs new file mode 100644 index 0000000000000000000000000000000000000000..18b2c4849af3687b6ea0468a3ccc77846637f67f --- /dev/null +++ b/crates/ui2/src/styles/typography.rs @@ -0,0 +1,27 @@ +use gpui::{rems, Rems}; + +#[derive(Debug, Default, Clone)] +pub enum UITextSize { + /// The default size for UI text. + /// + /// `0.825rem` or `14px` at the default scale of `1rem` = `16px`. + /// + /// Note: The absolute size of this text will change based on a user's `ui_scale` setting. + #[default] + Default, + /// The small size for UI text. + /// + /// `0.75rem` or `12px` at the default scale of `1rem` = `16px`. + /// + /// Note: The absolute size of this text will change based on a user's `ui_scale` setting. + Small, +} + +impl UITextSize { + pub fn rems(self) -> Rems { + match self { + Self::Default => rems(0.875), + Self::Small => rems(0.75), + } + } +}