wip: design

This commit is contained in:
2025-01-14 12:08:06 +07:00
parent 8be41c9bfa
commit e8b34ae69e
36 changed files with 302 additions and 532 deletions

102
Cargo.lock generated
View File

@@ -123,11 +123,12 @@ dependencies = [
[[package]] [[package]]
name = "anstyle-wincon" name = "anstyle-wincon"
version = "3.0.6" version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"once_cell",
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
@@ -1013,7 +1014,7 @@ dependencies = [
[[package]] [[package]]
name = "collections" name = "collections"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"rustc-hash 2.1.0", "rustc-hash 2.1.0",
@@ -1302,7 +1303,7 @@ dependencies = [
[[package]] [[package]]
name = "derive_refineable" name = "derive_refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1997,7 +1998,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui" name = "gpui"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"as-raw-xcb-connection", "as-raw-xcb-connection",
@@ -2082,7 +2083,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui_macros" name = "gpui_macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2287,7 +2288,7 @@ dependencies = [
[[package]] [[package]]
name = "http_client" name = "http_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@@ -2702,9 +2703,9 @@ checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.76" version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@@ -2909,7 +2910,7 @@ dependencies = [
[[package]] [[package]]
name = "media" name = "media"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bindgen", "bindgen",
@@ -2965,6 +2966,16 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@@ -2973,9 +2984,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.8.2" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924"
dependencies = [ dependencies = [
"adler2", "adler2",
"simd-adler32", "simd-adler32",
@@ -3078,7 +3089,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
[[package]] [[package]]
name = "nostr" name = "nostr"
version = "0.38.0" version = "0.38.0"
source = "git+https://github.com/rust-nostr/nostr#209812bcabc861cc6b619234da0cb95fef9e9bd3" source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f"
dependencies = [ dependencies = [
"aes", "aes",
"async-trait", "async-trait",
@@ -3107,7 +3118,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-database" name = "nostr-database"
version = "0.38.0" version = "0.38.0"
source = "git+https://github.com/rust-nostr/nostr#209812bcabc861cc6b619234da0cb95fef9e9bd3" source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"flatbuffers", "flatbuffers",
@@ -3118,7 +3129,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-lmdb" name = "nostr-lmdb"
version = "0.38.0" version = "0.38.0"
source = "git+https://github.com/rust-nostr/nostr#209812bcabc861cc6b619234da0cb95fef9e9bd3" source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"heed", "heed",
@@ -3130,7 +3141,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-relay-pool" name = "nostr-relay-pool"
version = "0.38.0" version = "0.38.0"
source = "git+https://github.com/rust-nostr/nostr#209812bcabc861cc6b619234da0cb95fef9e9bd3" source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"async-wsocket", "async-wsocket",
@@ -3146,7 +3157,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-sdk" name = "nostr-sdk"
version = "0.38.0" version = "0.38.0"
source = "git+https://github.com/rust-nostr/nostr#209812bcabc861cc6b619234da0cb95fef9e9bd3" source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"lnurl-pay", "lnurl-pay",
@@ -3162,7 +3173,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-zapper" name = "nostr-zapper"
version = "0.38.0" version = "0.38.0"
source = "git+https://github.com/rust-nostr/nostr#209812bcabc861cc6b619234da0cb95fef9e9bd3" source = "git+https://github.com/rust-nostr/nostr#6a9b65a3daeef00310b2a763dca58d94a0f4198f"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"nostr", "nostr",
@@ -3860,9 +3871,9 @@ dependencies = [
[[package]] [[package]]
name = "prettyplease" name = "prettyplease"
version = "0.2.28" version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "924b9a625d6df5b74b0b3cfbb5669b3f62ddf3d46a677ce12b1945471b4ae5c3" checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn 2.0.96", "syn 2.0.96",
@@ -4164,7 +4175,7 @@ dependencies = [
[[package]] [[package]]
name = "refineable" name = "refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"derive_refineable", "derive_refineable",
] ]
@@ -4265,6 +4276,7 @@ dependencies = [
"js-sys", "js-sys",
"log", "log",
"mime", "mime",
"mime_guess",
"once_cell", "once_cell",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
@@ -4292,7 +4304,7 @@ dependencies = [
[[package]] [[package]]
name = "reqwest_client" name = "reqwest_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@@ -4642,7 +4654,7 @@ checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe"
[[package]] [[package]]
name = "semantic_version" name = "semantic_version"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
@@ -4958,7 +4970,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "sum_tree" name = "sum_tree"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"log", "log",
@@ -5781,7 +5793,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]] [[package]]
name = "util" name = "util"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#61115bd04792d87a540558753cd01a6368baba2a" source = "git+https://github.com/zed-industries/zed#93f117b21a07cb0e5c41682658339a473794d2da"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-fs", "async-fs",
@@ -5933,20 +5945,21 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.99" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
"rustversion",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.99" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
@@ -5958,9 +5971,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.49" version = "0.4.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@@ -5971,9 +5984,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.99" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@@ -5981,9 +5994,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.99" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -5994,9 +6007,12 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.99" version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [
"unicode-ident",
]
[[package]] [[package]]
name = "wasm-streams" name = "wasm-streams"
@@ -6098,9 +6114,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.76" version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@@ -6642,7 +6658,7 @@ dependencies = [
"winnow", "winnow",
"xdg-home", "xdg-home",
"zbus_macros 5.3.0", "zbus_macros 5.3.0",
"zbus_names 4.1.0", "zbus_names 4.1.1",
"zvariant 5.2.0", "zvariant 5.2.0",
] ]
@@ -6669,7 +6685,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.96", "syn 2.0.96",
"zbus_names 4.1.0", "zbus_names 4.1.1",
"zvariant 5.2.0", "zvariant 5.2.0",
"zvariant_utils 3.1.0", "zvariant_utils 3.1.0",
] ]
@@ -6687,9 +6703,9 @@ dependencies = [
[[package]] [[package]]
name = "zbus_names" name = "zbus_names"
version = "4.1.0" version = "4.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "856b7a38811f71846fd47856ceee8bccaec8399ff53fb370247e66081ace647b" checksum = "519629a3f80976d89c575895b05677cbc45eaf9f70d62a364d819ba646409cc8"
dependencies = [ dependencies = [
"serde", "serde",
"static_assertions", "static_assertions",

View File

@@ -66,10 +66,9 @@ impl Account {
impl Render for Account { impl Render for Account {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
Button::new("account") Button::new("account")
.small()
.compact()
.reverse()
.ghost() .ghost()
.xsmall()
.reverse()
.icon(Icon::new(IconName::ChevronDownSmall)) .icon(Icon::new(IconName::ChevronDownSmall))
.map(|this| { .map(|this| {
if let Some(metadata) = self.metadata.read(cx).as_ref() { if let Some(metadata) = self.metadata.read(cx).as_ref() {

View File

@@ -4,7 +4,7 @@ use super::{
}; };
use crate::states::{app::AppRegistry, chat::ChatRegistry}; use crate::states::{app::AppRegistry, chat::ChatRegistry};
use gpui::{ use gpui::{
div, impl_actions, px, Axis, Context, Edges, InteractiveElement, IntoElement, Model, div, impl_internal_actions, px, Axis, Context, Edges, InteractiveElement, IntoElement, Model,
ParentElement, Render, Styled, View, ViewContext, VisualContext, WeakView, WindowContext, ParentElement, Render, Styled, View, ViewContext, VisualContext, WeakView, WindowContext,
}; };
use serde::Deserialize; use serde::Deserialize;
@@ -28,7 +28,7 @@ pub struct AddPanel {
pub position: DockPlacement, pub position: DockPlacement,
} }
impl_actions!(dock, [AddPanel]); impl_internal_actions!(dock, [AddPanel]);
pub struct DockAreaTab { pub struct DockAreaTab {
id: &'static str, id: &'static str,

View File

@@ -1,6 +1,6 @@
use crate::{constants::IMAGE_SERVICE, get_client, utils::show_npub}; use crate::{constants::IMAGE_SERVICE, get_client, utils::show_npub};
use gpui::{ use gpui::{
div, img, impl_actions, list, px, Context, ElementId, FocusHandle, InteractiveElement, div, img, impl_internal_actions, list, px, Context, ElementId, FocusHandle, InteractiveElement,
IntoElement, ListAlignment, ListState, Model, ParentElement, Pixels, Render, RenderOnce, IntoElement, ListAlignment, ListState, Model, ParentElement, Pixels, Render, RenderOnce,
SharedString, StatefulInteractiveElement, Styled, ViewContext, WindowContext, SharedString, StatefulInteractiveElement, Styled, ViewContext, WindowContext,
}; };
@@ -16,7 +16,7 @@ use ui::{
#[derive(Clone, PartialEq, Eq, Deserialize)] #[derive(Clone, PartialEq, Eq, Deserialize)]
struct SelectContact(PublicKey); struct SelectContact(PublicKey);
impl_actions!(contacts, [SelectContact]); impl_internal_actions!(contacts, [SelectContact]);
#[derive(Clone, IntoElement)] #[derive(Clone, IntoElement)]
struct ContactListItem { struct ContactListItem {
@@ -95,7 +95,7 @@ impl RenderOnce for ContactListItem {
this.child( this.child(
Icon::new(IconName::CircleCheck) Icon::new(IconName::CircleCheck)
.size_4() .size_4()
.text_color(cx.theme().primary), .text_color(cx.theme().colors.primary),
) )
}) })
.hover(|this| { .hover(|this| {

View File

@@ -4,10 +4,14 @@ use crate::{
views::app::{AddPanel, PanelKind}, views::app::{AddPanel, PanelKind},
}; };
use gpui::{ use gpui::{
div, img, percentage, prelude::FluentBuilder, InteractiveElement, IntoElement, ParentElement, div, img, percentage, prelude::FluentBuilder, px, InteractiveElement, IntoElement,
Render, SharedString, StatefulInteractiveElement, Styled, ViewContext, ParentElement, Render, SharedString, StatefulInteractiveElement, Styled, ViewContext,
};
use ui::{
skeleton::Skeleton,
theme::{scale::ColorScaleStep, ActiveTheme},
v_flex, Collapsible, Icon, IconName, StyledExt,
}; };
use ui::{skeleton::Skeleton, theme::ActiveTheme, v_flex, Collapsible, Icon, IconName, StyledExt};
pub struct Inbox { pub struct Inbox {
label: SharedString, label: SharedString,
@@ -59,8 +63,8 @@ impl Inbox {
.items_center() .items_center()
.justify_between() .justify_between()
.text_xs() .text_xs()
.rounded_md() .rounded(px(cx.theme().radius))
.hover(|this| this.bg(cx.theme().list_hover)) .hover(|this| this.bg(cx.theme().base.step(cx, ColorScaleStep::FOUR)))
.child(div().font_medium().map(|this| { .child(div().font_medium().map(|this| {
if room.is_group { if room.is_group {
this.flex() this.flex()
@@ -83,7 +87,11 @@ impl Inbox {
}) })
} }
})) }))
.child(div().child(ago)) .child(
div()
.text_color(cx.theme().base.step(cx, ColorScaleStep::ELEVEN))
.child(ago),
)
.on_click(cx.listener(move |this, _, cx| { .on_click(cx.listener(move |this, _, cx| {
this.action(id, cx); this.action(id, cx);
})) }))
@@ -126,10 +134,10 @@ impl Render for Inbox {
.px_1() .px_1()
.flex() .flex()
.items_center() .items_center()
.rounded_md() .rounded(px(cx.theme().radius))
.text_xs() .text_xs()
.font_semibold() .font_semibold()
.hover(|this| this.bg(cx.theme().list_hover)) .hover(|this| this.bg(cx.theme().base.step(cx, ColorScaleStep::THREE)))
.on_click(cx.listener(move |view, _event, cx| { .on_click(cx.listener(move |view, _event, cx| {
view.is_collapsed = !view.is_collapsed; view.is_collapsed = !view.is_collapsed;
cx.notify(); cx.notify();

View File

@@ -115,7 +115,7 @@ impl Render for Sidebar {
.child( .child(
v_flex() v_flex()
.px_2() .px_2()
.gap_1() .gap_0p5()
.child( .child(
Button::new("compose") Button::new("compose")
.small() .small()

View File

@@ -20,7 +20,7 @@ pub enum BadgeVariant {
impl BadgeVariant { impl BadgeVariant {
fn bg(&self, cx: &gpui::WindowContext) -> Hsla { fn bg(&self, cx: &gpui::WindowContext) -> Hsla {
match self { match self {
Self::Primary => cx.theme().primary, Self::Primary => cx.theme().colors.primary,
Self::Secondary => cx.theme().secondary, Self::Secondary => cx.theme().secondary,
Self::Outline => gpui::transparent_black(), Self::Outline => gpui::transparent_black(),
Self::Destructive => cx.theme().danger, Self::Destructive => cx.theme().danger,
@@ -30,7 +30,7 @@ impl BadgeVariant {
fn border(&self, cx: &gpui::WindowContext) -> Hsla { fn border(&self, cx: &gpui::WindowContext) -> Hsla {
match self { match self {
Self::Primary => cx.theme().primary, Self::Primary => cx.theme().colors.primary,
Self::Secondary => cx.theme().secondary, Self::Secondary => cx.theme().secondary,
Self::Outline => cx.theme().border, Self::Outline => cx.theme().border,
Self::Destructive => cx.theme().danger, Self::Destructive => cx.theme().danger,

View File

@@ -1,6 +1,6 @@
use crate::{ use crate::{
indicator::Indicator, indicator::Indicator,
theme::{ActiveTheme, Colorize as _}, theme::{scale::ColorScaleStep, ActiveTheme, Colorize as _},
tooltip::Tooltip, tooltip::Tooltip,
Disableable, Icon, Selectable, Sizable, Size, StyledExt, Disableable, Icon, Selectable, Sizable, Size, StyledExt,
}; };
@@ -76,11 +76,11 @@ pub trait ButtonVariants: Sized {
impl ButtonCustomVariant { impl ButtonCustomVariant {
pub fn new(cx: &WindowContext) -> Self { pub fn new(cx: &WindowContext) -> Self {
Self { Self {
color: cx.theme().secondary, color: cx.theme().accent.step(cx, ColorScaleStep::NINE),
foreground: cx.theme().secondary_foreground, foreground: cx.theme().accent.step(cx, ColorScaleStep::ONE),
border: cx.theme().border, border: cx.theme().accent.step(cx, ColorScaleStep::TEN),
hover: cx.theme().secondary_hover, hover: cx.theme().accent.step(cx, ColorScaleStep::TEN),
active: cx.theme().secondary_active, active: cx.theme().accent.step(cx, ColorScaleStep::ELEVEN),
shadow: true, shadow: true,
} }
} }
@@ -120,7 +120,6 @@ impl ButtonCustomVariant {
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum ButtonVariant { pub enum ButtonVariant {
Primary, Primary,
Secondary,
Danger, Danger,
Outline, Outline,
Ghost, Ghost,
@@ -131,7 +130,7 @@ pub enum ButtonVariant {
impl Default for ButtonVariant { impl Default for ButtonVariant {
fn default() -> Self { fn default() -> Self {
Self::Secondary Self::Primary
} }
} }
@@ -160,21 +159,20 @@ pub struct Button {
label: Option<SharedString>, label: Option<SharedString>,
children: Vec<AnyElement>, children: Vec<AnyElement>,
disabled: bool, disabled: bool,
pub(crate) selected: bool,
variant: ButtonVariant, variant: ButtonVariant,
rounded: ButtonRounded, rounded: ButtonRounded,
border_corners: Corners<bool>, border_corners: Corners<bool>,
border_edges: Edges<bool>, border_edges: Edges<bool>,
size: Size, size: Size,
compact: bool,
reverse: bool, reverse: bool,
bold: bool, bold: bool,
centered: bool, centered: bool,
tooltip: Option<SharedString>, tooltip: Option<SharedString>,
on_click: OnClick, on_click: OnClick,
pub(crate) stop_propagation: bool,
loading: bool, loading: bool,
loading_icon: Option<Icon>, loading_icon: Option<Icon>,
pub(crate) selected: bool,
pub(crate) stop_propagation: bool,
} }
impl From<Button> for AnyElement { impl From<Button> for AnyElement {
@@ -202,7 +200,6 @@ impl Button {
stop_propagation: true, stop_propagation: true,
loading: false, loading: false,
reverse: false, reverse: false,
compact: false,
bold: false, bold: false,
centered: true, centered: true,
children: Vec::new(), children: Vec::new(),
@@ -252,12 +249,6 @@ impl Button {
self self
} }
/// Set the button to compact mode, then padding will be reduced.
pub fn compact(mut self) -> Self {
self.compact = true;
self
}
/// Set reverse the position between icon and label. /// Set reverse the position between icon and label.
pub fn reverse(mut self) -> Self { pub fn reverse(mut self) -> Self {
self.reverse = true; self.reverse = true;
@@ -372,9 +363,9 @@ impl RenderOnce for Button {
// Normal Button // Normal Button
match self.size { match self.size {
Size::Size(size) => this.px(size * 0.2), Size::Size(size) => this.px(size * 0.2),
Size::XSmall => this.h_5().px_1().when(self.compact, |this| this.px_0()), Size::XSmall => this.h_6().px_0p5(),
Size::Small => this.h_6().px_2().when(self.compact, |this| this.px_0p5()), Size::Small => this.h_8().px_2(),
_ => this.h_8().px_4().when(self.compact, |this| this.px_1()), _ => this.h_10().px_4(),
} }
} }
}) })
@@ -486,7 +477,7 @@ impl RenderOnce for Button {
}) })
.when(self.loading, |this| this.bg(normal_style.bg.opacity(0.8))) .when(self.loading, |this| this.bg(normal_style.bg.opacity(0.8)))
.when_some(self.tooltip.clone(), |this, tooltip| { .when_some(self.tooltip.clone(), |this, tooltip| {
this.tooltip(move |cx| Tooltip::new(tooltip.clone(), cx)) this.tooltip(move |cx| Tooltip::new(tooltip.clone(), cx).into())
}) })
} }
} }
@@ -502,34 +493,25 @@ struct ButtonVariantStyle {
impl ButtonVariant { impl ButtonVariant {
fn bg_color(&self, cx: &WindowContext) -> Hsla { fn bg_color(&self, cx: &WindowContext) -> Hsla {
match self { match self {
ButtonVariant::Primary => cx.theme().primary, ButtonVariant::Primary => cx.theme().accent.step(cx, ColorScaleStep::NINE),
ButtonVariant::Secondary => cx.theme().secondary,
ButtonVariant::Danger => cx.theme().danger, ButtonVariant::Danger => cx.theme().danger,
ButtonVariant::Outline
| ButtonVariant::Ghost
| ButtonVariant::Link
| ButtonVariant::Text => cx.theme().transparent,
ButtonVariant::Custom(colors) => colors.color, ButtonVariant::Custom(colors) => colors.color,
_ => cx.theme().transparent,
} }
} }
fn text_color(&self, cx: &WindowContext) -> Hsla { fn text_color(&self, cx: &WindowContext) -> Hsla {
match self { match self {
ButtonVariant::Primary => cx.theme().primary_foreground, ButtonVariant::Primary => cx.theme().accent.step(cx, ColorScaleStep::ONE),
ButtonVariant::Secondary | ButtonVariant::Outline | ButtonVariant::Ghost => { ButtonVariant::Link => cx.theme().accent.step(cx, ColorScaleStep::NINE),
cx.theme().secondary_foreground
}
ButtonVariant::Danger => cx.theme().danger_foreground,
ButtonVariant::Link => cx.theme().link,
ButtonVariant::Text => cx.theme().foreground,
ButtonVariant::Custom(colors) => colors.foreground, ButtonVariant::Custom(colors) => colors.foreground,
_ => cx.theme().base.step(cx, ColorScaleStep::TWELVE),
} }
} }
fn border_color(&self, cx: &WindowContext) -> Hsla { fn border_color(&self, cx: &WindowContext) -> Hsla {
match self { match self {
ButtonVariant::Primary => cx.theme().primary, ButtonVariant::Primary => cx.theme().colors.primary,
ButtonVariant::Secondary => cx.theme().border,
ButtonVariant::Danger => cx.theme().danger, ButtonVariant::Danger => cx.theme().danger,
ButtonVariant::Outline => cx.theme().border, ButtonVariant::Outline => cx.theme().border,
ButtonVariant::Ghost | ButtonVariant::Link | ButtonVariant::Text => { ButtonVariant::Ghost | ButtonVariant::Link | ButtonVariant::Text => {
@@ -545,7 +527,7 @@ impl ButtonVariant {
fn shadow(&self, _: &WindowContext) -> bool { fn shadow(&self, _: &WindowContext) -> bool {
match self { match self {
ButtonVariant::Primary | ButtonVariant::Secondary | ButtonVariant::Danger => true, ButtonVariant::Primary | ButtonVariant::Danger => true,
ButtonVariant::Custom(c) => c.shadow, ButtonVariant::Custom(c) => c.shadow,
_ => false, _ => false,
} }
@@ -569,16 +551,10 @@ impl ButtonVariant {
fn hovered(&self, cx: &WindowContext) -> ButtonVariantStyle { fn hovered(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = match self { let bg = match self {
ButtonVariant::Primary => cx.theme().primary_hover, ButtonVariant::Primary => cx.theme().accent.step(cx, ColorScaleStep::TEN),
ButtonVariant::Secondary | ButtonVariant::Outline => cx.theme().secondary_hover, ButtonVariant::Outline => cx.theme().secondary_hover,
ButtonVariant::Danger => cx.theme().danger_hover, ButtonVariant::Danger => cx.theme().danger_hover,
ButtonVariant::Ghost => { ButtonVariant::Ghost => cx.theme().base.step(cx, ColorScaleStep::FOUR),
if cx.theme().mode.is_dark() {
cx.theme().secondary.lighten(0.1).opacity(0.8)
} else {
cx.theme().secondary.darken(0.1).opacity(0.8)
}
}
ButtonVariant::Link => cx.theme().transparent, ButtonVariant::Link => cx.theme().transparent,
ButtonVariant::Text => cx.theme().transparent, ButtonVariant::Text => cx.theme().transparent,
ButtonVariant::Custom(colors) => colors.hover, ButtonVariant::Custom(colors) => colors.hover,
@@ -603,9 +579,9 @@ impl ButtonVariant {
fn active(&self, cx: &WindowContext) -> ButtonVariantStyle { fn active(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = match self { let bg = match self {
ButtonVariant::Primary => cx.theme().primary_active, ButtonVariant::Primary => cx.theme().primary_active,
ButtonVariant::Secondary | ButtonVariant::Outline => cx.theme().secondary_active, ButtonVariant::Outline => cx.theme().secondary_active,
ButtonVariant::Ghost => { ButtonVariant::Ghost => {
if cx.theme().mode.is_dark() { if cx.theme().appearance.is_dark() {
cx.theme().secondary.lighten(0.2).opacity(0.8) cx.theme().secondary.lighten(0.2).opacity(0.8)
} else { } else {
cx.theme().secondary.darken(0.2).opacity(0.8) cx.theme().secondary.darken(0.2).opacity(0.8)
@@ -637,9 +613,9 @@ impl ButtonVariant {
fn selected(&self, cx: &WindowContext) -> ButtonVariantStyle { fn selected(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = match self { let bg = match self {
ButtonVariant::Primary => cx.theme().primary_active, ButtonVariant::Primary => cx.theme().primary_active,
ButtonVariant::Secondary | ButtonVariant::Outline => cx.theme().secondary_active, ButtonVariant::Outline => cx.theme().secondary_active,
ButtonVariant::Ghost => { ButtonVariant::Ghost => {
if cx.theme().mode.is_dark() { if cx.theme().appearance.is_dark() {
cx.theme().secondary.lighten(0.2).opacity(0.8) cx.theme().secondary.lighten(0.2).opacity(0.8)
} else { } else {
cx.theme().secondary.darken(0.2).opacity(0.8) cx.theme().secondary.darken(0.2).opacity(0.8)
@@ -674,9 +650,8 @@ impl ButtonVariant {
| ButtonVariant::Ghost | ButtonVariant::Ghost
| ButtonVariant::Outline | ButtonVariant::Outline
| ButtonVariant::Text => cx.theme().transparent, | ButtonVariant::Text => cx.theme().transparent,
ButtonVariant::Primary => cx.theme().primary.opacity(0.15), ButtonVariant::Primary => cx.theme().colors.primary.opacity(0.15),
ButtonVariant::Danger => cx.theme().danger.opacity(0.15), ButtonVariant::Danger => cx.theme().danger.opacity(0.15),
ButtonVariant::Secondary => cx.theme().secondary.opacity(1.5),
ButtonVariant::Custom(style) => style.color.opacity(0.15), ButtonVariant::Custom(style) => style.color.opacity(0.15),
}; };
let fg = match self { let fg = match self {

View File

@@ -167,7 +167,6 @@ impl RenderOnce for ButtonGroup {
.stop_propagation(false) .stop_propagation(false)
.when_some(self.size, |this, size| this.with_size(size)) .when_some(self.size, |this, size| this.with_size(size))
.when_some(self.variant, |this, variant| this.with_variant(variant)) .when_some(self.variant, |this, variant| this.with_variant(variant))
.when_some(self.compact, |this, _| this.compact())
.on_click(move |_, _| { .on_click(move |_, _| {
state.set(Some(child_index)); state.set(Some(child_index));
}) })

View File

@@ -65,11 +65,11 @@ impl RenderOnce for Checkbox {
fn render(self, cx: &mut WindowContext) -> impl IntoElement { fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let (color, icon_color) = if self.disabled { let (color, icon_color) = if self.disabled {
( (
cx.theme().primary.opacity(0.5), cx.theme().colors.primary.opacity(0.5),
cx.theme().primary_foreground.opacity(0.5), cx.theme().primary_foreground.opacity(0.5),
) )
} else { } else {
(cx.theme().primary, cx.theme().primary_foreground) (cx.theme().colors.primary, cx.theme().primary_foreground)
}; };
h_flex() h_flex()

View File

@@ -1,13 +1,11 @@
use std::{cell::RefCell, rc::Rc}; use crate::popup_menu::PopupMenu;
use gpui::{ use gpui::{
anchored, deferred, div, prelude::FluentBuilder, px, relative, AnyElement, Corner, anchored, deferred, div, prelude::FluentBuilder, px, relative, AnyElement, Corner,
DismissEvent, DispatchPhase, Element, ElementId, Focusable, GlobalElementId, DismissEvent, DispatchPhase, Element, ElementId, Focusable, GlobalElementId,
InteractiveElement, IntoElement, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, InteractiveElement, IntoElement, MouseButton, MouseDownEvent, ParentElement, Pixels, Point,
Position, Stateful, Style, View, ViewContext, WindowContext, Position, Stateful, Style, View, ViewContext, WindowContext,
}; };
use std::{cell::RefCell, rc::Rc};
use crate::popup_menu::PopupMenu;
pub trait ContextMenuExt: ParentElement + Sized { pub trait ContextMenuExt: ParentElement + Sized {
fn context_menu( fn context_menu(

View File

@@ -23,7 +23,7 @@ pub use state::*;
pub use tab_panel::*; pub use tab_panel::*;
pub use tiles::*; pub use tiles::*;
use crate::theme::ActiveTheme; use crate::theme::{scale::ColorScaleStep, ActiveTheme};
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.set_global(PanelRegistry::new()); cx.set_global(PanelRegistry::new());
@@ -856,8 +856,7 @@ impl Render for DockArea {
.h_full() .h_full()
// Left dock // Left dock
.when_some(self.left_dock.clone(), |this, dock| { .when_some(self.left_dock.clone(), |this, dock| {
this.bg(cx.theme().muted) this.bg(cx.theme().base.step(cx, ColorScaleStep::ONE))
.text_color(cx.theme().muted_foreground)
.child(div().flex().flex_none().child(dock)) .child(div().flex().flex_none().child(dock))
}) })
// Center // Center

View File

@@ -1,7 +1,3 @@
use gpui::*;
use prelude::FluentBuilder;
use std::sync::Arc;
use super::{ use super::{
ClosePanel, DockArea, DockPlacement, Panel, PanelEvent, PanelState, PanelStyle, PanelView, ClosePanel, DockArea, DockPlacement, Panel, PanelEvent, PanelState, PanelStyle, PanelView,
StackPanel, ToggleZoom, StackPanel, ToggleZoom,
@@ -12,9 +8,17 @@ use crate::{
h_flex, h_flex,
popup_menu::{PopupMenu, PopupMenuExt}, popup_menu::{PopupMenu, PopupMenuExt},
tab::{tab_bar::TabBar, Tab}, tab::{tab_bar::TabBar, Tab},
theme::ActiveTheme, theme::{scale::ColorScaleStep, ActiveTheme},
v_flex, AxisExt, IconName, Placement, Selectable, Sizable, v_flex, AxisExt, IconName, Placement, Selectable, Sizable,
}; };
use gpui::{
div, img, prelude::FluentBuilder, px, rems, AppContext, Corner, DefiniteLength, DismissEvent,
DragMoveEvent, Empty, Entity, EventEmitter, FocusHandle, FocusableView,
InteractiveElement as _, IntoElement, ObjectFit, ParentElement, Pixels, Render, ScrollHandle,
SharedString, StatefulInteractiveElement, Styled, StyledImage, View, ViewContext,
VisualContext as _, WeakView, WindowContext,
};
use std::sync::Arc;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct TabState { struct TabState {
@@ -49,13 +53,11 @@ impl Render for DragPanel {
.justify_center() .justify_center()
.overflow_hidden() .overflow_hidden()
.whitespace_nowrap() .whitespace_nowrap()
.border_1() .rounded(px(cx.theme().radius))
.border_color(cx.theme().border)
.rounded_md()
.text_color(cx.theme().tab_foreground)
.text_xs() .text_xs()
.bg(cx.theme().tab_active) .border_1()
.opacity(0.75) .border_color(cx.theme().base.step(cx, ColorScaleStep::THREE))
.bg(cx.theme().base.step(cx, ColorScaleStep::TWO))
.child(self.panel.title(cx)) .child(self.panel.title(cx))
} }
} }
@@ -572,8 +574,8 @@ impl TabPanel {
.border_r_1() .border_r_1()
.border_b_1() .border_b_1()
.h_full() .h_full()
.border_color(cx.theme().border) .border_color(cx.theme().base.step(cx, ColorScaleStep::THREE))
.bg(cx.theme().tab_bar) .bg(cx.theme().base.step(cx, ColorScaleStep::TWO))
.px_2() .px_2()
.children(left_dock_button) .children(left_dock_button)
.children(bottom_dock_button), .children(bottom_dock_button),
@@ -611,7 +613,7 @@ impl TabPanel {
this.rounded_l_none() this.rounded_l_none()
.border_l_2() .border_l_2()
.border_r_0() .border_r_0()
.border_color(cx.theme().drag_border) .border_color(cx.theme().base.step(cx, ColorScaleStep::TWO))
}) })
.on_drop(cx.listener( .on_drop(cx.listener(
move |this, drag: &DragPanel, cx| { move |this, drag: &DragPanel, cx| {
@@ -630,8 +632,11 @@ impl TabPanel {
.flex_grow() .flex_grow()
.min_w_16() .min_w_16()
.when(state.droppable, |this| { .when(state.droppable, |this| {
this.drag_over::<DragPanel>(|this, _, cx| this.bg(cx.theme().drop_target)) this.drag_over::<DragPanel>(|this, _, cx| {
.on_drop(cx.listener(move |this, drag: &DragPanel, cx| { this.bg(cx.theme().base.step(cx, ColorScaleStep::TWO))
})
.on_drop(cx.listener(
move |this, drag: &DragPanel, cx| {
this.will_split_placement = None; this.will_split_placement = None;
let ix = if drag.tab_panel == view { let ix = if drag.tab_panel == view {
@@ -641,7 +646,8 @@ impl TabPanel {
}; };
this.on_drop(drag, ix, false, cx) this.on_drop(drag, ix, false, cx)
})) },
))
}), }),
) )
.suffix( .suffix(
@@ -652,8 +658,8 @@ impl TabPanel {
.border_l_1() .border_l_1()
.border_b_1() .border_b_1()
.h_full() .h_full()
.border_color(cx.theme().border) .border_color(cx.theme().base.step(cx, ColorScaleStep::THREE))
.bg(cx.theme().tab_bar) .bg(cx.theme().base.step(cx, ColorScaleStep::TWO))
.px_2() .px_2()
.gap_1() .gap_1()
.child(self.render_toolbar(state, cx)) .child(self.render_toolbar(state, cx))

View File

@@ -1,11 +1,3 @@
use gpui::{
actions, anchored, canvas, deferred, div, prelude::FluentBuilder, px, rems, AnyElement,
AppContext, Bounds, ClickEvent, DismissEvent, ElementId, EventEmitter, FocusHandle,
FocusableView, InteractiveElement, IntoElement, KeyBinding, Length, ParentElement, Pixels,
Render, SharedString, StatefulInteractiveElement, Styled, Task, View, ViewContext,
VisualContext, WeakView, WindowContext,
};
use crate::{ use crate::{
h_flex, h_flex,
input::ClearButton, input::ClearButton,
@@ -13,6 +5,13 @@ use crate::{
theme::ActiveTheme, theme::ActiveTheme,
v_flex, Disableable, Icon, IconName, Sizable, Size, StyleSized, StyledExt, v_flex, Disableable, Icon, IconName, Sizable, Size, StyleSized, StyledExt,
}; };
use gpui::{
actions, anchored, canvas, deferred, div, prelude::FluentBuilder, px, rems, AnyElement,
AppContext, Bounds, ClickEvent, DismissEvent, ElementId, EventEmitter, FocusHandle,
FocusableView, InteractiveElement, IntoElement, KeyBinding, Length, ParentElement, Pixels,
Render, SharedString, StatefulInteractiveElement, Styled, Task, View, ViewContext,
VisualContext, WeakView, WindowContext,
};
actions!(dropdown, [Up, Down, Enter, Escape]); actions!(dropdown, [Up, Down, Enter, Escape]);

View File

@@ -144,7 +144,7 @@ impl TextElement {
), ),
size(px(1.5), line_height), size(px(1.5), line_height),
), ),
cx.theme().primary, cx.theme().colors.primary,
)) ))
}; };
} }

View File

@@ -1,10 +1,9 @@
use crate::{h_flex, theme::ActiveTheme};
use gpui::{ use gpui::{
div, prelude::FluentBuilder, rems, Div, IntoElement, ParentElement, RenderOnce, SharedString, div, prelude::FluentBuilder, rems, Div, IntoElement, ParentElement, RenderOnce, SharedString,
Styled, WindowContext, Styled, WindowContext,
}; };
use crate::{h_flex, theme::ActiveTheme};
const MASKED: &str = ""; const MASKED: &str = "";
#[derive(Default, PartialEq, Eq)] #[derive(Default, PartialEq, Eq)]

View File

@@ -23,7 +23,6 @@ pub mod radio;
pub mod resizable; pub mod resizable;
pub mod scroll; pub mod scroll;
pub mod skeleton; pub mod skeleton;
pub mod slider;
pub mod switch; pub mod switch;
pub mod tab; pub mod tab;
pub mod theme; pub mod theme;

View File

@@ -47,7 +47,7 @@ pub(crate) fn overlay_color(overlay: bool, cx: &WindowContext) -> Hsla {
return hsla(0., 0., 0., 0.); return hsla(0., 0., 0., 0.);
} }
if cx.theme().mode.is_dark() { if cx.theme().appearance.is_dark() {
hsla(0., 1., 1., 0.06) hsla(0., 1., 1., 0.06)
} else { } else {
hsla(0., 0., 0., 0.06) hsla(0., 0., 0., 0.06)

View File

@@ -228,8 +228,8 @@ impl Render for Notification {
.relative() .relative()
.w_96() .w_96()
.border_1() .border_1()
.border_color(cx.theme().border) .border_color(cx.theme().base.step(cx, ColorScaleStep::THREE))
.bg(cx.theme().popover) .bg(cx.theme().background)
.rounded_md() .rounded_md()
.shadow_md() .shadow_md()
.py_2() .py_2()

View File

@@ -1,3 +1,4 @@
use crate::{Selectable, StyledExt as _};
use gpui::{ use gpui::{
actions, anchored, deferred, div, prelude::FluentBuilder as _, px, AnyElement, AppContext, actions, anchored, deferred, div, prelude::FluentBuilder as _, px, AnyElement, AppContext,
Bounds, Corner, DismissEvent, DispatchPhase, Element, ElementId, EventEmitter, FocusHandle, Bounds, Corner, DismissEvent, DispatchPhase, Element, ElementId, EventEmitter, FocusHandle,
@@ -7,8 +8,6 @@ use gpui::{
}; };
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use crate::{Selectable, StyledExt as _};
const CONTEXT: &str = "Popover"; const CONTEXT: &str = "Popover";
actions!(popover, [Escape]); actions!(popover, [Escape]);
@@ -44,6 +43,7 @@ impl PopoverContent {
self self
} }
} }
impl EventEmitter<DismissEvent> for PopoverContent {} impl EventEmitter<DismissEvent> for PopoverContent {}
impl FocusableView for PopoverContent { impl FocusableView for PopoverContent {

View File

@@ -1,11 +1,19 @@
use crate::scroll::{Scrollbar, ScrollbarState};
use crate::StyledExt;
use crate::{ use crate::{
button::Button, h_flex, list::ListItem, popover::Popover, theme::ActiveTheme, v_flex, Icon, button::Button,
IconName, Selectable, Sizable as _, h_flex,
list::ListItem,
popover::Popover,
scroll::{Scrollbar, ScrollbarState},
theme::{scale::ColorScaleStep, ActiveTheme},
v_flex, Icon, IconName, Selectable, Sizable as _, StyledExt,
};
use gpui::{
actions, anchored, canvas, div, prelude::FluentBuilder, px, rems, Action, AnyElement,
AppContext, Bounds, Corner, DismissEvent, Edges, EventEmitter, FocusHandle, FocusableView,
InteractiveElement, IntoElement, KeyBinding, Keystroke, ParentElement, Pixels, Render,
ScrollHandle, SharedString, StatefulInteractiveElement, Styled, View, ViewContext,
VisualContext as _, WeakView, WindowContext,
}; };
use gpui::*;
use prelude::FluentBuilder;
use std::{cell::Cell, ops::Deref, rc::Rc}; use std::{cell::Cell, ops::Deref, rc::Rc};
actions!(menu, [Confirm, Dismiss, SelectNext, SelectPrev]); actions!(menu, [Confirm, Dismiss, SelectNext, SelectPrev]);
@@ -48,6 +56,7 @@ pub trait PopupMenuExt: Styled + Selectable + IntoElement + 'static {
.content(move |cx| PopupMenu::build(cx, |menu, cx| f(menu, cx))) .content(move |cx| PopupMenu::build(cx, |menu, cx| f(menu, cx)))
} }
} }
impl PopupMenuExt for Button {} impl PopupMenuExt for Button {}
enum PopupMenuItem { enum PopupMenuItem {
@@ -429,12 +438,14 @@ impl PopupMenu {
) -> Option<impl IntoElement> { ) -> Option<impl IntoElement> {
if let Some(action) = action { if let Some(action) = action {
if let Some(keybinding) = cx.bindings_for_action(action.deref()).first() { if let Some(keybinding) = cx.bindings_for_action(action.deref()).first() {
let el = div().text_color(cx.theme().muted_foreground).children( let el = div()
keybinding .text_color(cx.theme().base.step(cx, ColorScaleStep::ELEVEN))
.keystrokes() .children(
.iter() keybinding
.map(|key| key_shortcut(key.clone())), .keystrokes()
); .iter()
.map(|key| key_shortcut(key.clone())),
);
return Some(el); return Some(el);
} }
@@ -503,7 +514,6 @@ impl Render for PopupMenu {
.on_action(cx.listener(Self::dismiss)) .on_action(cx.listener(Self::dismiss))
.on_mouse_down_out(cx.listener(|this, _, cx| this.dismiss(&Dismiss, cx))) .on_mouse_down_out(cx.listener(|this, _, cx| this.dismiss(&Dismiss, cx)))
.popover_style(cx) .popover_style(cx)
.text_color(cx.theme().popover_foreground)
.relative() .relative()
.p_1() .p_1()
.child( .child(
@@ -557,7 +567,10 @@ impl Render for PopupMenu {
.h(px(1.)) .h(px(1.))
.mx_neg_1() .mx_neg_1()
.my_0p5() .my_0p5()
.bg(cx.theme().muted), .bg(cx
.theme()
.base
.step(cx, ColorScaleStep::TWO)),
) )
} }
PopupMenuItem::ElementItem { render, .. } => this PopupMenuItem::ElementItem { render, .. } => this

View File

@@ -1,4 +1,4 @@
use crate::theme::ActiveTheme; use crate::theme::{scale::ColorScaleStep, ActiveTheme};
use gpui::{ use gpui::{
div, prelude::FluentBuilder, px, relative, IntoElement, ParentElement, RenderOnce, Styled, div, prelude::FluentBuilder, px, relative, IntoElement, ParentElement, RenderOnce, Styled,
WindowContext, WindowContext,
@@ -44,7 +44,7 @@ impl RenderOnce for Progress {
.relative() .relative()
.h(px(self.height)) .h(px(self.height))
.rounded(rounded) .rounded(rounded)
.bg(cx.theme().progress_bar.opacity(0.2)) .bg(cx.theme().accent.step(cx, ColorScaleStep::THREE))
.child( .child(
div() div()
.absolute() .absolute()
@@ -52,7 +52,7 @@ impl RenderOnce for Progress {
.left_0() .left_0()
.h_full() .h_full()
.w(relative_w) .w(relative_w)
.bg(cx.theme().progress_bar) .bg(cx.theme().accent.step(cx, ColorScaleStep::NINE))
.map(|this| match self.value { .map(|this| match self.value {
v if v >= 100. => this.rounded(rounded), v if v >= 100. => this.rounded(rounded),
_ => this.rounded_l(rounded), _ => this.rounded_l(rounded),

View File

@@ -1,4 +1,8 @@
use crate::{h_flex, theme::ActiveTheme, IconName}; use crate::{
h_flex,
theme::{scale::ColorScaleStep, ActiveTheme},
IconName,
};
use gpui::{ use gpui::{
div, prelude::FluentBuilder, relative, svg, ElementId, InteractiveElement, IntoElement, div, prelude::FluentBuilder, relative, svg, ElementId, InteractiveElement, IntoElement,
ParentElement, RenderOnce, SharedString, StatefulInteractiveElement, Styled, WindowContext, ParentElement, RenderOnce, SharedString, StatefulInteractiveElement, Styled, WindowContext,
@@ -53,15 +57,14 @@ impl Radio {
impl RenderOnce for Radio { impl RenderOnce for Radio {
fn render(self, cx: &mut WindowContext) -> impl IntoElement { fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let color = if self.disabled { let color = if self.disabled {
cx.theme().primary.opacity(0.5) cx.theme().accent.step(cx, ColorScaleStep::FIVE)
} else { } else {
cx.theme().primary cx.theme().accent.step(cx, ColorScaleStep::NINE)
}; };
h_flex() h_flex()
.id(self.id) .id(self.id)
.gap_x_2() .gap_x_2()
.text_color(cx.theme().foreground)
.items_center() .items_center()
.line_height(relative(1.)) .line_height(relative(1.))
.child( .child(
@@ -80,9 +83,6 @@ impl RenderOnce for Radio {
.left_px() .left_px()
.size_3() .size_3()
.text_color(color) .text_color(color)
.when(self.checked, |this| {
this.text_color(cx.theme().primary_foreground)
})
.map(|this| match self.checked { .map(|this| match self.checked {
true => this.path(IconName::Check.path()), true => this.path(IconName::Check.path()),
false => this, false => this,

View File

@@ -1,15 +1,12 @@
use std::rc::Rc; use super::resize_handle;
use crate::{h_flex, v_flex, AxisExt};
use gpui::{ use gpui::{
canvas, div, prelude::FluentBuilder, px, relative, Along, AnyElement, AnyView, Axis, Bounds, canvas, div, prelude::FluentBuilder, px, relative, Along, AnyElement, AnyView, Axis, Bounds,
Element, Entity, EntityId, EventEmitter, IntoElement, IsZero, MouseMoveEvent, MouseUpEvent, Element, Entity, EntityId, EventEmitter, IntoElement, IsZero, MouseMoveEvent, MouseUpEvent,
ParentElement, Pixels, Render, StatefulInteractiveElement as _, Style, Styled, View, ParentElement, Pixels, Render, StatefulInteractiveElement as _, Style, Styled, View,
ViewContext, VisualContext as _, WeakView, WindowContext, ViewContext, VisualContext as _, WeakView, WindowContext,
}; };
use std::rc::Rc;
use crate::{h_flex, v_flex, AxisExt};
use super::resize_handle;
pub(crate) const PANEL_MIN_SIZE: Pixels = px(100.); pub(crate) const PANEL_MIN_SIZE: Pixels = px(100.);
@@ -237,7 +234,9 @@ impl ResizablePanelGroup {
} }
} }
} }
impl EventEmitter<ResizablePanelEvent> for ResizablePanelGroup {} impl EventEmitter<ResizablePanelEvent> for ResizablePanelGroup {}
impl Render for ResizablePanelGroup { impl Render for ResizablePanelGroup {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let view = cx.view().clone(); let view = cx.view().clone();

View File

@@ -1,11 +1,13 @@
use crate::{
theme::{scale::ColorScaleStep, ActiveTheme as _},
AxisExt as _,
};
use gpui::{ use gpui::{
div, prelude::FluentBuilder as _, px, Axis, Div, ElementId, InteractiveElement, IntoElement, div, prelude::FluentBuilder as _, px, Axis, Div, ElementId, InteractiveElement, IntoElement,
ParentElement as _, Pixels, RenderOnce, Stateful, StatefulInteractiveElement, Styled as _, ParentElement as _, Pixels, RenderOnce, Stateful, StatefulInteractiveElement, Styled as _,
WindowContext, WindowContext,
}; };
use crate::{theme::ActiveTheme as _, AxisExt as _};
pub(crate) const HANDLE_PADDING: Pixels = px(4.); pub(crate) const HANDLE_PADDING: Pixels = px(4.);
pub(crate) const HANDLE_SIZE: Pixels = px(1.); pub(crate) const HANDLE_SIZE: Pixels = px(1.);
@@ -34,6 +36,7 @@ impl InteractiveElement for ResizeHandle {
self.base.interactivity() self.base.interactivity()
} }
} }
impl StatefulInteractiveElement for ResizeHandle {} impl StatefulInteractiveElement for ResizeHandle {}
impl RenderOnce for ResizeHandle { impl RenderOnce for ResizeHandle {
@@ -62,7 +65,7 @@ impl RenderOnce for ResizeHandle {
}) })
.child( .child(
div() div()
.bg(cx.theme().border) .bg(cx.theme().base.step(cx, ColorScaleStep::THREE))
.when(self.axis.is_horizontal(), |this| { .when(self.axis.is_horizontal(), |this| {
this.h_full().w(HANDLE_SIZE) this.h_full().w(HANDLE_SIZE)
}) })

View File

@@ -1,3 +1,9 @@
use crate::{
modal::Modal,
notification::{Notification, NotificationList},
theme::{scale::ColorScaleStep, ActiveTheme},
window_border,
};
use gpui::{ use gpui::{
div, AnyView, FocusHandle, InteractiveElement, IntoElement, ParentElement as _, Render, Styled, div, AnyView, FocusHandle, InteractiveElement, IntoElement, ParentElement as _, Render, Styled,
View, ViewContext, VisualContext as _, WindowContext, View, ViewContext, VisualContext as _, WindowContext,
@@ -7,13 +13,6 @@ use std::{
rc::Rc, rc::Rc,
}; };
use crate::{
modal::Modal,
notification::{Notification, NotificationList},
theme::ActiveTheme,
window_border,
};
/// Extension trait for [`WindowContext`] and [`ViewContext`] to add drawer functionality. /// Extension trait for [`WindowContext`] and [`ViewContext`] to add drawer functionality.
pub trait ContextModal: Sized { pub trait ContextModal: Sized {
/// Opens a Modal. /// Opens a Modal.
@@ -268,8 +267,8 @@ impl Render for Root {
.relative() .relative()
.size_full() .size_full()
.font_family(".SystemUIFont") .font_family(".SystemUIFont")
.bg(cx.theme().background) .bg(cx.theme().base.step(cx, ColorScaleStep::ONE))
.text_color(cx.theme().foreground) .text_color(cx.theme().base.step(cx, ColorScaleStep::TWELVE))
.child(self.view.clone()), .child(self.view.clone()),
) )
} }

View File

@@ -1,4 +1,4 @@
use crate::theme::ActiveTheme; use crate::theme::{scale::ColorScaleStep, ActiveTheme};
use gpui::{ use gpui::{
bounce, div, ease_in_out, Animation, AnimationExt, Div, IntoElement, ParentElement as _, bounce, div, ease_in_out, Animation, AnimationExt, Div, IntoElement, ParentElement as _,
RenderOnce, Styled, RenderOnce, Styled,
@@ -33,16 +33,18 @@ impl Styled for Skeleton {
impl RenderOnce for Skeleton { impl RenderOnce for Skeleton {
fn render(self, cx: &mut gpui::WindowContext) -> impl IntoElement { fn render(self, cx: &mut gpui::WindowContext) -> impl IntoElement {
div().child( div().child(
self.base.bg(cx.theme().skeleton).with_animation( self.base
"skeleton", .bg(cx.theme().base.step(cx, ColorScaleStep::THREE))
Animation::new(Duration::from_secs(2)) .with_animation(
.repeat() "skeleton",
.with_easing(bounce(ease_in_out)), Animation::new(Duration::from_secs(2))
move |this, delta| { .repeat()
let v = 1.0 - delta * 0.5; .with_easing(bounce(ease_in_out)),
this.opacity(v) move |this, delta| {
}, let v = 1.0 - delta * 0.5;
), this.opacity(v)
},
),
) )
} }
} }

View File

@@ -1,196 +0,0 @@
use crate::{theme::ActiveTheme, tooltip::Tooltip};
use gpui::{
canvas, div, prelude::FluentBuilder as _, px, relative, Axis, Bounds, DragMoveEvent, EntityId,
EventEmitter, InteractiveElement, IntoElement, MouseButton, MouseDownEvent, ParentElement as _,
Pixels, Point, Render, StatefulInteractiveElement as _, Styled, ViewContext,
VisualContext as _,
};
#[derive(Clone, Render)]
pub struct DragThumb(EntityId);
pub enum SliderEvent {
Change(f32),
}
/// A Slider element.
pub struct Slider {
axis: Axis,
min: f32,
max: f32,
step: f32,
value: f32,
bounds: Bounds<Pixels>,
}
impl Slider {
fn new(axis: Axis) -> Self {
Self {
axis,
min: 0.0,
max: 100.0,
step: 1.0,
value: 0.0,
bounds: Bounds::default(),
}
}
pub fn horizontal() -> Self {
Self::new(Axis::Horizontal)
}
/// Set the minimum value of the slider, default: 0.0
pub fn min(mut self, min: f32) -> Self {
self.min = min;
self
}
/// Set the maximum value of the slider, default: 100.0
pub fn max(mut self, max: f32) -> Self {
self.max = max;
self
}
/// Set the step value of the slider, default: 1.0
pub fn step(mut self, step: f32) -> Self {
self.step = step;
self
}
/// Set the default value of the slider, default: 0.0
pub fn default_value(mut self, value: f32) -> Self {
self.value = value;
self
}
/// Set the value of the slider.
pub fn set_value(&mut self, value: f32, cx: &mut gpui::ViewContext<Self>) {
self.value = value;
cx.notify();
}
/// Return percentage value of the slider, range of 0.0..1.0
fn relative_value(&self) -> f32 {
let step = self.step;
let value = self.value;
let min = self.min;
let max = self.max;
let relative_value = (value - min) / (max - min);
let relative_step = step / (max - min);
let relative_value = (relative_value / relative_step).round() * relative_step;
relative_value.clamp(0.0, 1.0)
}
/// Update value by mouse position
fn update_value_by_position(
&mut self,
position: Point<Pixels>,
cx: &mut gpui::ViewContext<Self>,
) {
let bounds = self.bounds;
let axis = self.axis;
let min = self.min;
let max = self.max;
let step = self.step;
let value = match axis {
Axis::Horizontal => {
let relative = (position.x - bounds.left()) / bounds.size.width;
min + (max - min) * relative
}
Axis::Vertical => {
let relative = (position.y - bounds.top()) / bounds.size.height;
max - (max - min) * relative
}
};
let value = (value / step).round() * step;
self.value = value.clamp(self.min, self.max);
cx.emit(SliderEvent::Change(self.value));
cx.notify();
}
fn render_thumb(&self, cx: &mut ViewContext<Self>) -> impl gpui::IntoElement {
let value = self.value;
let entity_id = cx.entity_id();
div()
.id("slider-thumb")
.on_drag(DragThumb(entity_id), |drag, _, cx| {
cx.stop_propagation();
cx.new_view(|_| drag.clone())
})
.on_drag_move(cx.listener(
move |view, e: &DragMoveEvent<DragThumb>, cx| match e.drag(cx) {
DragThumb(id) => {
if *id != entity_id {
return;
}
// set value by mouse position
view.update_value_by_position(e.event.position, cx)
}
},
))
.absolute()
.top(px(-5.))
.left(relative(self.relative_value()))
.ml(-px(8.))
.size_4()
.rounded_full()
.border_1()
.border_color(cx.theme().slider_bar.opacity(0.9))
.when(cx.theme().shadow, |this| this.shadow_md())
.bg(cx.theme().slider_thumb)
.tooltip(move |cx| Tooltip::new(format!("{}", value), cx))
}
fn on_mouse_down(&mut self, event: &MouseDownEvent, cx: &mut gpui::ViewContext<Self>) {
self.update_value_by_position(event.position, cx);
}
}
impl EventEmitter<SliderEvent> for Slider {}
impl Render for Slider {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
div()
.id("slider")
.on_mouse_down(MouseButton::Left, cx.listener(Self::on_mouse_down))
.h_5()
.child(
div()
.id("slider-bar")
.relative()
.w_full()
.my_1p5()
.h_1p5()
.bg(cx.theme().slider_bar.opacity(0.2))
.active(|this| this.bg(cx.theme().slider_bar.opacity(0.4)))
.rounded(px(3.))
.child(
div()
.absolute()
.top_0()
.left_0()
.h_full()
.w(relative(self.relative_value()))
.bg(cx.theme().slider_bar)
.rounded_l(px(3.)),
)
.child(self.render_thumb(cx))
.child({
let view = cx.view().clone();
canvas(
move |bounds, cx| view.update(cx, |r, _| r.bounds = bounds),
|_, _, _| {},
)
.absolute()
.size_full()
}),
)
}
}

View File

@@ -1,6 +1,6 @@
use crate::{ use crate::{
scroll::{Scrollable, ScrollbarAxis}, scroll::{Scrollable, ScrollbarAxis},
theme::ActiveTheme, theme::{scale::ColorScaleStep, ActiveTheme},
}; };
use gpui::{div, px, Axis, Div, Element, ElementId, EntityId, Pixels, Styled, WindowContext}; use gpui::{div, px, Axis, Div, Element, ElementId, EntityId, Pixels, Styled, WindowContext};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -64,9 +64,9 @@ pub trait StyledExt: Styled + Sized {
/// Set as Popover style /// Set as Popover style
fn popover_style(self, cx: &mut WindowContext) -> Self { fn popover_style(self, cx: &mut WindowContext) -> Self {
self.bg(cx.theme().popover) self.bg(cx.theme().background)
.border_1() .border_1()
.border_color(cx.theme().border) .border_color(cx.theme().base.step(cx, ColorScaleStep::FOUR))
.shadow_lg() .shadow_lg()
.rounded_lg() .rounded_lg()
} }

View File

@@ -105,7 +105,7 @@ impl Element for Switch {
let on_click = self.on_click.clone(); let on_click = self.on_click.clone();
let (bg, toggle_bg) = match self.checked { let (bg, toggle_bg) = match self.checked {
true => (theme.primary, theme.background), true => (theme.colors.primary, theme.background),
false => (theme.input, theme.background), false => (theme.input, theme.background),
}; };

View File

@@ -1,11 +1,12 @@
use crate::h_flex; use crate::{
use crate::theme::ActiveTheme; h_flex,
use gpui::prelude::FluentBuilder as _; theme::{scale::ColorScaleStep, ActiveTheme},
use gpui::{ };
div, AnyElement, Div, ElementId, IntoElement, ParentElement, RenderOnce, ScrollHandle, use gpui::{
StatefulInteractiveElement as _, Styled, WindowContext, div, prelude::FluentBuilder as _, px, AnyElement, Div, ElementId, InteractiveElement,
IntoElement, ParentElement, RenderOnce, ScrollHandle, StatefulInteractiveElement as _, Styled,
WindowContext,
}; };
use gpui::{px, InteractiveElement};
use smallvec::SmallVec; use smallvec::SmallVec;
#[derive(IntoElement)] #[derive(IntoElement)]
@@ -70,8 +71,7 @@ impl RenderOnce for TabBar {
.flex() .flex()
.flex_none() .flex_none()
.items_center() .items_center()
.bg(cx.theme().tab_bar) .bg(cx.theme().base.step(cx, ColorScaleStep::TWO))
.text_color(cx.theme().tab_foreground)
.child( .child(
div() div()
.id("border-b") .id("border-b")
@@ -79,7 +79,7 @@ impl RenderOnce for TabBar {
.bottom_0() .bottom_0()
.size_full() .size_full()
.border_b_1() .border_b_1()
.border_color(cx.theme().border), .border_color(cx.theme().base.step(cx, ColorScaleStep::THREE)),
) )
.when_some(self.prefix, |this, prefix| this.child(prefix)) .when_some(self.prefix, |this, prefix| this.child(prefix))
.child( .child(

View File

@@ -1,9 +1,10 @@
use crate::scroll::ScrollbarShow; use crate::scroll::ScrollbarShow;
use colors::hsl; use colors::{default_color_scales, hsl};
use gpui::{ use gpui::{
blue, hsla, transparent_black, AppContext, Global, Hsla, ModelContext, SharedString, blue, hsla, transparent_black, AppContext, Global, Hsla, ModelContext, SharedString,
ViewContext, WindowAppearance, WindowContext, ViewContext, WindowAppearance, WindowContext,
}; };
use scale::ColorScaleSet;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
pub mod colors; pub mod colors;
@@ -11,11 +12,11 @@ pub mod scale;
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct ThemeColors { pub struct ThemeColors {
pub background: Hsla,
pub border: Hsla, pub border: Hsla,
pub window_border: Hsla, pub window_border: Hsla,
pub accent: Hsla, pub accent: Hsla,
pub accent_foreground: Hsla, pub accent_foreground: Hsla,
pub background: Hsla,
pub card: Hsla, pub card: Hsla,
pub card_foreground: Hsla, pub card_foreground: Hsla,
pub danger: Hsla, pub danger: Hsla,
@@ -68,9 +69,9 @@ pub struct ThemeColors {
impl ThemeColors { impl ThemeColors {
pub fn light() -> Self { pub fn light() -> Self {
Self { Self {
background: hsl(0.0, 0.0, 100.),
accent: hsl(240.0, 5.0, 96.0), accent: hsl(240.0, 5.0, 96.0),
accent_foreground: hsl(240.0, 5.9, 10.0), accent_foreground: hsl(240.0, 5.9, 10.0),
background: hsl(0.0, 0.0, 100.),
border: hsl(240.0, 5.9, 90.0), border: hsl(240.0, 5.9, 90.0),
window_border: hsl(240.0, 5.9, 78.0), window_border: hsl(240.0, 5.9, 78.0),
card: hsl(0.0, 0.0, 100.0), card: hsl(0.0, 0.0, 100.0),
@@ -125,9 +126,9 @@ impl ThemeColors {
pub fn dark() -> Self { pub fn dark() -> Self {
Self { Self {
background: hsl(0.0, 0.0, 8.0),
accent: hsl(240.0, 3.7, 15.9), accent: hsl(240.0, 3.7, 15.9),
accent_foreground: hsl(0.0, 0.0, 78.0), accent_foreground: hsl(0.0, 0.0, 78.0),
background: hsl(0.0, 0.0, 8.0),
border: hsl(240.0, 3.7, 16.9), border: hsl(240.0, 3.7, 16.9),
window_border: hsl(240.0, 3.7, 28.0), window_border: hsl(240.0, 3.7, 28.0),
card: hsl(0.0, 0.0, 8.0), card: hsl(0.0, 0.0, 8.0),
@@ -291,10 +292,14 @@ pub fn init(cx: &mut AppContext) {
Theme::sync_system_appearance(cx) Theme::sync_system_appearance(cx)
} }
#[derive(Debug, Clone)]
pub struct Theme { pub struct Theme {
pub colors: ThemeColors, pub colors: ThemeColors,
pub mode: ThemeMode, /// Base colors.
pub base: ColorScaleSet,
/// Accent colors.
pub accent: ColorScaleSet,
/// Window appearances.
pub appearance: Appearance,
pub font_family: SharedString, pub font_family: SharedString,
pub font_size: f32, pub font_size: f32,
pub radius: f32, pub radius: f32,
@@ -331,78 +336,26 @@ impl Theme {
cx.global_mut::<Theme>() cx.global_mut::<Theme>()
} }
/// Apply a mask color to the theme.
pub fn apply_color(&mut self, mask_color: Hsla) {
self.title_bar = self.title_bar.apply(mask_color);
self.title_bar_border = self.title_bar_border.apply(mask_color);
self.background = self.background.apply(mask_color);
self.foreground = self.foreground.apply(mask_color);
self.card = self.card.apply(mask_color);
self.card_foreground = self.card_foreground.apply(mask_color);
self.popover = self.popover.apply(mask_color);
self.popover_foreground = self.popover_foreground.apply(mask_color);
self.primary = self.primary.apply(mask_color);
self.primary_hover = self.primary_hover.apply(mask_color);
self.primary_active = self.primary_active.apply(mask_color);
self.primary_foreground = self.primary_foreground.apply(mask_color);
self.secondary = self.secondary.apply(mask_color);
self.secondary_hover = self.secondary_hover.apply(mask_color);
self.secondary_active = self.secondary_active.apply(mask_color);
self.secondary_foreground = self.secondary_foreground.apply(mask_color);
self.muted = self.muted.apply(mask_color);
self.muted_foreground = self.muted_foreground.apply(mask_color);
self.accent = self.accent.apply(mask_color);
self.accent_foreground = self.accent_foreground.apply(mask_color);
self.border = self.border.apply(mask_color);
self.input = self.input.apply(mask_color);
self.ring = self.ring.apply(mask_color);
self.scrollbar = self.scrollbar.apply(mask_color);
self.scrollbar_thumb = self.scrollbar_thumb.apply(mask_color);
self.scrollbar_thumb_hover = self.scrollbar_thumb_hover.apply(mask_color);
self.drag_border = self.drag_border.apply(mask_color);
self.drop_target = self.drop_target.apply(mask_color);
self.tab_bar = self.tab_bar.apply(mask_color);
self.tab = self.tab.apply(mask_color);
self.tab_active = self.tab_active.apply(mask_color);
self.tab_foreground = self.tab_foreground.apply(mask_color);
self.tab_active_foreground = self.tab_active_foreground.apply(mask_color);
self.progress_bar = self.progress_bar.apply(mask_color);
self.slider_bar = self.slider_bar.apply(mask_color);
self.slider_thumb = self.slider_thumb.apply(mask_color);
self.list = self.list.apply(mask_color);
self.list_even = self.list_even.apply(mask_color);
self.list_head = self.list_head.apply(mask_color);
self.list_active = self.list_active.apply(mask_color);
self.list_active_border = self.list_active_border.apply(mask_color);
self.list_hover = self.list_hover.apply(mask_color);
self.link = self.link.apply(mask_color);
self.link_hover = self.link_hover.apply(mask_color);
self.link_active = self.link_active.apply(mask_color);
self.skeleton = self.skeleton.apply(mask_color);
self.title_bar = self.title_bar.apply(mask_color);
self.title_bar_border = self.title_bar_border.apply(mask_color);
}
/// Sync the theme with the system appearance /// Sync the theme with the system appearance
pub fn sync_system_appearance(cx: &mut AppContext) { pub fn sync_system_appearance(cx: &mut AppContext) {
match cx.window_appearance() { match cx.window_appearance() {
WindowAppearance::Dark | WindowAppearance::VibrantDark => { WindowAppearance::Dark | WindowAppearance::VibrantDark => {
Self::change(ThemeMode::Dark, cx) Self::change(Appearance::Dark, cx)
} }
WindowAppearance::Light | WindowAppearance::VibrantLight => { WindowAppearance::Light | WindowAppearance::VibrantLight => {
Self::change(ThemeMode::Light, cx) Self::change(Appearance::Light, cx)
} }
} }
} }
pub fn change(mode: ThemeMode, cx: &mut AppContext) { pub fn change(mode: Appearance, cx: &mut AppContext) {
let colors = match mode { let colors = match mode {
ThemeMode::Light => ThemeColors::light(), Appearance::Light => ThemeColors::light(),
ThemeMode::Dark => ThemeColors::dark(), Appearance::Dark => ThemeColors::dark(),
}; };
let mut theme = Theme::from(colors); let mut theme = Theme::from(colors);
theme.mode = mode; theme.appearance = mode;
cx.set_global(theme); cx.set_global(theme);
cx.refresh(); cx.refresh();
@@ -411,8 +364,12 @@ impl Theme {
impl From<ThemeColors> for Theme { impl From<ThemeColors> for Theme {
fn from(colors: ThemeColors) -> Self { fn from(colors: ThemeColors) -> Self {
let color_scales = default_color_scales();
Theme { Theme {
mode: ThemeMode::default(), base: color_scales.gray,
accent: color_scales.yellow,
appearance: Appearance::default(),
transparent: Hsla::transparent_black(), transparent: Hsla::transparent_black(),
font_size: 16.0, font_size: 16.0,
font_family: if cfg!(target_os = "macos") { font_family: if cfg!(target_os = "macos") {
@@ -431,13 +388,13 @@ impl From<ThemeColors> for Theme {
} }
#[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd, Eq)] #[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd, Eq)]
pub enum ThemeMode { pub enum Appearance {
#[default] #[default]
Light, Light,
Dark, Dark,
} }
impl ThemeMode { impl Appearance {
pub fn is_dark(&self) -> bool { pub fn is_dark(&self) -> bool {
matches!(self, Self::Dark) matches!(self, Self::Dark)
} }

View File

@@ -1,4 +1,4 @@
use crate::theme::{ActiveTheme, ThemeMode}; use crate::theme::{ActiveTheme, Appearance};
use gpui::{AppContext, Hsla, SharedString}; use gpui::{AppContext, Hsla, SharedString};
/// A collection of colors that are used to style the UI. /// A collection of colors that are used to style the UI.
@@ -280,16 +280,16 @@ impl ColorScaleSet {
} }
pub fn step(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla { pub fn step(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
match cx.theme().mode { match cx.theme().appearance {
ThemeMode::Light => self.light().step(step), Appearance::Light => self.light().step(step),
ThemeMode::Dark => self.dark().step(step), Appearance::Dark => self.dark().step(step),
} }
} }
pub fn step_alpha(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla { pub fn step_alpha(&self, cx: &AppContext, step: ColorScaleStep) -> Hsla {
match cx.theme().mode { match cx.theme().appearance {
ThemeMode::Light => self.light_alpha.step(step), Appearance::Light => self.light_alpha.step(step),
ThemeMode::Dark => self.dark_alpha.step(step), Appearance::Dark => self.dark_alpha.step(step),
} }
} }
} }

View File

@@ -1,4 +1,8 @@
use crate::{h_flex, theme::ActiveTheme, Icon, IconName, InteractiveElementExt as _, Sizable as _}; use crate::{
h_flex,
theme::{scale::ColorScaleStep, ActiveTheme},
Icon, IconName, InteractiveElementExt as _, Sizable as _,
};
use gpui::{ use gpui::{
black, div, prelude::FluentBuilder as _, px, relative, white, AnyElement, ClickEvent, Div, black, div, prelude::FluentBuilder as _, px, relative, white, AnyElement, ClickEvent, Div,
Element, Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement, Pixels, Element, Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement, Pixels,
@@ -6,9 +10,8 @@ use gpui::{
}; };
use std::rc::Rc; use std::rc::Rc;
pub const HEIGHT: Pixels = px(34.); const HEIGHT: Pixels = px(34.);
pub const TITLE_BAR_HEIGHT: Pixels = px(35.); const TITLE_BAR_HEIGHT: Pixels = px(35.);
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
const TITLE_BAR_LEFT_PADDING: Pixels = px(80.); const TITLE_BAR_LEFT_PADDING: Pixels = px(80.);
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
@@ -59,14 +62,14 @@ impl Default for TitleBar {
// We don't need implementation the click event for the control buttons. // We don't need implementation the click event for the control buttons.
// If user clicked in the bounds, the window event will be triggered. // If user clicked in the bounds, the window event will be triggered.
#[derive(IntoElement, Clone)] #[derive(IntoElement, Clone)]
enum ControlIcon { enum Control {
Minimize, Minimize,
Restore, Restore,
Maximize, Maximize,
Close { on_close_window: OnCloseWindow }, Close { on_close_window: OnCloseWindow },
} }
impl ControlIcon { impl Control {
fn minimize() -> Self { fn minimize() -> Self {
Self::Minimize Self::Minimize
} }
@@ -106,7 +109,7 @@ impl ControlIcon {
} }
fn fg(&self, cx: &WindowContext) -> Hsla { fn fg(&self, cx: &WindowContext) -> Hsla {
if cx.theme().mode.is_dark() { if cx.theme().appearance.is_dark() {
white() white()
} else { } else {
black() black()
@@ -114,7 +117,7 @@ impl ControlIcon {
} }
fn hover_fg(&self, cx: &WindowContext) -> Hsla { fn hover_fg(&self, cx: &WindowContext) -> Hsla {
if self.is_close() || cx.theme().mode.is_dark() { if self.is_close() || cx.theme().appearance.is_dark() {
white() white()
} else { } else {
black() black()
@@ -129,7 +132,7 @@ impl ControlIcon {
b: 32.0 / 255.0, b: 32.0 / 255.0,
a: 1.0, a: 1.0,
} }
} else if cx.theme().mode.is_dark() { } else if cx.theme().appearance.is_dark() {
Rgba { Rgba {
r: 0.9, r: 0.9,
g: 0.9, g: 0.9,
@@ -147,7 +150,7 @@ impl ControlIcon {
} }
} }
impl RenderOnce for ControlIcon { impl RenderOnce for Control {
fn render(self, cx: &mut WindowContext) -> impl IntoElement { fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let fg = self.fg(cx); let fg = self.fg(cx);
let hover_fg = self.hover_fg(cx); let hover_fg = self.hover_fg(cx);
@@ -155,7 +158,7 @@ impl RenderOnce for ControlIcon {
let icon = self.clone(); let icon = self.clone();
let is_linux = cfg!(target_os = "linux"); let is_linux = cfg!(target_os = "linux");
let on_close_window = match &icon { let on_close_window = match &icon {
ControlIcon::Close { on_close_window } => on_close_window.clone(), Control::Close { on_close_window } => on_close_window.clone(),
_ => None, _ => None,
}; };
@@ -214,14 +217,14 @@ impl RenderOnce for WindowControls {
.justify_center() .justify_center()
.content_stretch() .content_stretch()
.h_full() .h_full()
.child(ControlIcon::minimize()) .child(Control::minimize())
.child(if cx.is_maximized() { .child(if cx.is_maximized() {
ControlIcon::restore() Control::restore()
} else { } else {
ControlIcon::maximize() Control::maximize()
}), }),
) )
.child(ControlIcon::close(self.on_close_window)) .child(Control::close(self.on_close_window))
} }
} }
@@ -249,8 +252,8 @@ impl RenderOnce for TitleBar {
.justify_between() .justify_between()
.h(HEIGHT) .h(HEIGHT)
.border_b_1() .border_b_1()
.border_color(cx.theme().title_bar_border.opacity(0.7)) .border_color(cx.theme().base.step(cx, ColorScaleStep::THREE))
.bg(cx.theme().title_bar) .bg(cx.theme().base.step(cx, ColorScaleStep::ONE))
.when(cx.is_fullscreen(), |this| this.pl(px(12.))) .when(cx.is_fullscreen(), |this| this.pl(px(12.)))
.on_double_click(|_, cx| cx.zoom_window()) .on_double_click(|_, cx| cx.zoom_window())
.child( .child(
@@ -292,7 +295,6 @@ impl IntoElement for TitleBarElement {
impl Element for TitleBarElement { impl Element for TitleBarElement {
type RequestLayoutState = (); type RequestLayoutState = ();
type PrepaintState = (); type PrepaintState = ();
fn id(&self) -> Option<gpui::ElementId> { fn id(&self) -> Option<gpui::ElementId> {
@@ -328,7 +330,6 @@ impl Element for TitleBarElement {
) -> Self::PrepaintState { ) -> Self::PrepaintState {
} }
#[allow(unused_variables)]
fn paint( fn paint(
&mut self, &mut self,
_: Option<&gpui::GlobalElementId>, _: Option<&gpui::GlobalElementId>,
@@ -338,6 +339,7 @@ impl Element for TitleBarElement {
cx: &mut WindowContext, cx: &mut WindowContext,
) { ) {
use gpui::{MouseButton, MouseMoveEvent, MouseUpEvent}; use gpui::{MouseButton, MouseMoveEvent, MouseUpEvent};
cx.on_mouse_event(move |ev: &MouseMoveEvent, _, cx: &mut WindowContext| { cx.on_mouse_event(move |ev: &MouseMoveEvent, _, cx: &mut WindowContext| {
if bounds.contains(&ev.position) && ev.pressed_button == Some(MouseButton::Left) { if bounds.contains(&ev.position) && ev.pressed_button == Some(MouseButton::Left) {
cx.start_window_move(); cx.start_window_move();

View File

@@ -1,18 +1,16 @@
use crate::theme::{scale::ColorScaleStep, ActiveTheme};
use gpui::{ use gpui::{
div, px, AnyView, IntoElement, ParentElement, Render, SharedString, Styled, ViewContext, div, px, IntoElement, ParentElement, Render, SharedString, Styled, View, ViewContext,
VisualContext, WindowContext, VisualContext, WindowContext,
}; };
use crate::theme::ActiveTheme;
pub struct Tooltip { pub struct Tooltip {
text: SharedString, text: SharedString,
} }
impl Tooltip { impl Tooltip {
#[allow(clippy::new_ret_no_self)] pub fn new(text: impl Into<SharedString>, cx: &mut WindowContext) -> View<Self> {
pub fn new(text: impl Into<SharedString>, cx: &mut WindowContext) -> AnyView { cx.new_view(|_| Self { text: text.into() })
cx.new_view(|_| Self { text: text.into() }).into()
} }
} }
@@ -23,10 +21,8 @@ impl Render for Tooltip {
div() div()
.font_family(".SystemUIFont") .font_family(".SystemUIFont")
.m_3() .m_3()
.bg(cx.theme().popover) .bg(cx.theme().base.step(cx, ColorScaleStep::TWELVE))
.text_color(cx.theme().popover_foreground) .text_color(cx.theme().base.step(cx, ColorScaleStep::ONE))
.border_1()
.border_color(cx.theme().border)
.shadow_md() .shadow_md()
.rounded(px(6.)) .rounded(px(6.))
.py_0p5() .py_0p5()

View File

@@ -1,19 +1,17 @@
use crate::theme::ActiveTheme;
use gpui::{ use gpui::{
canvas, div, point, prelude::FluentBuilder as _, px, AnyElement, Bounds, CursorStyle, canvas, div, point, prelude::FluentBuilder as _, px, AnyElement, Bounds, CursorStyle,
Decorations, Edges, Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement, Decorations, Edges, Hsla, InteractiveElement as _, IntoElement, MouseButton, ParentElement,
Pixels, Point, RenderOnce, ResizeEdge, Size, Styled as _, WindowContext, Pixels, Point, RenderOnce, ResizeEdge, Size, Styled as _, WindowContext,
}; };
use crate::theme::ActiveTheme; pub(crate) const BORDER_SIZE: Pixels = Pixels(1.0);
pub(crate) const BORDER_RADIUS: Pixels = Pixels(0.0);
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
pub(crate) const SHADOW_SIZE: Pixels = Pixels(0.0); pub(crate) const SHADOW_SIZE: Pixels = Pixels(0.0);
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub(crate) const SHADOW_SIZE: Pixels = Pixels(12.0); pub(crate) const SHADOW_SIZE: Pixels = Pixels(12.0);
pub(crate) const BORDER_SIZE: Pixels = Pixels(1.0);
pub(crate) const BORDER_RADIUS: Pixels = Pixels(0.0);
/// Create a new window border. /// Create a new window border.
pub fn window_border() -> WindowBorder { pub fn window_border() -> WindowBorder {
WindowBorder::new() WindowBorder::new()