Remove ThemeColor in favor of theme2::Theme

This commit is contained in:
Marshall Bowers 2023-10-25 16:32:44 +02:00
parent bb3f59252e
commit e1032c5341
42 changed files with 225 additions and 391 deletions

View file

@ -26,7 +26,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let color = ThemeColor::new(cx);
let theme = theme(cx);
let mut img = img();
@ -38,7 +38,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
img.uri(self.src.clone())
.size_4()
.bg(color.image_fallback_background)
.bg(theme.image_fallback_background)
}
}

View file

@ -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<S: 'static + Send + Sync> Button<S> {
_view: &mut S,
cx: &mut ViewContext<S>,
) -> impl Element<ViewState = S> {
let color = ThemeColor::new(cx);
let settings = user_settings(cx);
let icon_color = self.icon_color();
let mut button = h_stack()

View file

@ -31,13 +31,13 @@ impl<S: 'static + Send + Sync> Details<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
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))

View file

@ -177,7 +177,6 @@ impl<S: 'static + Send + Sync> IconElement<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let color = ThemeColor::new(cx);
let fill = self.color.color(cx);
let svg_size = match self.size {
IconSize::Small => ui_size(cx, 12. / 14.),

View file

@ -61,18 +61,18 @@ impl<S: 'static + Send + Sync> Input<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
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<S: 'static + Send + Sync> Input<S> {
.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))

View file

@ -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<S: 'static + Send + Sync> Label<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let color = ThemeColor::new(cx);
div()
.when(self.strikethrough, |this| {
this.relative().child(
@ -138,9 +136,9 @@ impl<S: 'static + Send + Sync> HighlightedLabel<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
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();

View file

@ -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<S: 'static>(&self, cx: &mut ViewContext<S>) -> 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<S: 'static>(&self, cx: &mut ViewContext<S>) -> 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 {

View file

@ -15,8 +15,8 @@ impl<S: 'static + Send + Sync> ToolDivider<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
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)
}
}