TextColor -> Color

This commit is contained in:
Nate Butler
2023-11-21 01:05:29 -05:00
parent 56d45e72cd
commit 453aa5ffd7
24 changed files with 148 additions and 148 deletions
+2
View File
@@ -2,6 +2,7 @@ mod avatar;
mod button;
mod checkbox;
mod context_menu;
mod disclosure;
mod divider;
mod icon;
mod icon_button;
@@ -19,6 +20,7 @@ pub use avatar::*;
pub use button::*;
pub use checkbox::*;
pub use context_menu::*;
pub use disclosure::*;
pub use divider::*;
pub use icon::*;
pub use icon_button::*;
+10 -10
View File
@@ -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<DefiniteLength>,
color: Option<TextColor>,
color: Option<Color>,
}
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<TextColor>) -> Self {
pub fn color(mut self, color: Option<Color>) -> Self {
self.color = color;
self
}
pub fn label_color(&self, color: Option<TextColor>) -> TextColor {
pub fn label_color(&self, color: Option<Color>) -> 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<IconElement> {
fn render_icon(&self, icon_color: Color) -> Option<IconElement> {
self.icon.map(|i| IconElement::new(i).color(icon_color))
}
}
+9 -9
View File
@@ -2,7 +2,7 @@ use gpui::{div, prelude::*, Div, Element, ElementId, RenderOnce, Styled, WindowC
use theme2::ActiveTheme;
use crate::{Icon, IconElement, Selection, TextColor};
use crate::{Color, Icon, IconElement, Selection};
pub type CheckHandler = Box<dyn Fn(&Selection, &mut WindowContext) + 'static>;
@@ -34,9 +34,9 @@ impl Component for Checkbox {
.color(
// If the checkbox is disabled we change the color of the icon.
if self.disabled {
TextColor::Disabled
Color::Disabled
} else {
TextColor::Selected
Color::Selected
},
),
)
@@ -49,9 +49,9 @@ impl Component for Checkbox {
.color(
// If the checkbox is disabled we change the color of the icon.
if self.disabled {
TextColor::Disabled
Color::Disabled
} else {
TextColor::Selected
Color::Selected
},
),
)
@@ -176,9 +176,9 @@ impl Checkbox {
.color(
// If the checkbox is disabled we change the color of the icon.
if self.disabled {
TextColor::Disabled
Color::Disabled
} else {
TextColor::Selected
Color::Selected
},
),
)
@@ -191,9 +191,9 @@ impl Checkbox {
.color(
// If the checkbox is disabled we change the color of the icon.
if self.disabled {
TextColor::Disabled
Color::Disabled
} else {
TextColor::Selected
Color::Selected
},
),
)
+19
View File
@@ -0,0 +1,19 @@
use gpui::{div, Element, ParentElement};
use crate::{Color, Icon, IconElement, IconSize, Toggle};
pub fn disclosure_control(toggle: Toggle) -> impl Element {
match (toggle.is_toggleable(), toggle.is_toggled()) {
(false, _) => div(),
(_, true) => div().child(
IconElement::new(Icon::ChevronDown)
.color(Color::Muted)
.size(IconSize::Small),
),
(_, false) => div().child(
IconElement::new(Icon::ChevronRight)
.color(Color::Muted)
.size(IconSize::Small),
),
}
}
+8 -8
View File
@@ -23,6 +23,7 @@ pub enum Icon {
BellOff,
BellRing,
Bolt,
CaseSensitive,
Check,
ChevronDown,
ChevronLeft,
@@ -65,9 +66,8 @@ pub enum Icon {
Split,
SplitMessage,
Terminal,
XCircle,
WholeWord,
CaseSensitive,
XCircle,
}
impl Icon {
@@ -84,6 +84,7 @@ impl Icon {
Icon::BellOff => "icons/bell-off.svg",
Icon::BellRing => "icons/bell-ring.svg",
Icon::Bolt => "icons/bolt.svg",
Icon::CaseSensitive => "icons/case_insensitive.svg",
Icon::Check => "icons/check.svg",
Icon::ChevronDown => "icons/chevron_down.svg",
Icon::ChevronLeft => "icons/chevron_left.svg",
@@ -126,9 +127,8 @@ impl Icon {
Icon::Split => "icons/split.svg",
Icon::SplitMessage => "icons/split_message.svg",
Icon::Terminal => "icons/terminal.svg",
Icon::XCircle => "icons/error.svg",
Icon::WholeWord => "icons/word_search.svg",
Icon::CaseSensitive => "icons/case_insensitive.svg",
Icon::XCircle => "icons/error.svg",
}
}
}
@@ -136,7 +136,7 @@ impl Icon {
#[derive(RenderOnce)]
pub struct IconElement {
path: SharedString,
color: TextColor,
color: Color,
size: IconSize,
}
@@ -161,7 +161,7 @@ impl IconElement {
pub fn new(icon: Icon) -> Self {
Self {
path: icon.path().into(),
color: TextColor::default(),
color: Color::default(),
size: IconSize::default(),
}
}
@@ -169,12 +169,12 @@ impl IconElement {
pub fn from_path(path: impl Into<SharedString>) -> Self {
Self {
path: path.into(),
color: TextColor::default(),
color: Color::default(),
size: IconSize::default(),
}
}
pub fn color(mut self, color: TextColor) -> Self {
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
+5 -5
View File
@@ -5,7 +5,7 @@ use gpui::{prelude::*, Action, AnyView, Div, MouseButton, MouseDownEvent, Statef
pub struct IconButton {
id: ElementId,
icon: Icon,
color: TextColor,
color: Color,
variant: ButtonVariant,
state: InteractionState,
selected: bool,
@@ -18,8 +18,8 @@ impl Component for IconButton {
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
let icon_color = match (self.state, self.color) {
(InteractionState::Disabled, _) => TextColor::Disabled,
(InteractionState::Active, _) => TextColor::Selected,
(InteractionState::Disabled, _) => Color::Disabled,
(InteractionState::Active, _) => Color::Selected,
_ => self.color,
};
@@ -76,7 +76,7 @@ impl IconButton {
Self {
id: id.into(),
icon,
color: TextColor::default(),
color: Color::default(),
variant: ButtonVariant::default(),
state: InteractionState::default(),
selected: false,
@@ -90,7 +90,7 @@ impl IconButton {
self
}
pub fn color(mut self, color: TextColor) -> Self {
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
+4 -4
View File
@@ -36,15 +36,15 @@ impl Component for Input {
};
let placeholder_label = Label::new(self.placeholder.clone()).color(if self.disabled {
TextColor::Disabled
Color::Disabled
} else {
TextColor::Placeholder
Color::Placeholder
});
let label = Label::new(self.value.clone()).color(if self.disabled {
TextColor::Disabled
Color::Disabled
} else {
TextColor::Default
Color::Default
});
div()
+8 -50
View File
@@ -9,48 +9,6 @@ pub enum LabelSize {
Small,
}
#[derive(Default, PartialEq, Copy, Clone)]
pub enum TextColor {
#[default]
Default,
Accent,
Created,
Deleted,
Disabled,
Error,
Hidden,
Info,
Modified,
Muted,
Placeholder,
Player(u32),
Selected,
Success,
Warning,
}
impl TextColor {
pub fn color(&self, cx: &WindowContext) -> Hsla {
match self {
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,
}
}
}
#[derive(Default, PartialEq, Copy, Clone)]
pub enum LineHeightStyle {
#[default]
@@ -64,7 +22,7 @@ pub struct Label {
label: SharedString,
size: LabelSize,
line_height_style: LineHeightStyle,
color: TextColor,
color: Color,
strikethrough: bool,
}
@@ -80,7 +38,7 @@ impl Component for Label {
.top_1_2()
.w_full()
.h_px()
.bg(TextColor::Hidden.color(cx)),
.bg(Color::Hidden.color(cx)),
)
})
.map(|this| match self.size {
@@ -101,7 +59,7 @@ impl Label {
label: label.into(),
size: LabelSize::Default,
line_height_style: LineHeightStyle::default(),
color: TextColor::Default,
color: Color::Default,
strikethrough: false,
}
}
@@ -111,7 +69,7 @@ impl Label {
self
}
pub fn color(mut self, color: TextColor) -> Self {
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
@@ -131,7 +89,7 @@ impl Label {
pub struct HighlightedLabel {
label: SharedString,
size: LabelSize,
color: TextColor,
color: Color,
highlight_indices: Vec<usize>,
strikethrough: bool,
}
@@ -185,7 +143,7 @@ impl Component for HighlightedLabel {
.my_auto()
.w_full()
.h_px()
.bg(TextColor::Hidden.color(cx)),
.bg(Color::Hidden.color(cx)),
)
})
.map(|this| match self.size {
@@ -203,7 +161,7 @@ impl HighlightedLabel {
Self {
label: label.into(),
size: LabelSize::Default,
color: TextColor::Default,
color: Color::Default,
highlight_indices,
strikethrough: false,
}
@@ -214,7 +172,7 @@ impl HighlightedLabel {
self
}
pub fn color(mut self, color: TextColor) -> Self {
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
+7 -9
View File
@@ -47,7 +47,7 @@ impl Component for ListHeader {
.items_center()
.children(icons.into_iter().map(|i| {
IconElement::new(i)
.color(TextColor::Muted)
.color(Color::Muted)
.size(IconSize::Small)
})),
),
@@ -80,10 +80,10 @@ impl Component for ListHeader {
.items_center()
.children(self.left_icon.map(|i| {
IconElement::new(i)
.color(TextColor::Muted)
.color(Color::Muted)
.size(IconSize::Small)
}))
.child(Label::new(self.label.clone()).color(TextColor::Muted)),
.child(Label::new(self.label.clone()).color(Color::Muted)),
)
.child(disclosure_control),
)
@@ -222,10 +222,10 @@ impl Component for ListSubHeader {
.items_center()
.children(self.left_icon.map(|i| {
IconElement::new(i)
.color(TextColor::Muted)
.color(Color::Muted)
.size(IconSize::Small)
}))
.child(Label::new(self.label.clone()).color(TextColor::Muted)),
.child(Label::new(self.label.clone()).color(Color::Muted)),
),
)
}
@@ -337,7 +337,7 @@ impl Component for ListItem {
h_stack().child(
IconElement::new(i)
.size(IconSize::Small)
.color(TextColor::Muted),
.color(Color::Muted),
),
),
Some(GraphicSlot::Avatar(src)) => Some(h_stack().child(Avatar::new(src))),
@@ -432,9 +432,7 @@ impl Component for List {
let list_content = match (self.children.is_empty(), self.toggle) {
(false, _) => div().children(self.children),
(true, Toggle::Toggled(false)) => div(),
(true, _) => {
div().child(Label::new(self.empty_message.clone()).color(TextColor::Muted))
}
(true, _) => div().child(Label::new(self.empty_message.clone()).color(Color::Muted)),
};
v_stack()
+1 -1
View File
@@ -4,7 +4,7 @@ pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use super::*;
use crate::{h_stack, v_stack, Story, TextColor};
use crate::{h_stack, v_stack, Color, Story};
use gpui::{rems, Div, Render};
use strum::IntoEnumIterator;
-20
View File
@@ -1,7 +1,3 @@
use gpui::{div, Element, ParentElement};
use crate::{Icon, IconElement, IconSize, TextColor};
/// Whether the entry is toggleable, and if so, whether it is currently toggled.
///
/// To make an element toggleable, simply add a `Toggle::Toggled(_)` and handle it's cases.
@@ -43,19 +39,3 @@ impl From<bool> for Toggle {
Toggle::Toggled(toggled)
}
}
pub fn disclosure_control(toggle: Toggle) -> impl Element {
match (toggle.is_toggleable(), toggle.is_toggled()) {
(false, _) => div(),
(_, true) => div().child(
IconElement::new(Icon::ChevronDown)
.color(TextColor::Muted)
.size(IconSize::Small),
),
(_, false) => div().child(
IconElement::new(Icon::ChevronRight)
.color(TextColor::Muted)
.size(IconSize::Small),
),
}
}
+2 -6
View File
@@ -3,7 +3,7 @@ use settings2::Settings;
use theme2::{ActiveTheme, ThemeSettings};
use crate::prelude::*;
use crate::{h_stack, v_stack, KeyBinding, Label, LabelSize, StyledExt, TextColor};
use crate::{h_stack, v_stack, Color, KeyBinding, Label, LabelSize, StyledExt};
pub struct Tooltip {
title: SharedString,
@@ -90,11 +90,7 @@ impl Render for Tooltip {
}),
)
.when_some(self.meta.clone(), |this, meta| {
this.child(
Label::new(meta)
.size(LabelSize::Small)
.color(TextColor::Muted),
)
this.child(Label::new(meta).size(LabelSize::Small).color(Color::Muted))
}),
),
)
+1 -1
View File
@@ -4,7 +4,7 @@ pub use gpui::{
};
pub use crate::StyledExt;
pub use crate::{ButtonVariant, TextColor};
pub use crate::{ButtonVariant, Color};
pub use theme2::ActiveTheme;
use strum::EnumIter;
+3
View File
@@ -1,4 +1,7 @@
mod color;
mod elevation;
mod typography;
pub use color::*;
pub use elevation::*;
pub use typography::*;
+44
View File
@@ -0,0 +1,44 @@
use gpui::{Hsla, WindowContext};
use theme2::ActiveTheme;
#[derive(Default, PartialEq, Copy, Clone)]
pub enum Color {
#[default]
Default,
Accent,
Created,
Deleted,
Disabled,
Error,
Hidden,
Info,
Modified,
Muted,
Placeholder,
Player(u32),
Selected,
Success,
Warning,
}
impl Color {
pub fn color(&self, cx: &WindowContext) -> Hsla {
match self {
Color::Default => cx.theme().colors().text,
Color::Muted => cx.theme().colors().text_muted,
Color::Created => cx.theme().status().created,
Color::Modified => cx.theme().status().modified,
Color::Deleted => cx.theme().status().deleted,
Color::Disabled => cx.theme().colors().text_disabled,
Color::Hidden => cx.theme().status().hidden,
Color::Info => cx.theme().status().info,
Color::Placeholder => cx.theme().colors().text_placeholder,
Color::Accent => cx.theme().colors().text_accent,
Color::Player(i) => cx.theme().styles.player.0[i.clone() as usize].cursor,
Color::Error => cx.theme().status().error,
Color::Selected => cx.theme().colors().text_accent,
Color::Success => cx.theme().status().success,
Color::Warning => cx.theme().status().warning,
}
}
}