Combine LabelColor and IconColor into TextColor

This commit is contained in:
Marshall Bowers 2023-11-14 13:48:01 -05:00
parent dc56a7b12b
commit 76c15229c1
25 changed files with 152 additions and 220 deletions

View file

@ -2,10 +2,8 @@ use std::sync::Arc;
use gpui::{div, DefiniteLength, Hsla, MouseButton, WindowContext};
use crate::{
h_stack, prelude::*, Icon, IconButton, IconColor, IconElement, Label, LabelColor,
LineHeightStyle,
};
use crate::prelude::*;
use crate::{h_stack, Icon, IconButton, IconElement, Label, LineHeightStyle, TextColor};
/// Provides the flexibility to use either a standard
/// button or an icon button in a given context.
@ -87,7 +85,7 @@ pub struct Button<V: 'static> {
label: SharedString,
variant: ButtonVariant,
width: Option<DefiniteLength>,
color: Option<LabelColor>,
color: Option<TextColor>,
}
impl<V: 'static> Button<V> {
@ -141,14 +139,14 @@ impl<V: 'static> Button<V> {
self
}
pub fn color(mut self, color: Option<LabelColor>) -> Self {
pub fn color(mut self, color: Option<TextColor>) -> Self {
self.color = color;
self
}
pub fn label_color(&self, color: Option<LabelColor>) -> LabelColor {
pub fn label_color(&self, color: Option<TextColor>) -> TextColor {
if self.disabled {
LabelColor::Disabled
TextColor::Disabled
} else if let Some(color) = color {
color
} else {
@ -156,21 +154,21 @@ impl<V: 'static> Button<V> {
}
}
fn render_label(&self, color: LabelColor) -> Label {
fn render_label(&self, color: TextColor) -> Label {
Label::new(self.label.clone())
.color(color)
.line_height_style(LineHeightStyle::UILabel)
}
fn render_icon(&self, icon_color: IconColor) -> Option<IconElement> {
fn render_icon(&self, icon_color: TextColor) -> Option<IconElement> {
self.icon.map(|i| IconElement::new(i).color(icon_color))
}
pub fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let (icon_color, label_color) = match (self.disabled, self.color) {
(true, _) => (IconColor::Disabled, LabelColor::Disabled),
(_, None) => (IconColor::Default, LabelColor::Default),
(_, Some(color)) => (IconColor::from(color), color),
(true, _) => (TextColor::Disabled, TextColor::Disabled),
(_, None) => (TextColor::Default, TextColor::Default),
(_, Some(color)) => (TextColor::from(color), color),
};
let mut button = h_stack()
@ -240,7 +238,7 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use super::*;
use crate::{h_stack, v_stack, LabelColor, Story};
use crate::{h_stack, v_stack, Story, TextColor};
use gpui::{rems, Div, Render};
use strum::IntoEnumIterator;
@ -265,7 +263,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label").variant(ButtonVariant::Ghost), // .state(state),
@ -276,7 +274,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label")
@ -290,7 +288,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label")
@ -307,7 +305,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label").variant(ButtonVariant::Filled), // .state(state),
@ -318,7 +316,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label")
@ -332,7 +330,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label")
@ -349,7 +347,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label")
@ -363,7 +361,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label")
@ -379,7 +377,7 @@ mod stories {
v_stack()
.gap_1()
.child(
Label::new(state.to_string()).color(LabelColor::Muted),
Label::new(state.to_string()).color(TextColor::Muted),
)
.child(
Button::new("Label")

View file

@ -6,7 +6,7 @@ use gpui::{
};
use theme2::ActiveTheme;
use crate::{Icon, IconColor, IconElement, Selection};
use crate::{Icon, IconElement, Selection, TextColor};
pub type CheckHandler<V> = Arc<dyn Fn(Selection, &mut V, &mut ViewContext<V>) + Send + Sync>;
@ -58,9 +58,9 @@ impl<V: 'static> Checkbox<V> {
.color(
// If the checkbox is disabled we change the color of the icon.
if self.disabled {
IconColor::Disabled
TextColor::Disabled
} else {
IconColor::Selected
TextColor::Selected
},
),
)
@ -73,9 +73,9 @@ impl<V: 'static> Checkbox<V> {
.color(
// If the checkbox is disabled we change the color of the icon.
if self.disabled {
IconColor::Disabled
TextColor::Disabled
} else {
IconColor::Selected
TextColor::Selected
},
),
)

View file

@ -1,7 +1,7 @@
use gpui::{rems, svg, Hsla};
use gpui::{rems, svg};
use strum::EnumIter;
use crate::{prelude::*, LabelColor};
use crate::prelude::*;
#[derive(Default, PartialEq, Copy, Clone)]
pub enum IconSize {
@ -10,70 +10,6 @@ pub enum IconSize {
Medium,
}
#[derive(Default, PartialEq, Copy, Clone)]
pub enum IconColor {
#[default]
Default,
Accent,
Created,
Deleted,
Disabled,
Error,
Hidden,
Info,
Modified,
Muted,
Placeholder,
Player(u32),
Selected,
Success,
Warning,
}
impl IconColor {
pub fn color(self, cx: &WindowContext) -> Hsla {
match self {
IconColor::Default => cx.theme().colors().icon,
IconColor::Muted => cx.theme().colors().icon_muted,
IconColor::Disabled => cx.theme().colors().icon_disabled,
IconColor::Placeholder => cx.theme().colors().icon_placeholder,
IconColor::Accent => cx.theme().colors().icon_accent,
IconColor::Error => cx.theme().status().error,
IconColor::Warning => cx.theme().status().warning,
IconColor::Success => cx.theme().status().success,
IconColor::Info => cx.theme().status().info,
IconColor::Selected => cx.theme().colors().icon_accent,
IconColor::Player(i) => cx.theme().styles.player.0[i.clone() as usize].cursor,
IconColor::Created => cx.theme().status().created,
IconColor::Modified => cx.theme().status().modified,
IconColor::Deleted => cx.theme().status().deleted,
IconColor::Hidden => cx.theme().status().hidden,
}
}
}
impl From<LabelColor> for IconColor {
fn from(label: LabelColor) -> Self {
match label {
LabelColor::Default => IconColor::Default,
LabelColor::Muted => IconColor::Muted,
LabelColor::Disabled => IconColor::Disabled,
LabelColor::Placeholder => IconColor::Placeholder,
LabelColor::Accent => IconColor::Accent,
LabelColor::Error => IconColor::Error,
LabelColor::Warning => IconColor::Warning,
LabelColor::Success => IconColor::Success,
LabelColor::Info => IconColor::Info,
LabelColor::Selected => IconColor::Selected,
LabelColor::Player(i) => IconColor::Player(i),
LabelColor::Created => IconColor::Created,
LabelColor::Modified => IconColor::Modified,
LabelColor::Deleted => IconColor::Deleted,
LabelColor::Hidden => IconColor::Hidden,
}
}
}
#[derive(Debug, PartialEq, Copy, Clone, EnumIter)]
pub enum Icon {
Ai,
@ -194,7 +130,7 @@ impl Icon {
#[derive(Component)]
pub struct IconElement {
icon: Icon,
color: IconColor,
color: TextColor,
size: IconSize,
}
@ -202,12 +138,12 @@ impl IconElement {
pub fn new(icon: Icon) -> Self {
Self {
icon,
color: IconColor::default(),
color: TextColor::default(),
size: IconSize::default(),
}
}
pub fn color(mut self, color: IconColor) -> Self {
pub fn color(mut self, color: TextColor) -> Self {
self.color = color;
self
}

View file

@ -1,4 +1,4 @@
use crate::{h_stack, prelude::*, ClickHandler, Icon, IconColor, IconElement, TextTooltip};
use crate::{h_stack, prelude::*, ClickHandler, Icon, IconElement, TextColor, TextTooltip};
use gpui::{MouseButton, VisualContext};
use std::sync::Arc;
@ -16,7 +16,7 @@ impl<V: 'static> Default for IconButtonHandlers<V> {
pub struct IconButton<V: 'static> {
id: ElementId,
icon: Icon,
color: IconColor,
color: TextColor,
variant: ButtonVariant,
state: InteractionState,
tooltip: Option<SharedString>,
@ -28,7 +28,7 @@ impl<V: 'static> IconButton<V> {
Self {
id: id.into(),
icon,
color: IconColor::default(),
color: TextColor::default(),
variant: ButtonVariant::default(),
state: InteractionState::default(),
tooltip: None,
@ -41,7 +41,7 @@ impl<V: 'static> IconButton<V> {
self
}
pub fn color(mut self, color: IconColor) -> Self {
pub fn color(mut self, color: TextColor) -> Self {
self.color = color;
self
}
@ -71,7 +71,7 @@ impl<V: 'static> IconButton<V> {
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let icon_color = match (self.state, self.color) {
(InteractionState::Disabled, _) => IconColor::Disabled,
(InteractionState::Disabled, _) => TextColor::Disabled,
_ => self.color,
};

View file

@ -1,6 +1,6 @@
use crate::prelude::*;
use crate::Label;
use crate::LabelColor;
use crate::TextColor;
#[derive(Default, PartialEq)]
pub enum InputVariant {
@ -71,15 +71,15 @@ impl Input {
};
let placeholder_label = Label::new(self.placeholder.clone()).color(if self.disabled {
LabelColor::Disabled
TextColor::Disabled
} else {
LabelColor::Placeholder
TextColor::Placeholder
});
let label = Label::new(self.value.clone()).color(if self.disabled {
LabelColor::Disabled
TextColor::Disabled
} else {
LabelColor::Default
TextColor::Default
});
div()

View file

@ -11,7 +11,7 @@ pub enum LabelSize {
}
#[derive(Default, PartialEq, Copy, Clone)]
pub enum LabelColor {
pub enum TextColor {
#[default]
Default,
Accent,
@ -30,24 +30,24 @@ pub enum LabelColor {
Warning,
}
impl LabelColor {
pub fn hsla(&self, cx: &WindowContext) -> Hsla {
impl TextColor {
pub fn color(&self, cx: &WindowContext) -> Hsla {
match self {
LabelColor::Default => cx.theme().colors().text,
LabelColor::Muted => cx.theme().colors().text_muted,
LabelColor::Created => cx.theme().status().created,
LabelColor::Modified => cx.theme().status().modified,
LabelColor::Deleted => cx.theme().status().deleted,
LabelColor::Disabled => cx.theme().colors().text_disabled,
LabelColor::Hidden => cx.theme().status().hidden,
LabelColor::Info => cx.theme().status().info,
LabelColor::Placeholder => cx.theme().colors().text_placeholder,
LabelColor::Accent => cx.theme().colors().text_accent,
LabelColor::Player(i) => cx.theme().styles.player.0[i.clone() as usize].cursor,
LabelColor::Error => cx.theme().status().error,
LabelColor::Selected => cx.theme().colors().text_accent,
LabelColor::Success => cx.theme().status().success,
LabelColor::Warning => cx.theme().status().warning,
TextColor::Default => cx.theme().colors().text,
TextColor::Muted => cx.theme().colors().text_muted,
TextColor::Created => cx.theme().status().created,
TextColor::Modified => cx.theme().status().modified,
TextColor::Deleted => cx.theme().status().deleted,
TextColor::Disabled => cx.theme().colors().text_disabled,
TextColor::Hidden => cx.theme().status().hidden,
TextColor::Info => cx.theme().status().info,
TextColor::Placeholder => cx.theme().colors().text_placeholder,
TextColor::Accent => cx.theme().colors().text_accent,
TextColor::Player(i) => cx.theme().styles.player.0[i.clone() as usize].cursor,
TextColor::Error => cx.theme().status().error,
TextColor::Selected => cx.theme().colors().text_accent,
TextColor::Success => cx.theme().status().success,
TextColor::Warning => cx.theme().status().warning,
}
}
}
@ -65,7 +65,7 @@ pub struct Label {
label: SharedString,
size: LabelSize,
line_height_style: LineHeightStyle,
color: LabelColor,
color: TextColor,
strikethrough: bool,
}
@ -75,7 +75,7 @@ impl Label {
label: label.into(),
size: LabelSize::Default,
line_height_style: LineHeightStyle::default(),
color: LabelColor::Default,
color: TextColor::Default,
strikethrough: false,
}
}
@ -85,7 +85,7 @@ impl Label {
self
}
pub fn color(mut self, color: LabelColor) -> Self {
pub fn color(mut self, color: TextColor) -> Self {
self.color = color;
self
}
@ -109,7 +109,7 @@ impl Label {
.top_1_2()
.w_full()
.h_px()
.bg(LabelColor::Hidden.hsla(cx)),
.bg(TextColor::Hidden.color(cx)),
)
})
.map(|this| match self.size {
@ -119,7 +119,7 @@ impl Label {
.when(self.line_height_style == LineHeightStyle::UILabel, |this| {
this.line_height(relative(1.))
})
.text_color(self.color.hsla(cx))
.text_color(self.color.color(cx))
.child(self.label.clone())
}
}
@ -128,7 +128,7 @@ impl Label {
pub struct HighlightedLabel {
label: SharedString,
size: LabelSize,
color: LabelColor,
color: TextColor,
highlight_indices: Vec<usize>,
strikethrough: bool,
}
@ -140,7 +140,7 @@ impl HighlightedLabel {
Self {
label: label.into(),
size: LabelSize::Default,
color: LabelColor::Default,
color: TextColor::Default,
highlight_indices,
strikethrough: false,
}
@ -151,7 +151,7 @@ impl HighlightedLabel {
self
}
pub fn color(mut self, color: LabelColor) -> Self {
pub fn color(mut self, color: TextColor) -> Self {
self.color = color;
self
}
@ -170,7 +170,7 @@ impl HighlightedLabel {
let mut runs: Vec<TextRun> = Vec::new();
for (char_ix, char) in self.label.char_indices() {
let mut color = self.color.hsla(cx);
let mut color = self.color.color(cx);
if let Some(highlight_ix) = highlight_indices.peek() {
if char_ix == *highlight_ix {
@ -207,7 +207,7 @@ impl HighlightedLabel {
.my_auto()
.w_full()
.h_px()
.bg(LabelColor::Hidden.hsla(cx)),
.bg(TextColor::Hidden.color(cx)),
)
})
.map(|this| match self.size {

View file

@ -1,11 +1,11 @@
use gpui::div;
use crate::prelude::*;
use crate::settings::user_settings;
use crate::{
disclosure_control, h_stack, v_stack, Avatar, Icon, IconColor, IconElement, IconSize, Label,
LabelColor, Toggle,
disclosure_control, h_stack, v_stack, Avatar, GraphicSlot, Icon, IconElement, IconSize, Label,
TextColor, Toggle,
};
use crate::{prelude::*, GraphicSlot};
#[derive(Clone, Copy, Default, Debug, PartialEq)]
pub enum ListItemVariant {
@ -68,7 +68,7 @@ impl ListHeader {
.items_center()
.children(icons.into_iter().map(|i| {
IconElement::new(i)
.color(IconColor::Muted)
.color(TextColor::Muted)
.size(IconSize::Small)
})),
),
@ -106,10 +106,10 @@ impl ListHeader {
.items_center()
.children(self.left_icon.map(|i| {
IconElement::new(i)
.color(IconColor::Muted)
.color(TextColor::Muted)
.size(IconSize::Small)
}))
.child(Label::new(self.label.clone()).color(LabelColor::Muted)),
.child(Label::new(self.label.clone()).color(TextColor::Muted)),
)
.child(disclosure_control),
)
@ -157,10 +157,10 @@ impl ListSubHeader {
.items_center()
.children(self.left_icon.map(|i| {
IconElement::new(i)
.color(IconColor::Muted)
.color(TextColor::Muted)
.size(IconSize::Small)
}))
.child(Label::new(self.label.clone()).color(LabelColor::Muted)),
.child(Label::new(self.label.clone()).color(TextColor::Muted)),
),
)
}
@ -291,7 +291,7 @@ impl ListEntry {
h_stack().child(
IconElement::new(i)
.size(IconSize::Small)
.color(IconColor::Muted),
.color(TextColor::Muted),
),
),
Some(GraphicSlot::Avatar(src)) => Some(h_stack().child(Avatar::new(src))),
@ -394,7 +394,7 @@ impl List {
(false, _) => div().children(self.items),
(true, Toggle::Toggled(false)) => div(),
(true, _) => {
div().child(Label::new(self.empty_message.clone()).color(LabelColor::Muted))
div().child(Label::new(self.empty_message.clone()).color(TextColor::Muted))
}
};

View file

@ -1,5 +1,5 @@
use crate::prelude::*;
use crate::{h_stack, v_stack, KeyBinding, Label, LabelColor};
use crate::{h_stack, v_stack, KeyBinding, Label, TextColor};
#[derive(Component)]
pub struct Palette {
@ -54,7 +54,7 @@ impl Palette {
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),
Label::new(self.input_placeholder.clone()).color(TextColor::Placeholder),
)))
.child(
div()
@ -75,7 +75,7 @@ impl Palette {
Some(
h_stack().justify_between().px_2().py_1().child(
Label::new(self.empty_string.clone())
.color(LabelColor::Muted),
.color(TextColor::Muted),
),
)
} else {

View file

@ -1,5 +1,5 @@
use crate::prelude::*;
use crate::{Icon, IconColor, IconElement, Label, LabelColor};
use crate::{Icon, IconElement, Label, TextColor};
use gpui::{red, Div, ElementId, Render, View, VisualContext};
#[derive(Component, Clone)]
@ -92,20 +92,18 @@ impl Tab {
let label = match (self.git_status, is_deleted) {
(_, true) | (GitStatus::Deleted, false) => Label::new(self.title.clone())
.color(LabelColor::Hidden)
.color(TextColor::Hidden)
.set_strikethrough(true),
(GitStatus::None, false) => Label::new(self.title.clone()),
(GitStatus::Created, false) => {
Label::new(self.title.clone()).color(LabelColor::Created)
}
(GitStatus::Created, false) => Label::new(self.title.clone()).color(TextColor::Created),
(GitStatus::Modified, false) => {
Label::new(self.title.clone()).color(LabelColor::Modified)
Label::new(self.title.clone()).color(TextColor::Modified)
}
(GitStatus::Renamed, false) => Label::new(self.title.clone()).color(LabelColor::Accent),
(GitStatus::Renamed, false) => Label::new(self.title.clone()).color(TextColor::Accent),
(GitStatus::Conflict, false) => Label::new(self.title.clone()),
};
let close_icon = || IconElement::new(Icon::Close).color(IconColor::Muted);
let close_icon = || IconElement::new(Icon::Close).color(TextColor::Muted);
let (tab_bg, tab_hover_bg, tab_active_bg) = match self.current {
false => (
@ -148,7 +146,7 @@ impl Tab {
.children(has_fs_conflict.then(|| {
IconElement::new(Icon::ExclamationTriangle)
.size(crate::IconSize::Small)
.color(IconColor::Warning)
.color(TextColor::Warning)
}))
.children(self.icon.map(IconElement::new))
.children(if self.close_side == IconSide::Left {

View file

@ -1,6 +1,6 @@
use gpui::{div, Component, ParentElement};
use crate::{Icon, IconColor, IconElement, IconSize};
use crate::{Icon, IconElement, IconSize, TextColor};
/// Whether the entry is toggleable, and if so, whether it is currently toggled.
///
@ -49,12 +49,12 @@ pub fn disclosure_control<V: 'static>(toggle: Toggle) -> impl Component<V> {
(false, _) => div(),
(_, true) => div().child(
IconElement::new(Icon::ChevronDown)
.color(IconColor::Muted)
.color(TextColor::Muted)
.size(IconSize::Small),
),
(_, false) => div().child(
IconElement::new(Icon::ChevronRight)
.color(IconColor::Muted)
.color(TextColor::Muted)
.size(IconSize::Small),
),
}

View file

@ -1,8 +1,8 @@
use gpui::{Div, Render};
use theme2::ActiveTheme;
use crate::{h_stack, v_stack, KeyBinding, Label, LabelColor, StyledExt};
use crate::{prelude::*, LabelSize};
use crate::prelude::*;
use crate::{h_stack, v_stack, KeyBinding, Label, LabelSize, StyledExt, TextColor};
pub struct TextTooltip {
title: SharedString,
@ -52,7 +52,7 @@ impl Render for TextTooltip {
this.child(
Label::new(meta)
.size(LabelSize::Small)
.color(LabelColor::Muted),
.color(TextColor::Muted),
)
})
}