diff --git a/crates/collab_ui2/src/collab_titlebar_item.rs b/crates/collab_ui2/src/collab_titlebar_item.rs index 2c08840691..94db2f4d9f 100644 --- a/crates/collab_ui2/src/collab_titlebar_item.rs +++ b/crates/collab_ui2/src/collab_titlebar_item.rs @@ -37,7 +37,7 @@ use gpui::{ }; use project::Project; use theme::ActiveTheme; -use ui::{h_stack, Button, ButtonVariant, KeyBinding, Label, TextColor, Tooltip}; +use ui::{h_stack, Button, ButtonVariant, Color, KeyBinding, Label, Tooltip}; use workspace::Workspace; // const MAX_PROJECT_NAME_LENGTH: usize = 40; @@ -115,7 +115,7 @@ impl Render for CollabTitlebarItem { .child( Button::new("player") .variant(ButtonVariant::Ghost) - .color(Some(TextColor::Player(0))), + .color(Some(Color::Player(0))), ) .tooltip(move |cx| Tooltip::text("Toggle following", cx)), ) @@ -133,7 +133,7 @@ impl Render for CollabTitlebarItem { .child( Button::new("branch_name") .variant(ButtonVariant::Ghost) - .color(Some(TextColor::Muted)), + .color(Some(Color::Muted)), ) .tooltip(move |cx| { cx.build_view(|_| { diff --git a/crates/diagnostics2/src/diagnostics.rs b/crates/diagnostics2/src/diagnostics.rs index 9cd049597d..7ff8cd84db 100644 --- a/crates/diagnostics2/src/diagnostics.rs +++ b/crates/diagnostics2/src/diagnostics.rs @@ -36,7 +36,7 @@ use std::{ }; use theme::ActiveTheme; pub use toolbar_controls::ToolbarControls; -use ui::{h_stack, HighlightedLabel, Icon, IconElement, Label, TextColor}; +use ui::{h_stack, Color, HighlightedLabel, Icon, IconElement, Label}; use util::TryFutureExt; use workspace::{ item::{BreadcrumbText, Item, ItemEvent, ItemHandle}, @@ -778,15 +778,15 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock { .bg(gpui::red()) .map(|stack| { let icon = if diagnostic.severity == DiagnosticSeverity::ERROR { - IconElement::new(Icon::XCircle).color(TextColor::Error) + IconElement::new(Icon::XCircle).color(Color::Error) } else { - IconElement::new(Icon::ExclamationTriangle).color(TextColor::Warning) + IconElement::new(Icon::ExclamationTriangle).color(Color::Warning) }; stack.child(div().pl_8().child(icon)) }) .when_some(diagnostic.source.as_ref(), |stack, source| { - stack.child(Label::new(format!("{source}:")).color(TextColor::Accent)) + stack.child(Label::new(format!("{source}:")).color(Color::Accent)) }) .child(HighlightedLabel::new(message.clone(), highlights.clone())) .when_some(diagnostic.code.as_ref(), |stack, code| { diff --git a/crates/diagnostics2/src/items.rs b/crates/diagnostics2/src/items.rs index 730927a79e..bbcfa748d4 100644 --- a/crates/diagnostics2/src/items.rs +++ b/crates/diagnostics2/src/items.rs @@ -7,7 +7,7 @@ use gpui::{ use language::Diagnostic; use lsp::LanguageServerId; use theme::ActiveTheme; -use ui::{h_stack, Icon, IconElement, Label, TextColor, Tooltip}; +use ui::{h_stack, Color, Icon, IconElement, Label, Tooltip}; use workspace::{item::ItemHandle, StatusItemView, ToolbarItemEvent, Workspace}; use crate::ProjectDiagnosticsEditor; @@ -26,20 +26,20 @@ impl Render for DiagnosticIndicator { fn render(&mut self, cx: &mut ViewContext) -> Self::Element { let diagnostic_indicator = match (self.summary.error_count, self.summary.warning_count) { - (0, 0) => h_stack().child(IconElement::new(Icon::Check).color(TextColor::Success)), + (0, 0) => h_stack().child(IconElement::new(Icon::Check).color(Color::Success)), (0, warning_count) => h_stack() .gap_1() - .child(IconElement::new(Icon::ExclamationTriangle).color(TextColor::Warning)) + .child(IconElement::new(Icon::ExclamationTriangle).color(Color::Warning)) .child(Label::new(warning_count.to_string())), (error_count, 0) => h_stack() .gap_1() - .child(IconElement::new(Icon::XCircle).color(TextColor::Error)) + .child(IconElement::new(Icon::XCircle).color(Color::Error)) .child(Label::new(error_count.to_string())), (error_count, warning_count) => h_stack() .gap_1() - .child(IconElement::new(Icon::XCircle).color(TextColor::Error)) + .child(IconElement::new(Icon::XCircle).color(Color::Error)) .child(Label::new(error_count.to_string())) - .child(IconElement::new(Icon::ExclamationTriangle).color(TextColor::Warning)) + .child(IconElement::new(Icon::ExclamationTriangle).color(Color::Warning)) .child(Label::new(warning_count.to_string())), }; diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index a4482af6af..fa7bfd77cc 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -4408,7 +4408,7 @@ impl Editor { editor.fold_at(&FoldAt { buffer_row }, cx); } })) - .color(ui::TextColor::Muted) + .color(ui::Color::Muted) }) }) .flatten() diff --git a/crates/editor2/src/items.rs b/crates/editor2/src/items.rs index cdb15329d3..eca3b99d78 100644 --- a/crates/editor2/src/items.rs +++ b/crates/editor2/src/items.rs @@ -30,7 +30,7 @@ use std::{ }; use text::Selection; use theme::{ActiveTheme, Theme}; -use ui::{Label, TextColor}; +use ui::{Color, Label}; use util::{paths::PathExt, ResultExt, TryFutureExt}; use workspace::item::{BreadcrumbText, FollowEvent, FollowableEvents, FollowableItemHandle}; use workspace::{ @@ -604,7 +604,7 @@ impl Item for Editor { &description, MAX_TAB_TITLE_LEN, )) - .color(TextColor::Muted), + .color(Color::Muted), ), ) })), diff --git a/crates/go_to_line2/src/go_to_line.rs b/crates/go_to_line2/src/go_to_line.rs index 4ba605c3c9..61f5742750 100644 --- a/crates/go_to_line2/src/go_to_line.rs +++ b/crates/go_to_line2/src/go_to_line.rs @@ -5,7 +5,7 @@ use gpui::{ }; use text::{Bias, Point}; use theme::ActiveTheme; -use ui::{h_stack, v_stack, Label, StyledExt, TextColor}; +use ui::{h_stack, v_stack, Color, Label, StyledExt}; use util::paths::FILE_ROW_COLUMN_DELIMITER; use workspace::Workspace; @@ -176,7 +176,7 @@ impl Render for GoToLine { .justify_between() .px_2() .py_1() - .child(Label::new(self.current_text.clone()).color(TextColor::Muted)), + .child(Label::new(self.current_text.clone()).color(Color::Muted)), ), ) } diff --git a/crates/picker2/src/picker2.rs b/crates/picker2/src/picker2.rs index 786e641ee8..e58b7782ef 100644 --- a/crates/picker2/src/picker2.rs +++ b/crates/picker2/src/picker2.rs @@ -4,7 +4,7 @@ use gpui::{ MouseDownEvent, Render, Task, UniformListScrollHandle, View, ViewContext, WindowContext, }; use std::{cmp, sync::Arc}; -use ui::{prelude::*, v_stack, Divider, Label, TextColor}; +use ui::{prelude::*, v_stack, Color, Divider, Label}; pub struct Picker { pub delegate: D, @@ -250,7 +250,7 @@ impl Render for Picker { v_stack().p_1().grow().child( div() .px_1() - .child(Label::new("No matches").color(TextColor::Muted)), + .child(Label::new("No matches").color(Color::Muted)), ), ) }) diff --git a/crates/ui2/Cargo.toml b/crates/ui2/Cargo.toml index efbec22bee..0fa277dc89 100644 --- a/crates/ui2/Cargo.toml +++ b/crates/ui2/Cargo.toml @@ -4,6 +4,10 @@ version = "0.1.0" edition = "2021" publish = false +[lib] +name = "ui2" +path = "src/ui2.rs" + [dependencies] anyhow.workspace = true chrono = "0.4" diff --git a/crates/ui2/src/components.rs b/crates/ui2/src/components.rs index e7b2d9cf0f..4d7e3c14b6 100644 --- a/crates/ui2/src/components.rs +++ b/crates/ui2/src/components.rs @@ -2,56 +2,34 @@ mod avatar; mod button; mod checkbox; mod context_menu; -mod details; +mod disclosure; mod divider; -mod elevated_surface; -mod facepile; mod icon; mod icon_button; -mod indicator; mod input; mod keybinding; mod label; mod list; -mod modal; -mod notification_toast; -mod palette; -mod panel; -mod player; -mod player_stack; mod slot; mod stack; -mod tab; -mod toast; +mod stories; mod toggle; -mod tool_divider; mod tooltip; pub use avatar::*; pub use button::*; pub use checkbox::*; pub use context_menu::*; -pub use details::*; +pub use disclosure::*; pub use divider::*; -pub use elevated_surface::*; -pub use facepile::*; pub use icon::*; pub use icon_button::*; -pub use indicator::*; pub use input::*; pub use keybinding::*; pub use label::*; pub use list::*; -pub use modal::*; -pub use notification_toast::*; -pub use palette::*; -pub use panel::*; -pub use player::*; -pub use player_stack::*; pub use slot::*; pub use stack::*; -pub use tab::*; -pub use toast::*; +pub use stories::*; pub use toggle::*; -pub use tool_divider::*; pub use tooltip::*; diff --git a/crates/ui2/src/components/avatar.rs b/crates/ui2/src/components/avatar.rs index ab79352f86..364a145494 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, @@ -39,31 +46,3 @@ impl Avatar { self } } - -#[cfg(feature = "stories")] -pub use stories::*; - -#[cfg(feature = "stories")] -mod stories { - use super::*; - use crate::Story; - use gpui::{Div, Render}; - - pub struct AvatarStory; - - impl Render for AvatarStory { - type Element = Div; - - fn render(&mut self, cx: &mut ViewContext) -> Self::Element { - Story::container(cx) - .child(Story::title_for::(cx)) - .child(Story::label(cx, "Default")) - .child(Avatar::new( - "https://avatars.githubusercontent.com/u/1714999?v=4", - )) - .child(Avatar::new( - "https://avatars.githubusercontent.com/u/326587?v=4", - )) - } - } -} diff --git a/crates/ui2/src/components/button.rs b/crates/ui2/src/components/button.rs index 3d92cebec5..a5176be52e 100644 --- a/crates/ui2/src/components/button.rs +++ b/crates/ui2/src/components/button.rs @@ -6,7 +6,7 @@ use gpui::{ }; use crate::prelude::*; -use crate::{h_stack, Icon, IconButton, IconElement, Label, LineHeightStyle, TextColor}; +use crate::{h_stack, Color, Icon, IconButton, IconElement, Label, LineHeightStyle}; /// Provides the flexibility to use either a standard /// button or an icon button in a given context. @@ -73,7 +73,7 @@ pub struct Button { label: SharedString, variant: ButtonVariant, width: Option, - color: Option, + color: Option, } impl Component for Button { @@ -81,9 +81,9 @@ impl Component for Button { fn render(self, cx: &mut WindowContext) -> Self::Rendered { let (icon_color, label_color) = match (self.disabled, self.color) { - (true, _) => (TextColor::Disabled, TextColor::Disabled), - (_, None) => (TextColor::Default, TextColor::Default), - (_, Some(color)) => (TextColor::from(color), color), + (true, _) => (Color::Disabled, Color::Disabled), + (_, None) => (Color::Default, Color::Default), + (_, Some(color)) => (Color::from(color), color), }; let mut button = h_stack() @@ -181,14 +181,14 @@ impl Button { self } - pub fn color(mut self, color: Option) -> Self { + pub fn color(mut self, color: Option) -> Self { self.color = color; self } - pub fn label_color(&self, color: Option) -> TextColor { + pub fn label_color(&self, color: Option) -> Color { if self.disabled { - TextColor::Disabled + Color::Disabled } else if let Some(color) = color { color } else { @@ -196,13 +196,13 @@ impl Button { } } - fn render_label(&self, color: TextColor) -> Label { + fn render_label(&self, color: Color) -> Label { Label::new(self.label.clone()) .color(color) .line_height_style(LineHeightStyle::UILabel) } - fn render_icon(&self, icon_color: TextColor) -> Option { + fn render_icon(&self, icon_color: Color) -> Option { self.icon.map(|i| IconElement::new(i).color(icon_color)) } } @@ -231,171 +231,3 @@ impl ButtonGroup { Self { buttons } } } - -#[cfg(feature = "stories")] -pub use stories::*; - -#[cfg(feature = "stories")] -mod stories { - use super::*; - use crate::{h_stack, v_stack, Story, TextColor}; - use gpui::{rems, Div, Render}; - use strum::IntoEnumIterator; - - pub struct ButtonStory; - - impl Render for ButtonStory { - type Element = Div; - - fn render(&mut self, cx: &mut ViewContext) -> Self::Element { - let states = InteractionState::iter(); - - Story::container(cx) - .child(Story::title_for::