Merge
This commit is contained in:
commit
21b4ae3fdc
36 changed files with 705 additions and 576 deletions
|
@ -3,7 +3,6 @@ use std::marker::PhantomData;
|
|||
use gpui3::img;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::theme::theme;
|
||||
|
||||
#[derive(Element, Clone)]
|
||||
pub struct Avatar<S: 'static + Send + Sync> {
|
||||
|
@ -27,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 theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
|
||||
let mut img = img();
|
||||
|
||||
|
@ -39,7 +38,7 @@ impl<S: 'static + Send + Sync> Avatar<S> {
|
|||
|
||||
img.uri(self.src.clone())
|
||||
.size_4()
|
||||
.bg(theme.middle.warning.default.foreground)
|
||||
.bg(color.image_fallback_background)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ impl<S: 'static + Send + Sync> Default for ButtonHandlers<S> {
|
|||
}
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct Button<S: 'static + Send + Sync + Clone> {
|
||||
pub struct Button<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
label: SharedString,
|
||||
variant: ButtonVariant,
|
||||
|
@ -45,7 +45,7 @@ pub struct Button<S: 'static + Send + Sync + Clone> {
|
|||
handlers: ButtonHandlers<S>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> Button<S> {
|
||||
impl<S: 'static + Send + Sync> Button<S> {
|
||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::theme;
|
||||
|
||||
#[derive(Element, Clone)]
|
||||
pub struct Details<S: 'static + Send + Sync + Clone> {
|
||||
#[derive(Element)]
|
||||
pub struct Details<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
text: &'static str,
|
||||
meta: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> Details<S> {
|
||||
impl<S: 'static + Send + Sync> Details<S> {
|
||||
pub fn new(text: &'static str) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
|
@ -25,7 +24,7 @@ impl<S: 'static + Send + Sync + Clone> Details<S> {
|
|||
}
|
||||
|
||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||
let theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
|
||||
div()
|
||||
// .flex()
|
||||
|
@ -33,7 +32,7 @@ impl<S: 'static + Send + Sync + Clone> Details<S> {
|
|||
.p_1()
|
||||
.gap_0p5()
|
||||
.text_xs()
|
||||
.text_color(theme.lowest.base.default.foreground)
|
||||
.text_color(color.text)
|
||||
.child(self.text)
|
||||
.children(self.meta.map(|m| m))
|
||||
}
|
||||
|
@ -60,7 +59,11 @@ mod stories {
|
|||
}
|
||||
}
|
||||
|
||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||
fn render(
|
||||
&mut self,
|
||||
_view: &mut S,
|
||||
cx: &mut ViewContext<S>,
|
||||
) -> impl Element<ViewState = S> {
|
||||
Story::container(cx)
|
||||
.child(Story::title_for::<_, Details<S>>(cx))
|
||||
.child(Story::label(cx, "Default"))
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui3::{svg, Hsla};
|
||||
use strum::EnumIter;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::theme::{theme, Theme};
|
||||
use crate::theme::theme;
|
||||
|
||||
#[derive(Default, PartialEq, Copy, Clone)]
|
||||
pub enum IconSize {
|
||||
|
@ -29,7 +28,8 @@ pub enum IconColor {
|
|||
}
|
||||
|
||||
impl IconColor {
|
||||
pub fn color(self, theme: Arc<Theme>) -> Hsla {
|
||||
pub fn color(self, cx: &WindowContext) -> Hsla {
|
||||
let theme = theme(cx);
|
||||
match self {
|
||||
IconColor::Default => theme.lowest.base.default.foreground,
|
||||
IconColor::Muted => theme.lowest.variant.default.foreground,
|
||||
|
@ -44,7 +44,7 @@ impl IconColor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Copy, Clone, EnumIter)]
|
||||
#[derive(Debug, Default, PartialEq, Copy, Clone, EnumIter)]
|
||||
pub enum Icon {
|
||||
Ai,
|
||||
ArrowLeft,
|
||||
|
@ -148,7 +148,7 @@ impl Icon {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Element, Clone)]
|
||||
#[derive(Element)]
|
||||
pub struct IconElement<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
icon: Icon,
|
||||
|
@ -177,8 +177,8 @@ impl<S: 'static + Send + Sync> IconElement<S> {
|
|||
}
|
||||
|
||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||
let theme = theme(cx);
|
||||
let fill = self.color.color(theme);
|
||||
let color = ThemeColor::new(cx);
|
||||
let fill = self.color.color(cx);
|
||||
let svg_size = match self.size {
|
||||
IconSize::Small => ui_size(cx, 12. / 14.),
|
||||
IconSize::Medium => ui_size(cx, 15. / 14.),
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::theme;
|
||||
use crate::Label;
|
||||
use crate::LabelColor;
|
||||
|
||||
#[derive(Default, PartialEq)]
|
||||
pub enum InputVariant {
|
||||
|
@ -17,6 +18,8 @@ pub struct Input<S: 'static + Send + Sync> {
|
|||
value: String,
|
||||
state: InteractionState,
|
||||
variant: InputVariant,
|
||||
disabled: bool,
|
||||
is_active: bool,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync> Input<S> {
|
||||
|
@ -27,6 +30,8 @@ impl<S: 'static + Send + Sync> Input<S> {
|
|||
value: "".to_string(),
|
||||
state: InteractionState::default(),
|
||||
variant: InputVariant::default(),
|
||||
disabled: false,
|
||||
is_active: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,41 +50,44 @@ impl<S: 'static + Send + Sync> Input<S> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.disabled = disabled;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_active(mut self, is_active: bool) -> Self {
|
||||
self.is_active = is_active;
|
||||
self
|
||||
}
|
||||
|
||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||
let theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
let system_color = SystemColor::new();
|
||||
|
||||
let text_el;
|
||||
let text_color;
|
||||
let background_color_default;
|
||||
let background_color_active;
|
||||
|
||||
let mut border_color_default = theme.middle.base.default.border;
|
||||
let mut border_color_hover = theme.middle.base.hovered.border;
|
||||
let border_color_focus = theme.middle.base.pressed.background;
|
||||
|
||||
match self.variant {
|
||||
InputVariant::Ghost => {
|
||||
background_color_default = theme.middle.base.default.background;
|
||||
background_color_active = theme.middle.base.active.background;
|
||||
}
|
||||
InputVariant::Filled => {
|
||||
background_color_default = theme.middle.on.default.background;
|
||||
background_color_active = theme.middle.on.active.background;
|
||||
}
|
||||
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,
|
||||
),
|
||||
InputVariant::Filled => (
|
||||
color.filled_element,
|
||||
color.filled_element_hover,
|
||||
color.filled_element_active,
|
||||
),
|
||||
};
|
||||
|
||||
if self.state == InteractionState::Focused {
|
||||
border_color_default = theme.players[0].cursor;
|
||||
border_color_hover = theme.players[0].cursor;
|
||||
}
|
||||
|
||||
if self.state == InteractionState::Focused || self.state == InteractionState::Active {
|
||||
text_el = self.value.clone();
|
||||
text_color = theme.lowest.base.default.foreground;
|
||||
let placeholder_label = Label::new(self.placeholder.clone()).color(if self.disabled {
|
||||
LabelColor::Disabled
|
||||
} else {
|
||||
text_el = self.placeholder.to_string().clone();
|
||||
text_color = theme.lowest.base.disabled.foreground;
|
||||
}
|
||||
LabelColor::Placeholder
|
||||
});
|
||||
|
||||
let label = Label::new(self.value.clone()).color(if self.disabled {
|
||||
LabelColor::Disabled
|
||||
} else {
|
||||
LabelColor::Default
|
||||
});
|
||||
|
||||
div()
|
||||
.id("input")
|
||||
|
@ -87,14 +95,10 @@ impl<S: 'static + Send + Sync> Input<S> {
|
|||
.w_full()
|
||||
.px_2()
|
||||
.border()
|
||||
.border_color(border_color_default)
|
||||
.bg(background_color_default)
|
||||
.hover(|style| {
|
||||
style
|
||||
.border_color(border_color_hover)
|
||||
.bg(background_color_active)
|
||||
})
|
||||
.active(|style| style.border_color(theme.middle.base.active.border))
|
||||
.border_color(system_color.transparent)
|
||||
.bg(input_bg)
|
||||
.hover(|style| style.bg(input_hover_bg))
|
||||
.active(|style| style.bg(input_active_bg))
|
||||
.flex()
|
||||
.items_center()
|
||||
.child(
|
||||
|
@ -102,9 +106,8 @@ impl<S: 'static + Send + Sync> Input<S> {
|
|||
.flex()
|
||||
.items_center()
|
||||
.text_sm()
|
||||
.text_color(text_color)
|
||||
.child(text_el)
|
||||
.child(div().text_color(theme.players[0].cursor).child("|")),
|
||||
.when(self.value.is_empty(), |this| this.child(placeholder_label))
|
||||
.when(!self.value.is_empty(), |this| this.child(label)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -119,11 +122,11 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct InputStory<S: 'static + Send + Sync + Clone> {
|
||||
pub struct InputStory<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> InputStory<S> {
|
||||
impl<S: 'static + Send + Sync> InputStory<S> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
|
|
|
@ -22,17 +22,19 @@ pub enum LabelColor {
|
|||
|
||||
impl LabelColor {
|
||||
pub fn hsla(&self, cx: &WindowContext) -> Hsla {
|
||||
let color = ThemeColor::new(cx);
|
||||
// TODO: Remove
|
||||
let theme = theme(cx);
|
||||
|
||||
match self {
|
||||
Self::Default => theme.middle.base.default.foreground,
|
||||
Self::Muted => theme.middle.variant.default.foreground,
|
||||
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 => theme.middle.base.disabled.foreground,
|
||||
Self::Disabled => color.text_disabled,
|
||||
Self::Hidden => theme.middle.variant.default.foreground,
|
||||
Self::Placeholder => theme.middle.base.disabled.foreground,
|
||||
Self::Placeholder => color.text_placeholder,
|
||||
Self::Accent => theme.middle.accent.default.foreground,
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +48,8 @@ pub enum LineHeightStyle {
|
|||
UILabel,
|
||||
}
|
||||
|
||||
#[derive(Element, Clone)]
|
||||
pub struct Label<S: 'static + Send + Sync + Clone> {
|
||||
#[derive(Element)]
|
||||
pub struct Label<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
label: SharedString,
|
||||
line_height_style: LineHeightStyle,
|
||||
|
@ -55,7 +57,7 @@ pub struct Label<S: 'static + Send + Sync + Clone> {
|
|||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> Label<S> {
|
||||
impl<S: 'static + Send + Sync> Label<S> {
|
||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
|
@ -82,7 +84,7 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
|
|||
}
|
||||
|
||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||
let theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
|
||||
div()
|
||||
.when(self.strikethrough, |this| {
|
||||
|
@ -105,8 +107,8 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Element, Clone)]
|
||||
pub struct HighlightedLabel<S: 'static + Send + Sync + Clone> {
|
||||
#[derive(Element)]
|
||||
pub struct HighlightedLabel<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
label: SharedString,
|
||||
color: LabelColor,
|
||||
|
@ -114,7 +116,7 @@ pub struct HighlightedLabel<S: 'static + Send + Sync + Clone> {
|
|||
strikethrough: bool,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> HighlightedLabel<S> {
|
||||
impl<S: 'static + Send + Sync> HighlightedLabel<S> {
|
||||
pub fn new(label: impl Into<SharedString>, highlight_indices: Vec<usize>) -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
|
@ -136,9 +138,9 @@ impl<S: 'static + Send + Sync + Clone> HighlightedLabel<S> {
|
|||
}
|
||||
|
||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||
let theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
|
||||
let highlight_color = theme.lowest.accent.default.foreground;
|
||||
let highlight_color = color.text_accent;
|
||||
|
||||
let mut highlight_indices = self.highlight_indices.iter().copied().peekable();
|
||||
|
||||
|
@ -212,11 +214,11 @@ mod stories {
|
|||
use super::*;
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct LabelStory<S: 'static + Send + Sync + Clone> {
|
||||
pub struct LabelStory<S: 'static + Send + Sync> {
|
||||
state_type: PhantomData<S>,
|
||||
}
|
||||
|
||||
impl<S: 'static + Send + Sync + Clone> LabelStory<S> {
|
||||
impl<S: 'static + Send + Sync> LabelStory<S> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
state_type: PhantomData,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use gpui3::{Hsla, ViewContext};
|
||||
|
||||
use crate::theme;
|
||||
use crate::ThemeColor;
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
pub enum PlayerStatus {
|
||||
|
@ -139,15 +139,15 @@ impl Player {
|
|||
}
|
||||
|
||||
pub fn cursor_color<S: 'static>(&self, cx: &mut ViewContext<S>) -> Hsla {
|
||||
let theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
let index = self.index % 8;
|
||||
theme.players[self.index].cursor
|
||||
color.player[self.index].cursor
|
||||
}
|
||||
|
||||
pub fn selection_color<S: 'static>(&self, cx: &mut ViewContext<S>) -> Hsla {
|
||||
let theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
let index = self.index % 8;
|
||||
theme.players[self.index].selection
|
||||
color.player[self.index].selection
|
||||
}
|
||||
|
||||
pub fn avatar_src(&self) -> &str {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::theme;
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct ToolDivider<S: 'static + Send + Sync> {
|
||||
|
@ -16,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 theme = theme(cx);
|
||||
let color = ThemeColor::new(cx);
|
||||
|
||||
div().w_px().h_3().bg(theme.lowest.base.default.border)
|
||||
div().w_px().h_3().bg(color.border)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue