Combine LabelColor
and IconColor
into TextColor
This commit is contained in:
parent
dc56a7b12b
commit
76c15229c1
25 changed files with 152 additions and 220 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue