Add ability to toggle user settings
This commit is contained in:
parent
4aac733238
commit
a869de3b1f
2 changed files with 59 additions and 15 deletions
|
@ -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<Self>) {
|
||||
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<Self>) -> impl Element<ViewState = Self> {
|
||||
let theme = theme(cx).clone();
|
||||
|
||||
// HACK: This should happen inside of `debug_toggle_user_settings`, but
|
||||
// we don't have `cx.global::<FakeSettings>()` 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(),
|
||||
|
|
|
@ -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::<FakeSettings>().clone()
|
||||
}
|
||||
|
||||
pub fn user_settings_mut<'cx>(cx: &'cx mut WindowContext) -> &'cx mut FakeSettings {
|
||||
cx.global_mut::<FakeSettings>()
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum SettingValue<T> {
|
||||
UserDefined(T),
|
||||
|
@ -143,3 +149,32 @@ impl<E: Element> Element for WithSettings<E> {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Element + Interactive> Interactive for WithSettings<E> {
|
||||
fn listeners(&mut self) -> &mut gpui3::EventListeners<Self::ViewState> {
|
||||
self.child.listeners()
|
||||
}
|
||||
|
||||
fn on_mouse_down(
|
||||
mut self,
|
||||
button: gpui3::MouseButton,
|
||||
handler: impl Fn(&mut Self::ViewState, &gpui3::MouseDownEvent, &mut ViewContext<Self::ViewState>)
|
||||
+ 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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue