diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index baef402de8ce9c38a7c3a58b7f170274f1e54131..856244f6a1799697444f7b49f18c68b4e943b3a9 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -1,10 +1,10 @@ use std::sync::Arc; use chrono::DateTime; -use gpui3::{px, relative, view, Context, Size, View}; +use gpui3::{px, relative, rems, view, Context, Size, View}; -use crate::settings::Settings; -use crate::{prelude::*, Button}; +use crate::settings::FakeSettings; +use crate::{prelude::*, user_settings_mut, Button, SettingValue}; use crate::{ theme, v_stack, AssistantPanel, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, LanguageSelector, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel, @@ -12,13 +12,13 @@ use crate::{ }; #[derive(Clone)] -pub struct GPUI2UIDebug { +pub struct Gpui2UiDebug { pub in_livestream: bool, pub enable_user_settings: bool, pub show_toast: bool, } -impl Default for GPUI2UIDebug { +impl Default for Gpui2UiDebug { fn default() -> Self { Self { in_livestream: false, @@ -44,8 +44,7 @@ pub struct Workspace { right_panel_scroll_state: ScrollState, tab_bar_scroll_state: ScrollState, bottom_panel_scroll_state: ScrollState, - debug: GPUI2UIDebug, - settings: Settings, + debug: Gpui2UiDebug, } impl Workspace { @@ -65,8 +64,7 @@ impl Workspace { right_panel_scroll_state: ScrollState::default(), tab_bar_scroll_state: ScrollState::default(), bottom_panel_scroll_state: ScrollState::default(), - debug: GPUI2UIDebug::default(), - settings: Settings::default(), + debug: Gpui2UiDebug::default(), } } @@ -155,11 +153,8 @@ impl Workspace { } pub fn debug_toggle_user_settings(&mut self, cx: &mut ViewContext) { - if self.debug.enable_user_settings { - self.debug.enable_user_settings = false; - } else { - self.debug.enable_user_settings = true; - } + self.debug.enable_user_settings = !self.debug.enable_user_settings; + cx.notify(); } @@ -188,6 +183,20 @@ impl Workspace { pub fn render(&mut self, cx: &mut ViewContext) -> impl Element { let theme = theme(cx).clone(); + // HACK: This should happen inside of `debug_toggle_user_settings`, but + // we don't have `cx.global::()` in event handlers at the moment. + // Need to talk with Nathan/Antonio about this. + { + let settings = user_settings_mut(cx); + + if self.debug.enable_user_settings { + settings.list_indent_depth = SettingValue::UserDefined(rems(0.5).into()); + settings.ui_scale = SettingValue::UserDefined(1.25); + } else { + *settings = FakeSettings::default(); + } + } + let root_group = PaneGroup::new_panes( vec![Pane::new( ScrollState::default(), diff --git a/crates/ui2/src/settings.rs b/crates/ui2/src/settings.rs index ffc2ef785183ce64044ec6733902fa903f61fe70..995da199cf90a6b600e9fc14a9eaaa2bbe2cf3b0 100644 --- a/crates/ui2/src/settings.rs +++ b/crates/ui2/src/settings.rs @@ -1,7 +1,9 @@ use std::ops::Deref; +use std::sync::Arc; use gpui3::{ - rems, AbsoluteLength, AnyElement, BorrowAppContext, Bounds, LayoutId, Pixels, WindowContext, + rems, AbsoluteLength, AnyElement, BorrowAppContext, Bounds, Interactive, LayoutId, Pixels, + WindowContext, }; use crate::prelude::*; @@ -11,6 +13,10 @@ pub fn user_settings(cx: &WindowContext) -> FakeSettings { cx.global::().clone() } +pub fn user_settings_mut<'cx>(cx: &'cx mut WindowContext) -> &'cx mut FakeSettings { + cx.global_mut::() +} + #[derive(Clone)] pub enum SettingValue { UserDefined(T), @@ -143,3 +149,32 @@ impl Element for WithSettings { }); } } + +impl Interactive for WithSettings { + fn listeners(&mut self) -> &mut gpui3::EventListeners { + self.child.listeners() + } + + fn on_mouse_down( + mut self, + button: gpui3::MouseButton, + handler: impl Fn(&mut Self::ViewState, &gpui3::MouseDownEvent, &mut ViewContext) + + Send + + Sync + + 'static, + ) -> Self + where + Self: Sized, + { + println!("WithSettings on_mouse_down"); + + let settings = self.settings.clone(); + + self.listeners() + .mouse_down + .push(Arc::new(move |view, event, bounds, phase, cx| { + cx.with_global(settings.clone(), |cx| handler(view, event, cx)) + })); + self + } +}