Checkpoint: Thread WindowContext through to user_settings

This commit is contained in:
Marshall Bowers 2023-10-19 12:58:17 -04:00
parent b16d37953d
commit 61e09ff532
15 changed files with 71 additions and 64 deletions

View file

@ -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> {
let theme = theme(cx);
Panel::new(self.scroll_state.clone())
Panel::new(cx)
.children(vec![div()
.flex()
.flex_col()

View file

@ -138,13 +138,10 @@ mod stories {
Story::container(cx)
.child(Story::title_for::<_, ChatPanel<S>>(cx))
.child(Story::label(cx, "Default"))
.child(
Panel::new(ScrollState::default())
.child(ChatPanel::new(ScrollState::default())),
)
.child(Panel::new(cx).child(ChatPanel::new(ScrollState::default())))
.child(Story::label(cx, "With Mesages"))
.child(Panel::new(ScrollState::default()).child(
ChatPanel::new(ScrollState::default()).messages(vec![
.child(
Panel::new(cx).child(ChatPanel::new(ScrollState::default()).messages(vec![
ChatMessage::new(
"osiewicz".to_string(),
"is this thing on?".to_string(),
@ -159,8 +156,8 @@ mod stories {
.unwrap()
.naive_local(),
),
]),
))
])),
)
}
}
}

View file

@ -78,8 +78,8 @@ impl<S: 'static + Send + Sync> IconButton<S> {
let mut button = h_stack()
.justify_center()
.rounded_md()
.py(ui_size(0.25))
.px(ui_size(6. / 14.))
.py(ui_size(cx, 0.25))
.px(ui_size(cx, 6. / 14.))
.when(self.variant == ButtonVariant::Filled, |this| {
this.bg(color.filled_element)
})

View file

@ -363,7 +363,7 @@ impl<S: 'static + Send + Sync + Clone> ListEntry<S> {
let theme = theme(cx);
let system_color = SystemColor::new();
let color = ThemeColor::new(cx);
let setting = user_settings();
let settings = user_settings(cx);
let left_content = match self.left_content.clone() {
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))
.children((0..self.indent_level).map(|_| {
div()
.w(*setting.list_indent_depth)
.w(*settings.list_indent_depth)
.h_full()
.flex()
.justify_center()

View file

@ -53,15 +53,15 @@ pub struct Panel<S: 'static + Send + Sync> {
}
impl<S: 'static + Send + Sync> Panel<S> {
pub fn new(scroll_state: ScrollState) -> Self {
let setting = user_settings();
pub fn new(cx: &mut WindowContext) -> Self {
let settings = user_settings(cx);
Self {
state_type: PhantomData,
scroll_state,
scroll_state: ScrollState::default(),
current_side: PanelSide::default(),
allowed_sides: PanelAllowedSides::default(),
initial_width: *setting.default_panel_size,
initial_width: *settings.default_panel_size,
width: None,
children: SmallVec::new(),
}
@ -175,7 +175,7 @@ mod stories {
.child(Story::title_for::<_, Panel<S>>(cx))
.child(Story::label(cx, "Default"))
.child(
Panel::new(ScrollState::default()).child(
Panel::new(cx).child(
div()
.overflow_y_scroll(ScrollState::default())
.children((0..100).map(|ix| Label::new(format!("Item {}", ix + 1)))),

View file

@ -87,7 +87,7 @@ mod stories {
.child(Story::title_for::<_, ProjectPanel<S>>(cx))
.child(Story::label(cx, "Default"))
.child(
Panel::new(ScrollState::default())
Panel::new(cx)
.child(ProjectPanel::new(ScrollState::default())),
)
}

View file

@ -95,7 +95,7 @@ impl TitleBar {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
let theme = theme(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 = true;
@ -127,7 +127,7 @@ impl TitleBar {
.flex()
.items_center()
.gap_1()
.when(*setting.titlebar.show_project_owner, |this| {
.when(*settings.titlebar.show_project_owner, |this| {
this.child(Button::new("iamnbutler"))
})
.child(Button::new("zed"))

View file

@ -165,7 +165,7 @@ impl Workspace {
.border_color(theme.lowest.base.default.border)
.children(
Some(
Panel::new(self.left_panel_scroll_state.clone())
Panel::new(cx)
.side(PanelSide::Left)
.child(ProjectPanel::new(ScrollState::default())),
)
@ -173,7 +173,7 @@ impl Workspace {
)
.children(
Some(
Panel::new(self.left_panel_scroll_state.clone())
Panel::new(cx)
.child(CollabPanel::new(ScrollState::default()))
.side(PanelSide::Left),
)
@ -196,7 +196,7 @@ impl Workspace {
)
.children(
Some(
Panel::new(self.bottom_panel_scroll_state.clone())
Panel::new(cx)
.child(Terminal::new())
.allowed_sides(PanelAllowedSides::BottomOnly)
.side(PanelSide::Bottom),
@ -205,10 +205,8 @@ impl Workspace {
),
)
.children(
Some(
Panel::new(self.right_panel_scroll_state.clone())
.side(PanelSide::Right)
.child(ChatPanel::new(ScrollState::default()).messages(vec![
Some(Panel::new(cx).side(PanelSide::Right).child(
ChatPanel::new(ScrollState::default()).messages(vec![
ChatMessage::new(
"osiewicz".to_string(),
"is this thing on?".to_string(),
@ -223,24 +221,21 @@ impl Workspace {
.unwrap()
.naive_local(),
),
])),
)
]),
))
.filter(|_| self.is_chat_panel_open()),
)
.children(
Some(
Panel::new(self.right_panel_scroll_state.clone())
Panel::new(cx)
.side(PanelSide::Right)
.child(div().w_96().h_full().child("Notifications")),
)
.filter(|_| self.is_notifications_panel_open()),
)
.children(
Some(
Panel::new(self.right_panel_scroll_state.clone())
.child(AssistantPanel::new()),
)
.filter(|_| self.is_assistant_panel_open()),
Some(Panel::new(cx).child(AssistantPanel::new()))
.filter(|_| self.is_assistant_panel_open()),
),
)
.child(StatusBar::new())