From e1032c53412c911e5a615d7332525d1588d2657f Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 25 Oct 2023 16:32:44 +0200 Subject: [PATCH] Remove `ThemeColor` in favor of `theme2::Theme` --- crates/ui2/src/color.rs | 72 +------------- crates/ui2/src/components/assistant_panel.rs | 2 - crates/ui2/src/components/breadcrumb.rs | 23 ++--- crates/ui2/src/components/buffer.rs | 20 ++-- crates/ui2/src/components/buffer_search.rs | 6 +- crates/ui2/src/components/collab_panel.rs | 73 +------------- crates/ui2/src/components/context_menu.rs | 6 +- crates/ui2/src/components/copilot.rs | 2 - crates/ui2/src/components/editor_pane.rs | 2 - crates/ui2/src/components/facepile.rs | 1 - crates/ui2/src/components/icon_button.rs | 14 +-- crates/ui2/src/components/keybinding.rs | 6 +- crates/ui2/src/components/list.rs | 40 ++++---- crates/ui2/src/components/modal.rs | 10 +- crates/ui2/src/components/multi_buffer.rs | 16 ++-- .../ui2/src/components/notification_toast.rs | 4 +- .../ui2/src/components/notifications_panel.rs | 4 +- crates/ui2/src/components/palette.rs | 14 ++- crates/ui2/src/components/panel.rs | 6 +- crates/ui2/src/components/panes.rs | 6 +- crates/ui2/src/components/player_stack.rs | 4 +- crates/ui2/src/components/project_panel.rs | 4 +- crates/ui2/src/components/status_bar.rs | 8 +- crates/ui2/src/components/tab.rs | 14 +-- crates/ui2/src/components/tab_bar.rs | 4 +- crates/ui2/src/components/terminal.rs | 6 +- crates/ui2/src/components/title_bar.rs | 4 +- crates/ui2/src/components/toast.rs | 4 +- crates/ui2/src/components/toolbar.rs | 14 +-- crates/ui2/src/components/traffic_lights.rs | 12 +-- crates/ui2/src/components/workspace.rs | 2 - crates/ui2/src/elements/avatar.rs | 4 +- crates/ui2/src/elements/button.rs | 21 ++-- crates/ui2/src/elements/details.rs | 4 +- crates/ui2/src/elements/icon.rs | 1 - crates/ui2/src/elements/input.rs | 16 ++-- crates/ui2/src/elements/label.rs | 28 +++--- crates/ui2/src/elements/player.rs | 12 +-- crates/ui2/src/elements/tool_divider.rs | 4 +- crates/ui2/src/prelude.rs | 16 ++-- crates/ui2/src/static_data.rs | 95 ++++++++++--------- crates/ui2/src/story.rs | 12 +-- 42 files changed, 225 insertions(+), 391 deletions(-) diff --git a/crates/ui2/src/color.rs b/crates/ui2/src/color.rs index dfc734a75e743183c86f1af771a51156888b557e..966df6b65bfcbc5dc87929a99aa2f0eed7bf0fbf 100644 --- a/crates/ui2/src/color.rs +++ b/crates/ui2/src/color.rs @@ -1,6 +1,5 @@ -use crate::theme; pub use crate::{old_theme, ButtonVariant, ElementExt, Theme}; -use gpui2::{hsla, rgb, Hsla, WindowContext}; +use gpui2::{rgb, Hsla, WindowContext}; use strum::EnumIter; #[derive(Clone, Copy)] @@ -251,75 +250,6 @@ impl std::fmt::Debug for ThemeColor { } } -impl ThemeColor { - pub fn new(cx: &WindowContext) -> Self { - let theme2 = theme(cx); - let transparent = hsla(0.0, 0.0, 0.0, 0.0); - - let players = [ - PlayerThemeColors::new(cx, 0), - PlayerThemeColors::new(cx, 1), - PlayerThemeColors::new(cx, 2), - PlayerThemeColors::new(cx, 3), - PlayerThemeColors::new(cx, 4), - PlayerThemeColors::new(cx, 5), - PlayerThemeColors::new(cx, 6), - PlayerThemeColors::new(cx, 7), - ]; - - Self { - transparent: theme2.transparent, - mac_os_traffic_light_red: theme2.mac_os_traffic_light_red, - mac_os_traffic_light_yellow: theme2.mac_os_traffic_light_yellow, - mac_os_traffic_light_green: theme2.mac_os_traffic_light_green, - border: theme2.border, - border_variant: theme2.border_variant, - border_focused: theme2.border_focused, - border_transparent: theme2.border_transparent, - elevated_surface: theme2.elevated_surface, - surface: theme2.surface, - background: theme2.background, - filled_element: theme2.filled_element, - filled_element_hover: theme2.filled_element_hover, - filled_element_active: theme2.filled_element_active, - filled_element_selected: theme2.filled_element_selected, - filled_element_disabled: theme2.filled_element_disabled, - ghost_element: theme2.ghost_element, - ghost_element_hover: theme2.ghost_element_hover, - ghost_element_active: theme2.ghost_element_active, - ghost_element_selected: theme2.ghost_element_selected, - ghost_element_disabled: theme2.ghost_element_disabled, - text: theme2.text, - text_muted: theme2.text_muted, - /// TODO: map this to a real value - text_placeholder: theme2.text_placeholder, - text_disabled: theme2.text_disabled, - text_accent: theme2.text_accent, - icon_muted: theme2.icon_muted, - syntax: SyntaxColor::new(cx), - - status_bar: theme2.status_bar, - title_bar: theme2.title_bar, - toolbar: theme2.toolbar, - tab_bar: theme2.tab_bar, - editor: theme2.editor, - editor_subheader: theme2.editor_subheader, - terminal: theme2.terminal, - editor_active_line: theme2.editor_active_line, - image_fallback_background: theme2.image_fallback_background, - - git_created: theme2.git_created, - git_modified: theme2.git_modified, - git_deleted: theme2.git_deleted, - git_conflict: theme2.git_conflict, - git_ignored: theme2.git_ignored, - git_renamed: theme2.git_renamed, - - player: players, - } - } -} - /// Colors used exclusively for syntax highlighting. /// /// For now we deserialize these from a theme. diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index 79ef630864ce58bc63528ab39e8d3a34f83cbfa0..31f299de910c90d7671b9267748796880e6901c8 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -27,8 +27,6 @@ impl AssistantPanel { } fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - Panel::new(self.id.clone(), cx) .children(vec![div() .flex() diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index 7d63425a7c0f75d9846c12b7e264669fbc82f62d..e67ceb1751cb54e41b153f12c6a83b4db27285ea 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -26,8 +26,9 @@ impl Breadcrumb { } fn render_separator(&self, cx: &WindowContext) -> Div { - let color = ThemeColor::new(cx); - div().child(" › ").text_color(color.text_muted) + let theme = theme(cx); + + div().child(" › ").text_color(theme.text_muted) } fn render( @@ -35,7 +36,7 @@ impl Breadcrumb { view_state: &mut S, cx: &mut ViewContext, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -43,10 +44,10 @@ impl Breadcrumb { .id("breadcrumb") .px_1() .text_sm() - .text_color(color.text_muted) + .text_color(theme.text_muted) .rounded_md() - .hover(|style| style.bg(color.ghost_element_hover)) - .active(|style| style.bg(color.ghost_element_active)) + .hover(|style| style.bg(theme.ghost_element_hover)) + .active(|style| style.bg(theme.ghost_element_active)) .child(self.path.clone().to_str().unwrap().to_string()) .child(if !self.symbols.is_empty() { self.render_separator(cx) @@ -106,7 +107,7 @@ mod stories { view_state: &mut S, cx: &mut ViewContext, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); Story::container(cx) .child(Story::title_for::<_, Breadcrumb>(cx)) @@ -117,21 +118,21 @@ mod stories { Symbol(vec![ HighlightedText { text: "impl ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "BreadcrumbStory".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, ]), Symbol(vec![ HighlightedText { text: "fn ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "render".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, ]), ], diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index c684d2e24d9aa1a01ac73b5a33ca19a7f05691d2..2e0e07e16c8ac7ecab113986d1139adb7339db2e 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -159,18 +159,18 @@ impl Buffer { } fn render_row(row: BufferRow, cx: &WindowContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let line_background = if row.current { - color.editor_active_line + theme.editor_active_line } else { - color.transparent + theme.transparent }; let line_number_color = if row.current { - color.text + theme.text } else { - color.syntax.comment + theme.syntax.comment }; h_stack() @@ -220,14 +220,14 @@ impl Buffer { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let rows = self.render_rows(cx); v_stack() .flex_1() .w_full() .h_full() - .bg(color.editor) + .bg(theme.editor) .children(rows) } } @@ -263,7 +263,7 @@ mod stories { _view: &mut S, cx: &mut ViewContext, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); Story::container(cx) .child(Story::title_for::<_, Buffer>(cx)) @@ -274,14 +274,14 @@ mod stories { div() .w(rems(64.)) .h_96() - .child(hello_world_rust_buffer_example(&color)), + .child(hello_world_rust_buffer_example(&theme)), ) .child(Story::label(cx, "Hello World (Rust) with Status")) .child( div() .w(rems(64.)) .h_96() - .child(hello_world_rust_buffer_with_status_example(&color)), + .child(hello_world_rust_buffer_with_status_example(&theme)), ) } } diff --git a/crates/ui2/src/components/buffer_search.rs b/crates/ui2/src/components/buffer_search.rs index 941dc904228782f7c5727c974af0cf67fc95ea17..1edbd58c8775e0eb59ca9d4678400a688895b58a 100644 --- a/crates/ui2/src/components/buffer_search.rs +++ b/crates/ui2/src/components/buffer_search.rs @@ -22,15 +22,13 @@ impl BufferSearch { } pub fn view(cx: &mut WindowContext) -> View { - let color = ThemeColor::new(cx); - view(cx.entity(|cx| Self::new()), Self::render) } fn render(&mut self, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); - h_stack().bg(color.toolbar).p_2().child( + h_stack().bg(theme.toolbar).p_2().child( h_stack().child(Input::new("Search")).child( IconButton::::new("replace", Icon::Replace) .when(self.is_replace_open, |this| this.color(IconColor::Accent)) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index 7be29e10304f4c2f39784b7a80342ce97ea5c315..6414e0e5ffbf00e3cd93cfc5d823e5e86ada2eda 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -3,7 +3,6 @@ use crate::{ static_collab_panel_channels, static_collab_panel_current_call, v_stack, Icon, List, ListHeader, ToggleState, }; -use gpui2::{img, svg, SharedString}; use std::marker::PhantomData; #[derive(Element)] @@ -21,19 +20,19 @@ impl CollabPanel { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); v_stack() .id(self.id.clone()) .h_full() - .bg(color.surface) + .bg(theme.surface) .child( v_stack() .id("crdb") .w_full() .overflow_y_scroll() .child( - div().pb_1().border_color(color.border).border_b().child( + div().pb_1().border_color(theme.border).border_b().child( List::new(static_collab_panel_current_call()) .header( ListHeader::new("CRDB") @@ -77,79 +76,17 @@ impl CollabPanel { .h_7() .px_2() .border_t() - .border_color(color.border) + .border_color(theme.border) .flex() .items_center() .child( div() .text_sm() - .text_color(color.text_placeholder) + .text_color(theme.text_placeholder) .child("Find..."), ), ) } - - fn list_section_header( - &self, - label: impl Into, - expanded: bool, - cx: &WindowContext, - ) -> impl Element { - let color = ThemeColor::new(cx); - div() - .h_7() - .px_2() - .flex() - .justify_between() - .items_center() - .child(div().flex().gap_1().text_sm().child(label.into())) - .child( - div().flex().h_full().gap_1().items_center().child( - svg() - .path(if expanded { - "icons/caret_down.svg" - } else { - "icons/caret_up.svg" - }) - .w_3p5() - .h_3p5() - .text_color(color.icon_muted), - ), - ) - } - - fn list_item( - &self, - avatar_uri: impl Into, - label: impl Into, - cx: &WindowContext, - ) -> impl Element { - let color = ThemeColor::new(cx); - - div() - .id("list_item") - .h_7() - .px_2() - .flex() - .items_center() - .hover(|style| style.bg(color.ghost_element_hover)) - .active(|style| style.bg(color.ghost_element_active)) - .child( - div() - .flex() - .items_center() - .gap_1() - .text_sm() - .child( - img() - .uri(avatar_uri) - .size_3p5() - .rounded_full() - .bg(color.image_fallback_background), - ) - .child(label.into()), - ) - } } #[cfg(feature = "stories")] diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index d99eac1b7de9682c4e72bf9131595f820d5b3940..73813ed61356926fec81d9c509b01a2de0d67cd5 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -43,13 +43,13 @@ impl ContextMenu { } } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); v_stack() .flex() - .bg(color.elevated_surface) + .bg(theme.elevated_surface) .border() - .border_color(color.border) + .border_color(theme.border) .child( List::new( self.items diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index 06592408925e03cd64a64bedcf6eff228fdae87b..b0f20cfa0d8928d949918a4bfa661534cfcfdbab 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -17,8 +17,6 @@ impl CopilotModal { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index 6bac3c1bc147bbb59138f4a82e6f0d22b92c7be6..7489b3e47d8edfa2c5d1e0f2544a33aa71804e4c 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -43,8 +43,6 @@ impl EditorPane { } pub fn view(cx: &mut WindowContext) -> View { - let color = ThemeColor::new(cx); - view( cx.entity(|cx| hello_world_rust_editor_with_status_example(cx)), Self::render, diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index 8bd4eafa18918b1b83bcf806434cb0eadd7e0a4e..9a96d8001053e1c6ea81d347d5a781aca23a39a8 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -18,7 +18,6 @@ impl Facepile { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index 86c3f994013aced8fbc5af2e2fb5e490ea83ebde..b74165720d15f0b78486d2d40fb9e6df07bcd6fd 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -69,7 +69,7 @@ impl IconButton { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let icon_color = match (self.state, self.color) { (InteractionState::Disabled, _) => IconColor::Disabled, @@ -78,14 +78,14 @@ impl IconButton { let (bg_color, bg_hover_color, bg_active_color) = match self.variant { ButtonVariant::Filled => ( - color.filled_element, - color.filled_element_hover, - color.filled_element_active, + theme.filled_element, + theme.filled_element_hover, + theme.filled_element_active, ), ButtonVariant::Ghost => ( - color.ghost_element, - color.ghost_element_hover, - color.ghost_element_active, + theme.ghost_element, + theme.ghost_element_hover, + theme.ghost_element_active, ), }; diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 081b4d907ed7627c185be77dc4bce34dc0230c6b..2fb40adac6446c1cc47d1682466110c6705db228 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -69,15 +69,15 @@ impl Key { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() .px_2() .py_0() .rounded_md() .text_sm() - .text_color(color.text) - .bg(color.filled_element) + .text_color(theme.text) + .bg(theme.filled_element) .child(self.key.clone()) } } diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index 56bd931121cdeeb394848279dcfdace97c126e40..99282fa06dd45ef1834942bfae1c56946a2fcb4c 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -93,7 +93,7 @@ impl ListHeader { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = self.toggleable.is_toggled(); @@ -103,9 +103,9 @@ impl ListHeader { h_stack() .flex_1() .w_full() - .bg(color.surface) + .bg(theme.surface) .when(self.state == InteractionState::Focused, |this| { - this.border().border_color(color.border_focused) + this.border().border_color(theme.border_focused) }) .relative() .child( @@ -158,8 +158,6 @@ impl ListSubHeader { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -350,8 +348,6 @@ impl ListEntry { &mut self, cx: &mut ViewContext, ) -> Option> { - let color = ThemeColor::new(cx); - let disclosure_control_icon = if let Some(ToggleState::Toggled) = self.toggle { IconElement::new(Icon::ChevronDown) } else { @@ -372,9 +368,8 @@ impl ListEntry { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - let color = ThemeColor::new(cx); let settings = user_settings(cx); + let theme = theme(cx); let left_content = match self.left_content.clone() { Some(LeftContent::Icon(i)) => Some( @@ -396,9 +391,9 @@ impl ListEntry { div() .relative() .group("") - .bg(color.surface) + .bg(theme.surface) .when(self.state == InteractionState::Focused, |this| { - this.border().border_color(color.border_focused) + this.border().border_color(theme.border_focused) }) .child( sized_item @@ -410,11 +405,11 @@ impl ListEntry { .h_full() .flex() .justify_center() - .group_hover("", |style| style.bg(color.border_focused)) + .group_hover("", |style| style.bg(theme.border_focused)) .child( h_stack() .child(div().w_px().h_full()) - .child(div().w_px().h_full().bg(color.border)), + .child(div().w_px().h_full().bg(theme.border)), ) })) .flex() @@ -483,19 +478,19 @@ impl ListDetailsEntry { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let settings = user_settings(cx); let (item_bg, item_bg_hover, item_bg_active) = match self.seen { true => ( - color.ghost_element, - color.ghost_element_hover, - color.ghost_element_active, + theme.ghost_element, + theme.ghost_element_hover, + theme.ghost_element_active, ), false => ( - color.filled_element, - color.filled_element_hover, - color.filled_element_active, + theme.filled_element, + theme.filled_element_hover, + theme.filled_element_active, ), }; @@ -540,9 +535,9 @@ impl ListSeparator { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); - div().h_px().w_full().bg(color.border) + div().h_px().w_full().bg(theme.border) } } @@ -580,7 +575,6 @@ impl List { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); diff --git a/crates/ui2/src/components/modal.rs b/crates/ui2/src/components/modal.rs index 9871036d23faf1a4a88784749451c5d20b8c3a2a..792f8e12682abe83d437df2758abe1c267ee79e4 100644 --- a/crates/ui2/src/components/modal.rs +++ b/crates/ui2/src/components/modal.rs @@ -43,22 +43,22 @@ impl Modal { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); v_stack() .id(self.id.clone()) .w_96() // .rounded_xl() - .bg(color.background) + .bg(theme.background) .border() - .border_color(color.border) + .border_color(theme.border) .shadow_2xl() .child( h_stack() .justify_between() .p_1() .border_b() - .border_color(color.border) + .border_color(theme.border) .child(div().children(self.title.clone().map(|t| Label::new(t)))) .child(IconButton::new("close", Icon::Close)), ) @@ -69,7 +69,7 @@ impl Modal { this.child( h_stack() .border_t() - .border_color(color.border) + .border_color(theme.border) .p_1() .justify_end() .children(self.secondary_action.take()) diff --git a/crates/ui2/src/components/multi_buffer.rs b/crates/ui2/src/components/multi_buffer.rs index bf8b6777cf753787a02faeb896d237bf8b2cd26a..b53ea13ef232f3681650923672ced4cccef06f91 100644 --- a/crates/ui2/src/components/multi_buffer.rs +++ b/crates/ui2/src/components/multi_buffer.rs @@ -18,7 +18,7 @@ impl MultiBuffer { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); v_stack() .w_full() @@ -32,7 +32,7 @@ impl MultiBuffer { .items_center() .justify_between() .p_4() - .bg(color.editor_subheader) + .bg(theme.editor_subheader) .child(Label::new("main.rs")) .child(IconButton::new("arrow_up_right", Icon::ArrowUpRight)), ) @@ -67,17 +67,17 @@ mod stories { _view: &mut S, cx: &mut ViewContext, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); Story::container(cx) .child(Story::title_for::<_, MultiBuffer>(cx)) .child(Story::label(cx, "Default")) .child(MultiBuffer::new(vec![ - hello_world_rust_buffer_example(&color), - hello_world_rust_buffer_example(&color), - hello_world_rust_buffer_example(&color), - hello_world_rust_buffer_example(&color), - hello_world_rust_buffer_example(&color), + hello_world_rust_buffer_example(&theme), + hello_world_rust_buffer_example(&theme), + hello_world_rust_buffer_example(&theme), + hello_world_rust_buffer_example(&theme), + hello_world_rust_buffer_example(&theme), ])) } } diff --git a/crates/ui2/src/components/notification_toast.rs b/crates/ui2/src/components/notification_toast.rs index 2d2afec7c34025f832e472487a0269b232bfc851..b7709e1a58ee1e0cfb199a6d140b09245ea239a2 100644 --- a/crates/ui2/src/components/notification_toast.rs +++ b/crates/ui2/src/components/notification_toast.rs @@ -29,7 +29,7 @@ impl NotificationToast { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); h_stack() .z_index(5) @@ -42,7 +42,7 @@ impl NotificationToast { .px_1p5() .rounded_lg() .shadow_md() - .bg(color.elevated_surface) + .bg(theme.elevated_surface) .child(div().size_full().child(self.label.clone())) } } diff --git a/crates/ui2/src/components/notifications_panel.rs b/crates/ui2/src/components/notifications_panel.rs index 026c34539f8881b22fcbff848a04ee40fd2d727f..eaf64eb4848fc195488a7e9a80ec57a8f33c3a5e 100644 --- a/crates/ui2/src/components/notifications_panel.rs +++ b/crates/ui2/src/components/notifications_panel.rs @@ -18,7 +18,7 @@ impl NotificationsPanel { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() .id(self.id.clone()) @@ -26,7 +26,7 @@ impl NotificationsPanel { .flex_col() .w_full() .h_full() - .bg(color.surface) + .bg(theme.surface) .child( div() .id("header") diff --git a/crates/ui2/src/components/palette.rs b/crates/ui2/src/components/palette.rs index 9cb8f2d9ca72f0daea090b1254727e4494e20dd0..87eb88c76487861bd85cc970fb182a03edea5ff7 100644 --- a/crates/ui2/src/components/palette.rs +++ b/crates/ui2/src/components/palette.rs @@ -47,22 +47,22 @@ impl Palette { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); v_stack() .id(self.id.clone()) .w_96() .rounded_lg() - .bg(color.elevated_surface) + .bg(theme.elevated_surface) .border() - .border_color(color.border) + .border_color(theme.border) .child( v_stack() .gap_px() .child(v_stack().py_0p5().px_1().child(div().px_2().py_0p5().child( Label::new(self.input_placeholder.clone()).color(LabelColor::Placeholder), ))) - .child(div().h_px().w_full().bg(color.filled_element)) + .child(div().h_px().w_full().bg(theme.filled_element)) .child( v_stack() .id("items") @@ -92,8 +92,8 @@ impl Palette { .px_2() .py_0p5() .rounded_lg() - .hover(|style| style.bg(color.ghost_element_hover)) - .active(|style| style.bg(color.ghost_element_active)) + .hover(|style| style.bg(theme.ghost_element_hover)) + .active(|style| style.bg(theme.ghost_element_active)) .child(item) })), ), @@ -136,8 +136,6 @@ impl PaletteItem { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - div() .flex() .flex_row() diff --git a/crates/ui2/src/components/panel.rs b/crates/ui2/src/components/panel.rs index 5c83d98339eef02ec0bf9d2c71240bf2e0aee1ce..90dbcf39599566392773f658501e4450a4578b86 100644 --- a/crates/ui2/src/components/panel.rs +++ b/crates/ui2/src/components/panel.rs @@ -97,7 +97,7 @@ impl Panel { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let current_size = self.width.unwrap_or(self.initial_width); @@ -115,8 +115,8 @@ impl Panel { .when(self.current_side == PanelSide::Bottom, |this| { this.border_b().w_full().h(current_size) }) - .bg(color.surface) - .border_color(color.border) + .bg(theme.surface) + .border_color(theme.border) .children(self.children.drain(..)) } } diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index d9a7b0a483d259ca41cd6b1ad03b933d17d149a0..1c60520c033048929017679e98bc79a37f45ee27 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -41,8 +41,6 @@ impl Pane { } fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - div() .id(self.id.clone()) .flex() @@ -100,7 +98,7 @@ impl PaneGroup { } fn render(&mut self, view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); if !self.panes.is_empty() { let el = div() @@ -125,7 +123,7 @@ impl PaneGroup { .gap_px() .w_full() .h_full() - .bg(color.editor) + .bg(theme.editor) .children(self.groups.iter_mut().map(|group| group.render(view, cx))); if self.split_direction == SplitDirection::Horizontal { diff --git a/crates/ui2/src/components/player_stack.rs b/crates/ui2/src/components/player_stack.rs index c7b0d52eefa22a96ab49c8b4d96891ec7ea49142..0240af8f47c419d7e560553297e4d5991abc57a3 100644 --- a/crates/ui2/src/components/player_stack.rs +++ b/crates/ui2/src/components/player_stack.rs @@ -18,7 +18,7 @@ impl PlayerStack { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let player = self.player_with_call_status.get_player(); self.player_with_call_status.get_call_status(); @@ -54,7 +54,7 @@ impl PlayerStack { .pl_1() .rounded_lg() .bg(if followers.is_none() { - color.transparent + theme.transparent } else { player.selection_color(cx) }) diff --git a/crates/ui2/src/components/project_panel.rs b/crates/ui2/src/components/project_panel.rs index aa50e0e044d932d0727b89b4362ca4ba2301e008..9328b21d4350a5eb35cd0a02bf208682a4bbaf6f 100644 --- a/crates/ui2/src/components/project_panel.rs +++ b/crates/ui2/src/components/project_panel.rs @@ -20,7 +20,7 @@ impl ProjectPanel { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() .id(self.id.clone()) @@ -28,7 +28,7 @@ impl ProjectPanel { .flex_col() .w_full() .h_full() - .bg(color.surface) + .bg(theme.surface) .child( div() .id("project-panel-contents") diff --git a/crates/ui2/src/components/status_bar.rs b/crates/ui2/src/components/status_bar.rs index 8ebb8901f34c87b316b1c2ea8639d05d7ee7a7d3..db28ac5070353316dd5cec4db318ed6e20040caa 100644 --- a/crates/ui2/src/components/status_bar.rs +++ b/crates/ui2/src/components/status_bar.rs @@ -87,7 +87,7 @@ impl StatusBar { view: &mut Workspace, cx: &mut ViewContext, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() .py_0p5() @@ -96,7 +96,7 @@ impl StatusBar { .items_center() .justify_between() .w_full() - .bg(color.status_bar) + .bg(theme.status_bar) .child(self.left_tools(view, cx)) .child(self.right_tools(view, cx)) } @@ -106,8 +106,6 @@ impl StatusBar { workspace: &mut Workspace, cx: &WindowContext, ) -> impl Element { - let color = ThemeColor::new(cx); - div() .flex() .items_center() @@ -139,8 +137,6 @@ impl StatusBar { workspace: &mut Workspace, cx: &WindowContext, ) -> impl Element { - let color = ThemeColor::new(cx); - div() .flex() .items_center() diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index c13d4e5637cd4254caf26f57f38dc3de2a371e5b..451dba9aa47978351b1b06777340465fc421e862 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -82,7 +82,7 @@ impl Tab { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let has_fs_conflict = self.fs_status == FileSystemStatus::Conflict; let is_deleted = self.fs_status == FileSystemStatus::Deleted; @@ -105,14 +105,14 @@ impl Tab { let (tab_bg, tab_hover_bg, tab_active_bg) = match self.current { true => ( - color.ghost_element, - color.ghost_element_hover, - color.ghost_element_active, + theme.ghost_element, + theme.ghost_element_hover, + theme.ghost_element_active, ), false => ( - color.filled_element, - color.filled_element_hover, - color.filled_element_active, + theme.filled_element, + theme.filled_element_hover, + theme.filled_element_active, ), }; diff --git a/crates/ui2/src/components/tab_bar.rs b/crates/ui2/src/components/tab_bar.rs index d83659dc5004ce8d15c8901aa1e9f52dcb3b1b58..ef67088287db104e8669a1b9c2fc62687fff0077 100644 --- a/crates/ui2/src/components/tab_bar.rs +++ b/crates/ui2/src/components/tab_bar.rs @@ -28,7 +28,7 @@ impl TabBar { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let (can_navigate_back, can_navigate_forward) = self.can_navigate; @@ -36,7 +36,7 @@ impl TabBar { .id(self.id.clone()) .w_full() .flex() - .bg(color.tab_bar) + .bg(theme.tab_bar) // Left Side .child( div() diff --git a/crates/ui2/src/components/terminal.rs b/crates/ui2/src/components/terminal.rs index 6304530f45732add8f38043c92efc7bda76d8250..236a8961bbad8a8337dbdc653d75c1ecfc1bf3f5 100644 --- a/crates/ui2/src/components/terminal.rs +++ b/crates/ui2/src/components/terminal.rs @@ -18,7 +18,7 @@ impl Terminal { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let can_navigate_back = true; let can_navigate_forward = false; @@ -32,7 +32,7 @@ impl Terminal { div() .w_full() .flex() - .bg(color.surface) + .bg(theme.surface) .child( div().px_1().flex().flex_none().gap_2().child( div() @@ -79,7 +79,7 @@ impl Terminal { height: rems(36.).into(), }, ) - .child(crate::static_data::terminal_buffer(&color)), + .child(crate::static_data::terminal_buffer(&theme)), ) } } diff --git a/crates/ui2/src/components/title_bar.rs b/crates/ui2/src/components/title_bar.rs index c0e0a79bf2aca041fcde0aa6f58889407414a76b..4cfb0921691bd00608745eb51dcae495807dd23e 100644 --- a/crates/ui2/src/components/title_bar.rs +++ b/crates/ui2/src/components/title_bar.rs @@ -88,7 +88,7 @@ impl TitleBar { } fn render(&mut self, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let settings = user_settings(cx); // let has_focus = cx.window_is_active(); @@ -105,7 +105,7 @@ impl TitleBar { .items_center() .justify_between() .w_full() - .bg(color.background) + .bg(theme.background) .py_1() .child( div() diff --git a/crates/ui2/src/components/toast.rs b/crates/ui2/src/components/toast.rs index 7780b90d4425de36316c52d2b8b016a4c0a85686..f75f9218417843fa831e7212959c9eff5c909ff4 100644 --- a/crates/ui2/src/components/toast.rs +++ b/crates/ui2/src/components/toast.rs @@ -37,7 +37,7 @@ impl Toast { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let mut div = div(); @@ -56,7 +56,7 @@ impl Toast { .rounded_lg() .shadow_md() .overflow_hidden() - .bg(color.elevated_surface) + .bg(theme.elevated_surface) .children(self.children.drain(..)) } } diff --git a/crates/ui2/src/components/toolbar.rs b/crates/ui2/src/components/toolbar.rs index 3fc7a6c19ea3fbb386be5243e841d7e97b92e710..2dc5dbff2fb09a803fe2c0eada5cd9a5fe1119f7 100644 --- a/crates/ui2/src/components/toolbar.rs +++ b/crates/ui2/src/components/toolbar.rs @@ -55,10 +55,10 @@ impl Toolbar { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() - .bg(color.toolbar) + .bg(theme.toolbar) .p_2() .flex() .justify_between() @@ -97,7 +97,7 @@ mod stories { _view: &mut S, cx: &mut ViewContext, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); Story::container(cx) .child(Story::title_for::<_, Toolbar>(cx)) @@ -110,21 +110,21 @@ mod stories { Symbol(vec![ HighlightedText { text: "impl ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "ToolbarStory".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, ]), Symbol(vec![ HighlightedText { text: "fn ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "render".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, ]), ], diff --git a/crates/ui2/src/components/traffic_lights.rs b/crates/ui2/src/components/traffic_lights.rs index 58f252628dd9d304b0af98aa5d4cd0fc4043c9e0..254855bc3f783eb5b1649a67018a36aed6d77b65 100644 --- a/crates/ui2/src/components/traffic_lights.rs +++ b/crates/ui2/src/components/traffic_lights.rs @@ -26,13 +26,13 @@ impl TrafficLight { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let fill = match (self.window_has_focus, self.color) { - (true, TrafficLightColor::Red) => color.mac_os_traffic_light_red, - (true, TrafficLightColor::Yellow) => color.mac_os_traffic_light_yellow, - (true, TrafficLightColor::Green) => color.mac_os_traffic_light_green, - (false, _) => color.filled_element, + (true, TrafficLightColor::Red) => theme.mac_os_traffic_light_red, + (true, TrafficLightColor::Yellow) => theme.mac_os_traffic_light_yellow, + (true, TrafficLightColor::Green) => theme.mac_os_traffic_light_green, + (false, _) => theme.filled_element, }; div().w_3().h_3().rounded_full().bg(fill) @@ -59,8 +59,6 @@ impl TrafficLights { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - div() .flex() .items_center() diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index e26ce6d659e5628cefdf6f23d5d3fe49afe720d4..ee913cb69314644a212607f1254d59a5998430a2 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -177,8 +177,6 @@ impl Workspace { pub fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = old_theme(cx).clone(); - let color = ThemeColor::new(cx); - // HACK: This should happen inside of `debug_toggle_user_settings`, but // we don't have `cx.global::()` in event handlers at the moment. // Need to talk with Nathan/Antonio about this. diff --git a/crates/ui2/src/elements/avatar.rs b/crates/ui2/src/elements/avatar.rs index 518fd2b166a2f70943a31cb99590f09affa6821a..416a55a4f7ababbc0068891e6da418c258f4502a 100644 --- a/crates/ui2/src/elements/avatar.rs +++ b/crates/ui2/src/elements/avatar.rs @@ -26,7 +26,7 @@ impl Avatar { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let mut img = img(); @@ -38,7 +38,7 @@ impl Avatar { img.uri(self.src.clone()) .size_4() - .bg(color.image_fallback_background) + .bg(theme.image_fallback_background) } } diff --git a/crates/ui2/src/elements/button.rs b/crates/ui2/src/elements/button.rs index c3413399cdd9db6aaf2507bfef8ba28fbefcae87..9948c91999a7c9b58bf9b44b5b2cb4c3f513a2ea 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -3,7 +3,6 @@ use std::sync::Arc; use gpui2::{div, DefiniteLength, Hsla, MouseButton, WindowContext}; -use crate::settings::user_settings; use crate::{h_stack, Icon, IconColor, IconElement, Label, LabelColor}; use crate::{prelude::*, LineHeightStyle}; @@ -23,29 +22,29 @@ pub enum ButtonVariant { impl ButtonVariant { pub fn bg_color(&self, cx: &mut WindowContext) -> Hsla { - let color = ThemeColor::new(cx); + let theme = theme(cx); match self { - ButtonVariant::Ghost => color.ghost_element, - ButtonVariant::Filled => color.filled_element, + ButtonVariant::Ghost => theme.ghost_element, + ButtonVariant::Filled => theme.filled_element, } } pub fn bg_color_hover(&self, cx: &mut WindowContext) -> Hsla { - let color = ThemeColor::new(cx); + let theme = theme(cx); match self { - ButtonVariant::Ghost => color.ghost_element_hover, - ButtonVariant::Filled => color.filled_element_hover, + ButtonVariant::Ghost => theme.ghost_element_hover, + ButtonVariant::Filled => theme.filled_element_hover, } } pub fn bg_color_active(&self, cx: &mut WindowContext) -> Hsla { - let color = ThemeColor::new(cx); + let theme = theme(cx); match self { - ButtonVariant::Ghost => color.ghost_element_active, - ButtonVariant::Filled => color.filled_element_active, + ButtonVariant::Ghost => theme.ghost_element_active, + ButtonVariant::Filled => theme.filled_element_active, } } } @@ -156,8 +155,6 @@ impl Button { _view: &mut S, cx: &mut ViewContext, ) -> impl Element { - let color = ThemeColor::new(cx); - let settings = user_settings(cx); let icon_color = self.icon_color(); let mut button = h_stack() diff --git a/crates/ui2/src/elements/details.rs b/crates/ui2/src/elements/details.rs index e53e5f7cf50e1fd488aef92062089794421bbc5b..9a37fb093587cce15d04297ad1b605d97d000ef1 100644 --- a/crates/ui2/src/elements/details.rs +++ b/crates/ui2/src/elements/details.rs @@ -31,13 +31,13 @@ impl Details { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); v_stack() .p_1() .gap_0p5() .text_xs() - .text_color(color.text) + .text_color(theme.text) .size_full() .child(self.text) .children(self.meta.map(|m| m)) diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index 9f2d174accc9fe5d88210185cb1d494306f17290..ebeed25ea839b4cb33b8405e60751a8868bcdf0d 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -177,7 +177,6 @@ impl IconElement { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); let fill = self.color.color(cx); let svg_size = match self.size { IconSize::Small => ui_size(cx, 12. / 14.), diff --git a/crates/ui2/src/elements/input.rs b/crates/ui2/src/elements/input.rs index eb2bdcdc25c2c23be1aae5ba663f4f5e3a46d53c..af0e73c9eb41d1a19467bcf0d8805166afbc654d 100644 --- a/crates/ui2/src/elements/input.rs +++ b/crates/ui2/src/elements/input.rs @@ -61,18 +61,18 @@ impl Input { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); let (input_bg, input_hover_bg, input_active_bg) = match self.variant { InputVariant::Ghost => ( - color.ghost_element, - color.ghost_element_hover, - color.ghost_element_active, + theme.ghost_element, + theme.ghost_element_hover, + theme.ghost_element_active, ), InputVariant::Filled => ( - color.filled_element, - color.filled_element_hover, - color.filled_element_active, + theme.filled_element, + theme.filled_element_hover, + theme.filled_element_active, ), }; @@ -94,7 +94,7 @@ impl Input { .w_full() .px_2() .border() - .border_color(color.transparent) + .border_color(theme.transparent) .bg(input_bg) .hover(|style| style.bg(input_hover_bg)) .active(|style| style.bg(input_active_bg)) diff --git a/crates/ui2/src/elements/label.rs b/crates/ui2/src/elements/label.rs index bea301c1c2166c84844c0c9807e21c6d2ba30191..81219206a996013d97efe7f6b577d2088b84843d 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -22,20 +22,20 @@ pub enum LabelColor { impl LabelColor { pub fn hsla(&self, cx: &WindowContext) -> Hsla { - let color = ThemeColor::new(cx); + let theme = theme(cx); // TODO: Remove - let theme = old_theme(cx); + let old_theme = old_theme(cx); match self { - Self::Default => color.text, - Self::Muted => color.text_muted, - Self::Created => theme.middle.positive.default.foreground, - Self::Modified => theme.middle.warning.default.foreground, - Self::Deleted => theme.middle.negative.default.foreground, - Self::Disabled => color.text_disabled, - Self::Hidden => theme.middle.variant.default.foreground, - Self::Placeholder => color.text_placeholder, - Self::Accent => theme.middle.accent.default.foreground, + Self::Default => theme.text, + Self::Muted => theme.text_muted, + Self::Created => old_theme.middle.positive.default.foreground, + Self::Modified => old_theme.middle.warning.default.foreground, + Self::Deleted => old_theme.middle.negative.default.foreground, + Self::Disabled => theme.text_disabled, + Self::Hidden => old_theme.middle.variant.default.foreground, + Self::Placeholder => theme.text_placeholder, + Self::Accent => old_theme.middle.accent.default.foreground, } } } @@ -84,8 +84,6 @@ impl Label { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); - div() .when(self.strikethrough, |this| { this.relative().child( @@ -138,9 +136,9 @@ impl HighlightedLabel { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); - let highlight_color = color.text_accent; + let highlight_color = theme.text_accent; let mut highlight_indices = self.highlight_indices.iter().copied().peekable(); diff --git a/crates/ui2/src/elements/player.rs b/crates/ui2/src/elements/player.rs index 2d1bbc1ce419146ae14415cf2042f094de259762..6d22f0e3b2c9367c0e9938ad008422f3a1fa5445 100644 --- a/crates/ui2/src/elements/player.rs +++ b/crates/ui2/src/elements/player.rs @@ -1,6 +1,6 @@ use gpui2::{Hsla, ViewContext}; -use crate::ThemeColor; +use crate::theme; #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] pub enum PlayerStatus { @@ -139,15 +139,13 @@ impl Player { } pub fn cursor_color(&self, cx: &mut ViewContext) -> Hsla { - let color = ThemeColor::new(cx); - let index = self.index % 8; - color.player[self.index].cursor + let theme = theme(cx); + theme.player[self.index].cursor } pub fn selection_color(&self, cx: &mut ViewContext) -> Hsla { - let color = ThemeColor::new(cx); - let index = self.index % 8; - color.player[self.index].selection + let theme = theme(cx); + theme.player[self.index].selection } pub fn avatar_src(&self) -> &str { diff --git a/crates/ui2/src/elements/tool_divider.rs b/crates/ui2/src/elements/tool_divider.rs index 7316b22c4ce9361614ba453bf4aed0cdb2a537e4..68b97ccb035c9c43be3793ed040a245a07e078b7 100644 --- a/crates/ui2/src/elements/tool_divider.rs +++ b/crates/ui2/src/elements/tool_divider.rs @@ -15,8 +15,8 @@ impl ToolDivider { } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); - div().w_px().h_3().bg(color.border) + div().w_px().h_3().bg(theme.border) } } diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index 8b8ad30b919bb2595dc9a2a12636cbd53e703518..099f3c4f908c5895d3a8d2b3d3e4c7992d2f17fe 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -6,7 +6,7 @@ pub use gpui2::{ pub use crate::color::*; pub use crate::elevation::*; use crate::settings::user_settings; -pub use crate::{old_theme, ButtonVariant, ElementExt, Theme}; +pub use crate::{old_theme, theme, ButtonVariant, ElementExt, Theme}; use gpui2::{rems, Hsla, Rems}; use strum::EnumIter; @@ -61,15 +61,15 @@ impl GitStatus { } pub fn hsla(&self, cx: &WindowContext) -> Hsla { - let color = ThemeColor::new(cx); + let theme = theme(cx); match self { - Self::None => color.transparent, - Self::Created => color.git_created, - Self::Modified => color.git_modified, - Self::Deleted => color.git_deleted, - Self::Conflict => color.git_conflict, - Self::Renamed => color.git_renamed, + Self::None => theme.transparent, + Self::Created => theme.git_created, + Self::Modified => theme.git_modified, + Self::Deleted => theme.git_deleted, + Self::Conflict => theme.git_conflict, + Self::Renamed => theme.git_renamed, } } } diff --git a/crates/ui2/src/static_data.rs b/crates/ui2/src/static_data.rs index c01389d004739fab188a09ced31a4e630fc86334..82ab7da0e4cbc435e03334a20bdee78b68be5903 100644 --- a/crates/ui2/src/static_data.rs +++ b/crates/ui2/src/static_data.rs @@ -3,12 +3,13 @@ use std::str::FromStr; use gpui2::WindowContext; use rand::Rng; +use theme2::Theme; use crate::{ - Buffer, BufferRow, BufferRows, Button, EditorPane, FileSystemStatus, GitStatus, + theme, Buffer, BufferRow, BufferRows, Button, EditorPane, FileSystemStatus, GitStatus, HighlightedLine, Icon, Keybinding, Label, LabelColor, ListEntry, ListEntrySize, ListItem, Livestream, MicStatus, ModifierKeys, PaletteItem, Player, PlayerCallStatus, - PlayerWithCallStatus, ScreenShareStatus, Symbol, Tab, ThemeColor, ToggleState, VideoStatus, + PlayerWithCallStatus, ScreenShareStatus, Symbol, Tab, ToggleState, VideoStatus, }; use crate::{HighlightedText, ListDetailsEntry}; @@ -642,7 +643,7 @@ pub fn empty_buffer_example() -> Buffer { } pub fn hello_world_rust_editor_example(cx: &mut WindowContext) -> EditorPane { - let color = ThemeColor::new(cx); + let theme = theme(cx); EditorPane::new( cx, @@ -651,19 +652,19 @@ pub fn hello_world_rust_editor_example(cx: &mut WindowContext) -> EditorPane { vec![Symbol(vec![ HighlightedText { text: "fn ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "main".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, ])], - hello_world_rust_buffer_example(&color), + hello_world_rust_buffer_example(&theme), ) } pub fn hello_world_rust_buffer_example( - color: &ThemeColor, + theme: &Theme, ) -> Buffer { Buffer::new("hello-world-rust-buffer") .set_title("hello_world.rs".to_string()) @@ -671,11 +672,11 @@ pub fn hello_world_rust_buffer_example( .set_language("rust".to_string()) .set_rows(Some(BufferRows { show_line_numbers: true, - rows: hello_world_rust_buffer_rows(color), + rows: hello_world_rust_buffer_rows(theme), })) } -pub fn hello_world_rust_buffer_rows(color: &ThemeColor) -> Vec { +pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec { let show_line_number = true; vec![ @@ -687,15 +688,15 @@ pub fn hello_world_rust_buffer_rows(color: &ThemeColor) -> Vec { highlighted_texts: vec![ HighlightedText { text: "fn ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "main".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, HighlightedText { text: "() {".to_string(), - color: color.text, + color: theme.text, }, ], }), @@ -711,7 +712,7 @@ pub fn hello_world_rust_buffer_rows(color: &ThemeColor) -> Vec { highlighted_texts: vec![HighlightedText { text: " // Statements here are executed when the compiled binary is called." .to_string(), - color: color.syntax.comment, + color: theme.syntax.comment, }], }), cursors: None, @@ -734,7 +735,7 @@ pub fn hello_world_rust_buffer_rows(color: &ThemeColor) -> Vec { line: Some(HighlightedLine { highlighted_texts: vec![HighlightedText { text: " // Print text to the console.".to_string(), - color: color.syntax.comment, + color: theme.syntax.comment, }], }), cursors: None, @@ -749,15 +750,15 @@ pub fn hello_world_rust_buffer_rows(color: &ThemeColor) -> Vec { highlighted_texts: vec![ HighlightedText { text: " println!(".to_string(), - color: color.text, + color: theme.text, }, HighlightedText { text: "\"Hello, world!\"".to_string(), - color: color.syntax.string, + color: theme.syntax.string, }, HighlightedText { text: ");".to_string(), - color: color.text, + color: theme.text, }, ], }), @@ -772,7 +773,7 @@ pub fn hello_world_rust_buffer_rows(color: &ThemeColor) -> Vec { line: Some(HighlightedLine { highlighted_texts: vec![HighlightedText { text: "}".to_string(), - color: color.text, + color: theme.text, }], }), cursors: None, @@ -783,7 +784,7 @@ pub fn hello_world_rust_buffer_rows(color: &ThemeColor) -> Vec { } pub fn hello_world_rust_editor_with_status_example(cx: &mut WindowContext) -> EditorPane { - let color = ThemeColor::new(cx); + let theme = theme(cx); EditorPane::new( cx, @@ -792,19 +793,19 @@ pub fn hello_world_rust_editor_with_status_example(cx: &mut WindowContext) -> Ed vec![Symbol(vec![ HighlightedText { text: "fn ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "main".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, ])], - hello_world_rust_buffer_with_status_example(&color), + hello_world_rust_buffer_with_status_example(&theme), ) } pub fn hello_world_rust_buffer_with_status_example( - color: &ThemeColor, + theme: &Theme, ) -> Buffer { Buffer::new("hello-world-rust-buffer-with-status") .set_title("hello_world.rs".to_string()) @@ -812,11 +813,11 @@ pub fn hello_world_rust_buffer_with_status_example Vec { +pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec { let show_line_number = true; vec![ @@ -828,15 +829,15 @@ pub fn hello_world_rust_with_status_buffer_rows(color: &ThemeColor) -> Vec Vec Vec Vec Vec Vec Vec Vec(color: &ThemeColor) -> Buffer { +pub fn terminal_buffer(theme: &Theme) -> Buffer { Buffer::new("terminal") .set_title("zed — fish".to_string()) .set_rows(Some(BufferRows { show_line_numbers: false, - rows: terminal_buffer_rows(color), + rows: terminal_buffer_rows(theme), })) } -pub fn terminal_buffer_rows(color: &ThemeColor) -> Vec { +pub fn terminal_buffer_rows(theme: &Theme) -> Vec { let show_line_number = false; vec![ @@ -972,31 +973,31 @@ pub fn terminal_buffer_rows(color: &ThemeColor) -> Vec { highlighted_texts: vec![ HighlightedText { text: "maxdeviant ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, HighlightedText { text: "in ".to_string(), - color: color.text, + color: theme.text, }, HighlightedText { text: "profaned-capital ".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, HighlightedText { text: "in ".to_string(), - color: color.text, + color: theme.text, }, HighlightedText { text: "~/p/zed ".to_string(), - color: color.syntax.function, + color: theme.syntax.function, }, HighlightedText { text: "on ".to_string(), - color: color.text, + color: theme.text, }, HighlightedText { text: " gpui2-ui ".to_string(), - color: color.syntax.keyword, + color: theme.syntax.keyword, }, ], }), @@ -1011,7 +1012,7 @@ pub fn terminal_buffer_rows(color: &ThemeColor) -> Vec { line: Some(HighlightedLine { highlighted_texts: vec![HighlightedText { text: "λ ".to_string(), - color: color.syntax.string, + color: theme.syntax.string, }], }), cursors: None, diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rs index e2f0e1184d134df7a7c9df019968b227c4c201e3..7a5358dfed1fb3b7f8d6105929c9d02681b99958 100644 --- a/crates/ui2/src/story.rs +++ b/crates/ui2/src/story.rs @@ -6,7 +6,7 @@ pub struct Story {} impl Story { pub fn container(cx: &mut ViewContext) -> Div { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() .size_full() @@ -15,18 +15,18 @@ impl Story { .pt_2() .px_4() .font("Zed Mono") - .bg(color.background) + .bg(theme.background) } pub fn title( cx: &mut ViewContext, title: &str, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() .text_xl() - .text_color(color.text) + .text_color(theme.text) .child(title.to_owned()) } @@ -40,13 +40,13 @@ impl Story { cx: &mut ViewContext, label: &str, ) -> impl Element { - let color = ThemeColor::new(cx); + let theme = theme(cx); div() .mt_4() .mb_2() .text_xs() - .text_color(color.text) + .text_color(theme.text) .child(label.to_owned()) } }