Define theme/ui text style settings in theme crate

This commit is contained in:
Max Brunsfeld
2023-05-17 14:44:59 -07:00
parent 5c729c0e56
commit 67a25126d4
86 changed files with 530 additions and 637 deletions
-3
View File
@@ -408,7 +408,6 @@ mod tests {
use gpui::{AppContext, BorrowWindowContext, TestAppContext, ViewContext, WindowContext};
use project::{FakeFs, Project};
use theme::ThemeRegistry;
use super::*;
use crate::{
@@ -468,7 +467,6 @@ mod tests {
project.clone(),
Arc::new(AppState {
languages: project.read(cx).languages().clone(),
themes: ThemeRegistry::new((), cx.font_cache().clone()),
client: project.read(cx).client(),
user_store: project.read(cx).user_store(),
fs: project.read(cx).fs().clone(),
@@ -615,7 +613,6 @@ mod tests {
project.clone(),
Arc::new(AppState {
languages: project.read(cx).languages().clone(),
themes: ThemeRegistry::new((), cx.font_cache().clone()),
client: project.read(cx).client(),
user_store: project.read(cx).user_store(),
fs: project.read(cx).fs().clone(),
@@ -6,7 +6,6 @@ use gpui::{
platform::MouseButton,
AnyElement, Element, Entity, View, ViewContext, ViewHandle, WeakViewHandle,
};
use settings::Settings;
pub struct ToggleDockButton {
workspace: WeakViewHandle<Workspace>,
@@ -43,7 +42,7 @@ impl View for ToggleDockButton {
let dock_position = workspace.read(cx).dock.position;
let dock_pane = workspace.read(cx).dock_pane().clone();
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
let button = MouseEventHandler::<Self, _>::new(0, cx, {
let theme = theme.clone();
+3 -6
View File
@@ -149,6 +149,8 @@ impl Workspace {
}
pub mod simple_message_notification {
use super::Notification;
use crate::Workspace;
use gpui::{
actions,
elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text},
@@ -158,13 +160,8 @@ pub mod simple_message_notification {
};
use menu::Cancel;
use serde::Deserialize;
use settings::Settings;
use std::{borrow::Cow, sync::Arc};
use crate::Workspace;
use super::Notification;
actions!(message_notifications, [CancelMessageNotification]);
#[derive(Clone, Default, Deserialize, PartialEq)]
@@ -240,7 +237,7 @@ pub mod simple_message_notification {
}
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::AnyElement<Self> {
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
let theme = &theme.simple_message_notification;
enum MessageNotificationTag {}
+8 -9
View File
@@ -30,7 +30,6 @@ use gpui::{
};
use project::{Project, ProjectEntryId, ProjectPath};
use serde::Deserialize;
use settings::Settings;
use std::{any::Any, cell::RefCell, cmp, mem, path::Path, rc::Rc};
use theme::Theme;
use util::ResultExt;
@@ -1297,7 +1296,7 @@ impl Pane {
}
fn render_tabs(&mut self, cx: &mut ViewContext<Self>) -> impl Element<Self> {
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
let pane = cx.handle().downgrade();
let autoscroll = if mem::take(&mut self.autoscroll) {
@@ -1328,7 +1327,7 @@ impl Pane {
let pane = pane.clone();
let detail = detail.clone();
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
let mut tooltip_theme = theme.tooltip.clone();
tooltip_theme.max_text_width = None;
let tab_tooltip_text = item.tab_tooltip_text(cx).map(|a| a.to_string());
@@ -1406,7 +1405,7 @@ impl Pane {
pane: pane.clone(),
},
{
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
let detail = detail.clone();
move |dragged_item: &DraggedItem, cx: &mut ViewContext<Workspace>| {
@@ -1699,7 +1698,7 @@ impl View for Pane {
if let Some(active_item) = self.active_item() {
Flex::column()
.with_child({
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
let mut stack = Stack::new();
@@ -1765,7 +1764,7 @@ impl View for Pane {
.into_any()
} else {
enum EmptyPane {}
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
dragged_item_receiver::<EmptyPane, _, _>(0, 0, false, None, cx, |_, cx| {
self.render_blank_pane(&theme, cx)
@@ -1862,7 +1861,7 @@ fn render_tab_bar_button<F: 'static + Fn(&mut Pane, &mut EventContext<Pane>)>(
Stack::new()
.with_child(
MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
let theme = &cx.global::<Settings>().theme.workspace.tab_bar;
let theme = &theme::current(cx).workspace.tab_bar;
let style = theme.pane_button.style_for(mouse_state, false);
Svg::new(icon)
.with_color(style.color)
@@ -2024,7 +2023,7 @@ impl<V: View> Element<V> for PaneBackdrop<V> {
view: &mut V,
cx: &mut ViewContext<V>,
) -> Self::PaintState {
let background = cx.global::<Settings>().theme.editor.background;
let background = theme::current(cx).editor.background;
let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
@@ -2536,7 +2535,7 @@ mod tests {
fn init_test(cx: &mut TestAppContext) {
cx.update(|cx| {
cx.set_global(SettingsStore::test(cx));
cx.set_global(settings::Settings::test(cx));
theme::init((), cx);
crate::init_settings(cx);
});
}
@@ -1,3 +1,5 @@
use super::DraggedItem;
use crate::{Pane, SplitDirection, Workspace};
use drag_and_drop::DragAndDrop;
use gpui::{
color::Color,
@@ -8,11 +10,6 @@ use gpui::{
AppContext, Element, EventContext, MouseState, Quad, View, ViewContext, WeakViewHandle,
};
use project::ProjectEntryId;
use settings::Settings;
use crate::{Pane, SplitDirection, Workspace};
use super::DraggedItem;
pub fn dragged_item_receiver<Tag, D, F>(
region_id: usize,
@@ -225,8 +222,5 @@ fn drop_split_direction(
}
fn overlay_color(cx: &AppContext) -> Color {
cx.global::<Settings>()
.theme
.workspace
.drop_target_overlay_color
theme::current(cx).workspace.drop_target_overlay_color
}
+1 -2
View File
@@ -12,7 +12,6 @@ use gpui::{
platform::MouseButton,
AppContext, Entity, Task, View, ViewContext,
};
use settings::Settings;
use smallvec::SmallVec;
use std::{
borrow::Cow,
@@ -88,7 +87,7 @@ impl View for SharedScreen {
}
})
.contained()
.with_style(cx.global::<Settings>().theme.shared_screen)
.with_style(theme::current(cx).shared_screen)
})
.on_down(MouseButton::Left, |_, _, cx| cx.focus_parent())
.into_any()
+2 -3
View File
@@ -4,7 +4,6 @@ use gpui::{
AppContext, Entity, Subscription, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
};
use serde::Deserialize;
use settings::Settings;
use std::rc::Rc;
pub trait SidebarItem: View {
@@ -192,7 +191,7 @@ impl View for Sidebar {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(active_item) = self.active_item() {
enum ResizeHandleTag {}
let style = &cx.global::<Settings>().theme.workspace.sidebar;
let style = &theme::current(cx).workspace.sidebar;
ChildView::new(active_item.as_any(), cx)
.contained()
.with_style(style.container)
@@ -231,7 +230,7 @@ impl View for SidebarButtons {
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = &cx.global::<Settings>().theme;
let theme = &theme::current(cx);
let tooltip_style = theme.tooltip.clone();
let theme = &theme.workspace.status_bar.sidebar_buttons;
let sidebar = self.sidebar.read(cx);
+1 -2
View File
@@ -11,7 +11,6 @@ use gpui::{
AnyElement, AnyViewHandle, Entity, LayoutContext, SceneBuilder, SizeConstraint, Subscription,
View, ViewContext, ViewHandle, WindowContext,
};
use settings::Settings;
pub trait StatusItemView: View {
fn set_active_pane_item(
@@ -47,7 +46,7 @@ impl View for StatusBar {
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
let theme = &theme::current(cx).workspace.status_bar;
StatusBarElement {
left: Flex::row()
+2 -3
View File
@@ -3,7 +3,6 @@ use gpui::{
elements::*, platform::CursorStyle, platform::MouseButton, Action, AnyElement, AnyViewHandle,
AppContext, Entity, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
};
use settings::Settings;
pub trait ToolbarItemView: View {
fn set_active_pane_item(
@@ -68,7 +67,7 @@ impl View for Toolbar {
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = &cx.global::<Settings>().theme.workspace.toolbar;
let theme = &theme::current(cx).workspace.toolbar;
let mut primary_left_items = Vec::new();
let mut primary_right_items = Vec::new();
@@ -131,7 +130,7 @@ impl View for Toolbar {
let height = theme.height * primary_items_row_count as f32;
let nav_button_height = theme.height;
let button_style = theme.nav_button;
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
let tooltip_style = theme::current(cx).tooltip.clone();
Flex::column()
.with_child(
+6 -11
View File
@@ -76,12 +76,11 @@ pub use persistence::{
use postage::prelude::Stream;
use project::{Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};
use serde::Deserialize;
use settings::Settings;
use shared_screen::SharedScreen;
use sidebar::{Sidebar, SidebarButtons, SidebarSide, ToggleSidebarItem};
use status_bar::StatusBar;
pub use status_bar::StatusItemView;
use theme::{Theme, ThemeRegistry};
use theme::Theme;
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
use util::{async_iife, paths, ResultExt};
pub use workspace_settings::{AutosaveSetting, DockAnchor, GitGutterSetting, WorkspaceSettings};
@@ -276,7 +275,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
cx.add_action(
move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext<Workspace>| {
create_and_open_local_file(&paths::SETTINGS, cx, || {
Settings::initial_user_settings_content(&Assets)
settings::initial_user_settings_content(&Assets)
.as_ref()
.into()
})
@@ -361,7 +360,6 @@ pub fn register_deserializable_item<I: Item>(cx: &mut AppContext) {
pub struct AppState {
pub languages: Arc<LanguageRegistry>,
pub themes: Arc<ThemeRegistry>,
pub client: Arc<client::Client>,
pub user_store: ModelHandle<client::UserStore>,
pub fs: Arc<dyn fs::Fs>,
@@ -379,7 +377,6 @@ impl AppState {
if !cx.has_global::<SettingsStore>() {
cx.set_global(SettingsStore::test(cx));
cx.set_global(Settings::test(cx));
}
let fs = fs::FakeFs::new(cx.background().clone());
@@ -387,14 +384,13 @@ impl AppState {
let http_client = util::http::FakeHttpClient::with_404_response();
let client = Client::new(http_client.clone(), cx);
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let themes = ThemeRegistry::new((), cx.font_cache().clone());
theme::init((), cx);
client::init(&client, cx);
crate::init_settings(cx);
Arc::new(Self {
client,
themes,
fs,
languages,
user_store,
@@ -1992,7 +1988,7 @@ impl Workspace {
enum DisconnectedOverlay {}
Some(
MouseEventHandler::<DisconnectedOverlay, _>::new(0, cx, |_, cx| {
let theme = &cx.global::<Settings>().theme;
let theme = &theme::current(cx);
Label::new(
"Your connection to the remote project has been lost.",
theme.workspace.disconnected_overlay.text.clone(),
@@ -2630,7 +2626,6 @@ impl Workspace {
pub fn test_new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
let app_state = Arc::new(AppState {
languages: project.read(cx).languages().clone(),
themes: ThemeRegistry::new((), cx.font_cache().clone()),
client: project.read(cx).client(),
user_store: project.read(cx).user_store(),
fs: project.read(cx).fs().clone(),
@@ -2776,7 +2771,7 @@ impl View for Workspace {
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = cx.global::<Settings>().theme.clone();
let theme = theme::current(cx).clone();
Stack::new()
.with_child(
Flex::column()
@@ -3798,7 +3793,7 @@ mod tests {
cx.foreground().forbid_parking();
cx.update(|cx| {
cx.set_global(SettingsStore::test(cx));
cx.set_global(Settings::test(cx));
theme::init((), cx);
language::init(cx);
crate::init_settings(cx);
});