1// use std::ops::Deref;
2// use std::sync::Arc;
3
4// use gpui3::{
5// rems, AbsoluteLength, AnyElement, BorrowAppContext, Bounds, LayoutId, Pixels, WindowContext,
6// };
7
8// use crate::prelude::*;
9
10// /// Returns the user settings.
11// pub fn user_settings(cx: &WindowContext) -> FakeSettings {
12// cx.global::<FakeSettings>().clone()
13// }
14
15// pub fn user_settings_mut<'cx>(cx: &'cx mut WindowContext) -> &'cx mut FakeSettings {
16// cx.global_mut::<FakeSettings>()
17// }
18
19// #[derive(Clone)]
20// pub enum SettingValue<T> {
21// UserDefined(T),
22// Default(T),
23// }
24
25// impl<T> Deref for SettingValue<T> {
26// type Target = T;
27
28// fn deref(&self) -> &Self::Target {
29// match self {
30// Self::UserDefined(value) => value,
31// Self::Default(value) => value,
32// }
33// }
34// }
35
36// #[derive(Clone)]
37// pub struct TitlebarSettings {
38// pub show_project_owner: SettingValue<bool>,
39// pub show_git_status: SettingValue<bool>,
40// pub show_git_controls: SettingValue<bool>,
41// }
42
43// impl Default for TitlebarSettings {
44// fn default() -> Self {
45// Self {
46// show_project_owner: SettingValue::Default(true),
47// show_git_status: SettingValue::Default(true),
48// show_git_controls: SettingValue::Default(true),
49// }
50// }
51// }
52
53// // These should be merged into settings
54// #[derive(Clone)]
55// pub struct FakeSettings {
56// pub default_panel_size: SettingValue<AbsoluteLength>,
57// pub list_disclosure_style: SettingValue<DisclosureControlStyle>,
58// pub list_indent_depth: SettingValue<AbsoluteLength>,
59// pub titlebar: TitlebarSettings,
60// pub ui_scale: SettingValue<f32>,
61// }
62
63// impl Default for FakeSettings {
64// fn default() -> Self {
65// Self {
66// titlebar: TitlebarSettings::default(),
67// list_disclosure_style: SettingValue::Default(DisclosureControlStyle::ChevronOnHover),
68// list_indent_depth: SettingValue::Default(rems(0.3).into()),
69// default_panel_size: SettingValue::Default(rems(16.).into()),
70// ui_scale: SettingValue::Default(1.),
71// }
72// }
73// }
74
75// impl FakeSettings {}
76
77// pub fn with_settings<E, F>(
78// settings: FakeSettings,
79// cx: &mut ViewContext<E::ViewState>,
80// build_child: F,
81// ) -> WithSettings<E>
82// where
83// E: Element,
84// F: FnOnce(&mut ViewContext<E::ViewState>) -> E,
85// {
86// let child = cx.with_global(settings.clone(), |cx| build_child(cx));
87// WithSettings { settings, child }
88// }
89
90// pub struct WithSettings<E> {
91// pub(crate) settings: FakeSettings,
92// pub(crate) child: E,
93// }
94
95// impl<E> IntoAnyElement<E::ViewState> for WithSettings<E>
96// where
97// E: Element,
98// {
99// fn into_any(self) -> AnyElement<E::ViewState> {
100// AnyElement::new(self)
101// }
102// }
103
104// impl<E: Element> Element for WithSettings<E> {
105// type ViewState = E::ViewState;
106// type ElementState = E::ElementState;
107
108// fn id(&self) -> Option<gpui3::ElementId> {
109// None
110// }
111
112// fn initialize(
113// &mut self,
114// view_state: &mut Self::ViewState,
115// element_state: Option<Self::ElementState>,
116// cx: &mut ViewContext<Self::ViewState>,
117// ) -> Self::ElementState {
118// cx.with_global(self.settings.clone(), |cx| {
119// self.child.initialize(view_state, element_state, cx)
120// })
121// }
122
123// fn layout(
124// &mut self,
125// view_state: &mut E::ViewState,
126// element_state: &mut Self::ElementState,
127// cx: &mut ViewContext<E::ViewState>,
128// ) -> LayoutId
129// where
130// Self: Sized,
131// {
132// cx.with_global(self.settings.clone(), |cx| {
133// self.child.layout(view_state, element_state, cx)
134// })
135// }
136
137// fn paint(
138// &mut self,
139// bounds: Bounds<Pixels>,
140// view_state: &mut Self::ViewState,
141// frame_state: &mut Self::ElementState,
142// cx: &mut ViewContext<Self::ViewState>,
143// ) where
144// Self: Sized,
145// {
146// cx.with_global(self.settings.clone(), |cx| {
147// self.child.paint(bounds, view_state, frame_state, cx);
148// });
149// }
150// }
151
152// impl<E: Element + Interactive> Interactive for WithSettings<E> {
153// fn listeners(&mut self) -> &mut gpui3::EventListeners<Self::ViewState> {
154// self.child.listeners()
155// }
156
157// fn on_mouse_down(
158// mut self,
159// button: gpui3::MouseButton,
160// handler: impl Fn(&mut Self::ViewState, &gpui3::MouseDownEvent, &mut ViewContext<Self::ViewState>)
161// + Send
162// + Sync
163// + 'static,
164// ) -> Self
165// where
166// Self: Sized,
167// {
168// println!("WithSettings on_mouse_down");
169
170// let settings = self.settings.clone();
171
172// self.listeners()
173// .mouse_down
174// .push(Arc::new(move |view, event, bounds, phase, cx| {
175// cx.with_global(settings.clone(), |cx| handler(view, event, cx))
176// }));
177// self
178// }
179// }