wip
This commit is contained in:
@@ -4,7 +4,7 @@ use gpui::{
|
||||
Window, div, px,
|
||||
};
|
||||
use settings::AppSettings;
|
||||
use theme::{ActiveTheme, Theme, ThemeMode};
|
||||
use theme::{ActiveTheme, Appearance, Theme};
|
||||
use ui::button::{Button, ButtonVariants};
|
||||
use ui::group_box::{GroupBox, GroupBoxVariants};
|
||||
use ui::input::{Input, InputState};
|
||||
@@ -47,10 +47,10 @@ impl Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the theme mode (light or dark)
|
||||
fn set_theme_mode(mode: ThemeMode, window: &mut Window, cx: &mut App) {
|
||||
AppSettings::update_theme_mode(mode, cx);
|
||||
Theme::change(mode, Some(window), cx);
|
||||
/// Set the appearance (light or dark)
|
||||
fn set_appearance(appearance: Appearance, window: &mut Window, cx: &mut App) {
|
||||
AppSettings::update_appearance(appearance, cx);
|
||||
Theme::change(appearance, Some(window), cx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ impl Render for Preferences {
|
||||
let screening = AppSettings::get_screening(cx);
|
||||
let hide_avatar = AppSettings::get_hide_avatar(cx);
|
||||
let nip4e = AppSettings::get_nip4e(cx);
|
||||
let theme_mode = AppSettings::get_theme_mode(cx);
|
||||
let appearance = AppSettings::get_appearance(cx);
|
||||
|
||||
v_flex()
|
||||
.gap_4()
|
||||
@@ -114,18 +114,22 @@ impl Render for Preferences {
|
||||
)
|
||||
.child(
|
||||
Button::new("theme-mode")
|
||||
.label(theme_mode.name())
|
||||
.label(if appearance.is_dark() {
|
||||
"Dark"
|
||||
} else {
|
||||
"Light"
|
||||
})
|
||||
.ghost_alt()
|
||||
.small()
|
||||
.dropdown_menu(|this, _window, _cx| {
|
||||
this.item(PopupMenuItem::new("Light").on_click(
|
||||
|_, window, cx| {
|
||||
Self::set_theme_mode(ThemeMode::Light, window, cx);
|
||||
Self::set_appearance(Appearance::Light, window, cx);
|
||||
},
|
||||
))
|
||||
.item(
|
||||
PopupMenuItem::new("Dark").on_click(|_, window, cx| {
|
||||
Self::set_theme_mode(ThemeMode::Dark, window, cx);
|
||||
Self::set_appearance(Appearance::Dark, window, cx);
|
||||
}),
|
||||
)
|
||||
}),
|
||||
|
||||
+20
-12
@@ -15,7 +15,7 @@ use nostr_sdk::prelude::*;
|
||||
use serde::Deserialize;
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use state::{NostrRegistry, StateEvent};
|
||||
use theme::{ActiveTheme, SIDEBAR_WIDTH, Theme, ThemeRegistry};
|
||||
use theme::{ActiveTheme, SIDEBAR_WIDTH, Theme, ThemeRegistry, ThemeVariant};
|
||||
use ui::button::{Button, ButtonVariants};
|
||||
use ui::dock::{self, DockArea, DockLayout, DockPlacement, Panel, PanelHandle};
|
||||
use ui::notification::{Notification, NotificationKind};
|
||||
@@ -464,17 +464,20 @@ impl Workspace {
|
||||
}
|
||||
|
||||
fn theme_selector(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
window.open_dialog(cx, move |this, _window, cx| {
|
||||
let registry = ThemeRegistry::global(cx);
|
||||
let themes = registry.read(cx).themes();
|
||||
let appearance = cx.theme().appearance;
|
||||
let variants: Vec<ThemeVariant> = ThemeRegistry::active()
|
||||
.variants_for(appearance)
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
window.open_dialog(cx, move |this, _window, cx| {
|
||||
this.width(px(520.))
|
||||
.show_close(true)
|
||||
.title("Select theme")
|
||||
.child(v_flex().gap_2().w_full().children({
|
||||
let mut items = vec![];
|
||||
|
||||
for (ix, (path, theme)) in themes.iter().enumerate() {
|
||||
for (ix, variant) in variants.iter().enumerate() {
|
||||
items.push(
|
||||
h_flex()
|
||||
.id(ix)
|
||||
@@ -491,13 +494,15 @@ impl Workspace {
|
||||
.gap_1p5()
|
||||
.flex_1()
|
||||
.text_sm()
|
||||
.child(theme.name.clone())
|
||||
.child(SharedString::from(variant.name.clone()))
|
||||
.child(
|
||||
div()
|
||||
.text_xs()
|
||||
.italic()
|
||||
.text_color(cx.theme().text_muted)
|
||||
.child(theme.author.clone()),
|
||||
.child(SharedString::from(
|
||||
variant.family_id.clone(),
|
||||
)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
@@ -511,9 +516,9 @@ impl Workspace {
|
||||
.ghost()
|
||||
.small()
|
||||
.on_click({
|
||||
let theme = theme.clone();
|
||||
let url = variant.source.url.clone();
|
||||
move |_ev, _window, cx| {
|
||||
cx.open_url(&theme.url);
|
||||
cx.open_url(&url);
|
||||
}
|
||||
}),
|
||||
)
|
||||
@@ -523,13 +528,16 @@ impl Workspace {
|
||||
.primary()
|
||||
.small()
|
||||
.on_click({
|
||||
let path = path.clone();
|
||||
let id = variant.id.clone();
|
||||
move |_ev, window, cx| {
|
||||
let settings = AppSettings::global(cx);
|
||||
let path = path.clone();
|
||||
|
||||
settings.update(cx, |this, cx| {
|
||||
this.set_theme(path, window, cx);
|
||||
this.set_theme_variant(
|
||||
id.clone(),
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user