Checkpoint: Thread WindowContext
through to user_settings
This commit is contained in:
parent
b16d37953d
commit
61e09ff532
15 changed files with 71 additions and 64 deletions
|
@ -17,7 +17,7 @@ use log::LevelFilter;
|
||||||
use simplelog::SimpleLogger;
|
use simplelog::SimpleLogger;
|
||||||
use story_selector::ComponentStory;
|
use story_selector::ComponentStory;
|
||||||
use ui::prelude::*;
|
use ui::prelude::*;
|
||||||
use ui::themed;
|
use ui::{themed, FakeSettings};
|
||||||
|
|
||||||
use crate::assets::Assets;
|
use crate::assets::Assets;
|
||||||
use crate::story_selector::StorySelector;
|
use crate::story_selector::StorySelector;
|
||||||
|
@ -68,9 +68,11 @@ fn main() {
|
||||||
move |cx| {
|
move |cx| {
|
||||||
view(
|
view(
|
||||||
cx.entity(|cx| {
|
cx.entity(|cx| {
|
||||||
|
cx.with_global(FakeSettings::default(), |cx| {
|
||||||
cx.with_global(theme.clone(), |cx| {
|
cx.with_global(theme.clone(), |cx| {
|
||||||
StoryWrapper::new(selector.story(cx), theme)
|
StoryWrapper::new(selector.story(cx), theme)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
StoryWrapper::render,
|
StoryWrapper::render,
|
||||||
)
|
)
|
||||||
|
@ -85,14 +87,20 @@ fn main() {
|
||||||
pub struct StoryWrapper {
|
pub struct StoryWrapper {
|
||||||
story: AnyView,
|
story: AnyView,
|
||||||
theme: Theme,
|
theme: Theme,
|
||||||
|
settings: FakeSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StoryWrapper {
|
impl StoryWrapper {
|
||||||
pub(crate) fn new(story: AnyView, theme: Theme) -> Self {
|
pub(crate) fn new(story: AnyView, theme: Theme) -> Self {
|
||||||
Self { story, theme }
|
Self {
|
||||||
|
story,
|
||||||
|
theme,
|
||||||
|
settings: FakeSettings::default(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
|
||||||
|
cx.with_global(self.settings.clone(), |cx| {
|
||||||
themed(self.theme.clone(), cx, |cx| {
|
themed(self.theme.clone(), cx, |cx| {
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
@ -100,6 +108,7 @@ impl StoryWrapper {
|
||||||
.size_full()
|
.size_full()
|
||||||
.child(self.story.clone())
|
.child(self.story.clone())
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl<S: 'static + Send + Sync + Clone> AssistantPanel<S> {
|
||||||
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
fn render(&mut self, view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
|
|
||||||
Panel::new(self.scroll_state.clone())
|
Panel::new(cx)
|
||||||
.children(vec![div()
|
.children(vec![div()
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
|
|
|
@ -138,13 +138,10 @@ mod stories {
|
||||||
Story::container(cx)
|
Story::container(cx)
|
||||||
.child(Story::title_for::<_, ChatPanel<S>>(cx))
|
.child(Story::title_for::<_, ChatPanel<S>>(cx))
|
||||||
.child(Story::label(cx, "Default"))
|
.child(Story::label(cx, "Default"))
|
||||||
.child(
|
.child(Panel::new(cx).child(ChatPanel::new(ScrollState::default())))
|
||||||
Panel::new(ScrollState::default())
|
|
||||||
.child(ChatPanel::new(ScrollState::default())),
|
|
||||||
)
|
|
||||||
.child(Story::label(cx, "With Mesages"))
|
.child(Story::label(cx, "With Mesages"))
|
||||||
.child(Panel::new(ScrollState::default()).child(
|
.child(
|
||||||
ChatPanel::new(ScrollState::default()).messages(vec![
|
Panel::new(cx).child(ChatPanel::new(ScrollState::default()).messages(vec![
|
||||||
ChatMessage::new(
|
ChatMessage::new(
|
||||||
"osiewicz".to_string(),
|
"osiewicz".to_string(),
|
||||||
"is this thing on?".to_string(),
|
"is this thing on?".to_string(),
|
||||||
|
@ -159,8 +156,8 @@ mod stories {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.naive_local(),
|
.naive_local(),
|
||||||
),
|
),
|
||||||
]),
|
])),
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,8 @@ impl<S: 'static + Send + Sync> IconButton<S> {
|
||||||
let mut button = h_stack()
|
let mut button = h_stack()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.rounded_md()
|
.rounded_md()
|
||||||
.py(ui_size(0.25))
|
.py(ui_size(cx, 0.25))
|
||||||
.px(ui_size(6. / 14.))
|
.px(ui_size(cx, 6. / 14.))
|
||||||
.when(self.variant == ButtonVariant::Filled, |this| {
|
.when(self.variant == ButtonVariant::Filled, |this| {
|
||||||
this.bg(color.filled_element)
|
this.bg(color.filled_element)
|
||||||
})
|
})
|
||||||
|
|
|
@ -363,7 +363,7 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
let system_color = SystemColor::new();
|
let system_color = SystemColor::new();
|
||||||
let color = ThemeColor::new(cx);
|
let color = ThemeColor::new(cx);
|
||||||
let setting = user_settings();
|
let settings = user_settings(cx);
|
||||||
|
|
||||||
let left_content = match self.left_content.clone() {
|
let left_content = match self.left_content.clone() {
|
||||||
Some(LeftContent::Icon(i)) => Some(
|
Some(LeftContent::Icon(i)) => Some(
|
||||||
|
@ -395,7 +395,7 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
|
||||||
// .ml(rems(0.75 * self.indent_level as f32))
|
// .ml(rems(0.75 * self.indent_level as f32))
|
||||||
.children((0..self.indent_level).map(|_| {
|
.children((0..self.indent_level).map(|_| {
|
||||||
div()
|
div()
|
||||||
.w(*setting.list_indent_depth)
|
.w(*settings.list_indent_depth)
|
||||||
.h_full()
|
.h_full()
|
||||||
.flex()
|
.flex()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
|
|
|
@ -53,15 +53,15 @@ pub struct Panel<S: 'static + Send + Sync> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync> Panel<S> {
|
impl<S: 'static + Send + Sync> Panel<S> {
|
||||||
pub fn new(scroll_state: ScrollState) -> Self {
|
pub fn new(cx: &mut WindowContext) -> Self {
|
||||||
let setting = user_settings();
|
let settings = user_settings(cx);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
state_type: PhantomData,
|
state_type: PhantomData,
|
||||||
scroll_state,
|
scroll_state: ScrollState::default(),
|
||||||
current_side: PanelSide::default(),
|
current_side: PanelSide::default(),
|
||||||
allowed_sides: PanelAllowedSides::default(),
|
allowed_sides: PanelAllowedSides::default(),
|
||||||
initial_width: *setting.default_panel_size,
|
initial_width: *settings.default_panel_size,
|
||||||
width: None,
|
width: None,
|
||||||
children: SmallVec::new(),
|
children: SmallVec::new(),
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ mod stories {
|
||||||
.child(Story::title_for::<_, Panel<S>>(cx))
|
.child(Story::title_for::<_, Panel<S>>(cx))
|
||||||
.child(Story::label(cx, "Default"))
|
.child(Story::label(cx, "Default"))
|
||||||
.child(
|
.child(
|
||||||
Panel::new(ScrollState::default()).child(
|
Panel::new(cx).child(
|
||||||
div()
|
div()
|
||||||
.overflow_y_scroll(ScrollState::default())
|
.overflow_y_scroll(ScrollState::default())
|
||||||
.children((0..100).map(|ix| Label::new(format!("Item {}", ix + 1)))),
|
.children((0..100).map(|ix| Label::new(format!("Item {}", ix + 1)))),
|
||||||
|
|
|
@ -87,7 +87,7 @@ mod stories {
|
||||||
.child(Story::title_for::<_, ProjectPanel<S>>(cx))
|
.child(Story::title_for::<_, ProjectPanel<S>>(cx))
|
||||||
.child(Story::label(cx, "Default"))
|
.child(Story::label(cx, "Default"))
|
||||||
.child(
|
.child(
|
||||||
Panel::new(ScrollState::default())
|
Panel::new(cx)
|
||||||
.child(ProjectPanel::new(ScrollState::default())),
|
.child(ProjectPanel::new(ScrollState::default())),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl TitleBar {
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
let color = ThemeColor::new(cx);
|
let color = ThemeColor::new(cx);
|
||||||
let setting = user_settings();
|
let settings = user_settings(cx);
|
||||||
|
|
||||||
// let has_focus = cx.window_is_active();
|
// let has_focus = cx.window_is_active();
|
||||||
let has_focus = true;
|
let has_focus = true;
|
||||||
|
@ -127,7 +127,7 @@ impl TitleBar {
|
||||||
.flex()
|
.flex()
|
||||||
.items_center()
|
.items_center()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.when(*setting.titlebar.show_project_owner, |this| {
|
.when(*settings.titlebar.show_project_owner, |this| {
|
||||||
this.child(Button::new("iamnbutler"))
|
this.child(Button::new("iamnbutler"))
|
||||||
})
|
})
|
||||||
.child(Button::new("zed"))
|
.child(Button::new("zed"))
|
||||||
|
|
|
@ -165,7 +165,7 @@ impl Workspace {
|
||||||
.border_color(theme.lowest.base.default.border)
|
.border_color(theme.lowest.base.default.border)
|
||||||
.children(
|
.children(
|
||||||
Some(
|
Some(
|
||||||
Panel::new(self.left_panel_scroll_state.clone())
|
Panel::new(cx)
|
||||||
.side(PanelSide::Left)
|
.side(PanelSide::Left)
|
||||||
.child(ProjectPanel::new(ScrollState::default())),
|
.child(ProjectPanel::new(ScrollState::default())),
|
||||||
)
|
)
|
||||||
|
@ -173,7 +173,7 @@ impl Workspace {
|
||||||
)
|
)
|
||||||
.children(
|
.children(
|
||||||
Some(
|
Some(
|
||||||
Panel::new(self.left_panel_scroll_state.clone())
|
Panel::new(cx)
|
||||||
.child(CollabPanel::new(ScrollState::default()))
|
.child(CollabPanel::new(ScrollState::default()))
|
||||||
.side(PanelSide::Left),
|
.side(PanelSide::Left),
|
||||||
)
|
)
|
||||||
|
@ -196,7 +196,7 @@ impl Workspace {
|
||||||
)
|
)
|
||||||
.children(
|
.children(
|
||||||
Some(
|
Some(
|
||||||
Panel::new(self.bottom_panel_scroll_state.clone())
|
Panel::new(cx)
|
||||||
.child(Terminal::new())
|
.child(Terminal::new())
|
||||||
.allowed_sides(PanelAllowedSides::BottomOnly)
|
.allowed_sides(PanelAllowedSides::BottomOnly)
|
||||||
.side(PanelSide::Bottom),
|
.side(PanelSide::Bottom),
|
||||||
|
@ -205,10 +205,8 @@ impl Workspace {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.children(
|
.children(
|
||||||
Some(
|
Some(Panel::new(cx).side(PanelSide::Right).child(
|
||||||
Panel::new(self.right_panel_scroll_state.clone())
|
ChatPanel::new(ScrollState::default()).messages(vec![
|
||||||
.side(PanelSide::Right)
|
|
||||||
.child(ChatPanel::new(ScrollState::default()).messages(vec![
|
|
||||||
ChatMessage::new(
|
ChatMessage::new(
|
||||||
"osiewicz".to_string(),
|
"osiewicz".to_string(),
|
||||||
"is this thing on?".to_string(),
|
"is this thing on?".to_string(),
|
||||||
|
@ -223,23 +221,20 @@ impl Workspace {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.naive_local(),
|
.naive_local(),
|
||||||
),
|
),
|
||||||
])),
|
]),
|
||||||
)
|
))
|
||||||
.filter(|_| self.is_chat_panel_open()),
|
.filter(|_| self.is_chat_panel_open()),
|
||||||
)
|
)
|
||||||
.children(
|
.children(
|
||||||
Some(
|
Some(
|
||||||
Panel::new(self.right_panel_scroll_state.clone())
|
Panel::new(cx)
|
||||||
.side(PanelSide::Right)
|
.side(PanelSide::Right)
|
||||||
.child(div().w_96().h_full().child("Notifications")),
|
.child(div().w_96().h_full().child("Notifications")),
|
||||||
)
|
)
|
||||||
.filter(|_| self.is_notifications_panel_open()),
|
.filter(|_| self.is_notifications_panel_open()),
|
||||||
)
|
)
|
||||||
.children(
|
.children(
|
||||||
Some(
|
Some(Panel::new(cx).child(AssistantPanel::new()))
|
||||||
Panel::new(self.right_panel_scroll_state.clone())
|
|
||||||
.child(AssistantPanel::new()),
|
|
||||||
)
|
|
||||||
.filter(|_| self.is_assistant_panel_open()),
|
.filter(|_| self.is_assistant_panel_open()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -149,11 +149,11 @@ impl<S: 'static + Send + Sync + Clone> Button<S> {
|
||||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
||||||
let icon_color = self.icon_color();
|
let icon_color = self.icon_color();
|
||||||
let border_color = self.border_color(cx);
|
let border_color = self.border_color(cx);
|
||||||
let setting = user_settings();
|
let settings = user_settings(cx);
|
||||||
|
|
||||||
let mut el = h_stack()
|
let mut el = h_stack()
|
||||||
.p_1()
|
.p_1()
|
||||||
.text_size(ui_size(1.))
|
.text_size(ui_size(cx, 1.))
|
||||||
.rounded_md()
|
.rounded_md()
|
||||||
.border()
|
.border()
|
||||||
.border_color(border_color)
|
.border_color(border_color)
|
||||||
|
|
|
@ -180,8 +180,8 @@ impl<S: 'static + Send + Sync> IconElement<S> {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
let fill = self.color.color(theme);
|
let fill = self.color.color(theme);
|
||||||
let svg_size = match self.size {
|
let svg_size = match self.size {
|
||||||
IconSize::Small => ui_size(12. / 14.),
|
IconSize::Small => ui_size(cx, 12. / 14.),
|
||||||
IconSize::Medium => ui_size(15. / 14.),
|
IconSize::Medium => ui_size(cx, 15. / 14.),
|
||||||
};
|
};
|
||||||
|
|
||||||
svg()
|
svg()
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
|
||||||
.bg(LabelColor::Hidden.hsla(cx)),
|
.bg(LabelColor::Hidden.hsla(cx)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.text_size(ui_size(1.))
|
.text_size(ui_size(cx, 1.))
|
||||||
.when(self.line_height_style == LineHeightStyle::UILabel, |this| {
|
.when(self.line_height_style == LineHeightStyle::UILabel, |this| {
|
||||||
this.line_height(relative(1.))
|
this.line_height(relative(1.))
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,6 +14,14 @@ pub use elements::*;
|
||||||
pub use prelude::*;
|
pub use prelude::*;
|
||||||
pub use static_data::*;
|
pub use static_data::*;
|
||||||
|
|
||||||
|
// This needs to be fully qualified with `crate::` otherwise we get a panic
|
||||||
|
// at:
|
||||||
|
// thread '<unnamed>' panicked at crates/gpui3/src/platform/mac/platform.rs:66:81:
|
||||||
|
// called `Option::unwrap()` on a `None` value
|
||||||
|
//
|
||||||
|
// AFAICT this is something to do with conflicting names between crates and modules that
|
||||||
|
// interfaces with declaring the `ClassDecl`.
|
||||||
|
pub use crate::settings::*;
|
||||||
pub use crate::theme::*;
|
pub use crate::theme::*;
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
#[cfg(feature = "stories")]
|
||||||
|
|
|
@ -142,12 +142,12 @@ impl HighlightColor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ui_size(size: f32) -> Rems {
|
pub fn ui_size(cx: &mut WindowContext, size: f32) -> Rems {
|
||||||
const UI_SCALE_RATIO: f32 = 0.875;
|
const UI_SCALE_RATIO: f32 = 0.875;
|
||||||
|
|
||||||
let setting = user_settings();
|
let settings = user_settings(cx);
|
||||||
|
|
||||||
rems(*setting.ui_scale * UI_SCALE_RATIO * size)
|
rems(*settings.ui_scale * UI_SCALE_RATIO * size)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use gpui3::{rems, AbsoluteLength};
|
use gpui3::{rems, AbsoluteLength, WindowContext};
|
||||||
|
|
||||||
use crate::DisclosureControlStyle;
|
use crate::DisclosureControlStyle;
|
||||||
|
|
||||||
// This is a fake static example of user settings overriding the default settings
|
/// Returns the user settings.
|
||||||
pub fn user_settings() -> Settings {
|
pub fn user_settings(cx: &WindowContext) -> FakeSettings {
|
||||||
let mut settings = Settings::default();
|
// cx.global::<FakeSettings>().clone()
|
||||||
settings.list_indent_depth = SettingValue::UserDefined(rems(0.5).into());
|
FakeSettings::default()
|
||||||
// settings.ui_scale = SettingValue::UserDefined(2.);
|
|
||||||
settings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -48,7 +46,7 @@ impl Default for TitlebarSettings {
|
||||||
|
|
||||||
// These should be merged into settings
|
// These should be merged into settings
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Settings {
|
pub struct FakeSettings {
|
||||||
pub default_panel_size: SettingValue<AbsoluteLength>,
|
pub default_panel_size: SettingValue<AbsoluteLength>,
|
||||||
pub list_disclosure_style: SettingValue<DisclosureControlStyle>,
|
pub list_disclosure_style: SettingValue<DisclosureControlStyle>,
|
||||||
pub list_indent_depth: SettingValue<AbsoluteLength>,
|
pub list_indent_depth: SettingValue<AbsoluteLength>,
|
||||||
|
@ -56,7 +54,7 @@ pub struct Settings {
|
||||||
pub ui_scale: SettingValue<f32>,
|
pub ui_scale: SettingValue<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for FakeSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
titlebar: TitlebarSettings::default(),
|
titlebar: TitlebarSettings::default(),
|
||||||
|
@ -68,4 +66,4 @@ impl Default for Settings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {}
|
impl FakeSettings {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue