Checkpoint

This commit is contained in:
Nathan Sobo 2023-09-21 14:10:53 -06:00
parent a0416e9c6d
commit d120d0cf2e
5 changed files with 51 additions and 35 deletions

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
current_platform, Context, LayoutId, Platform, Reference, TextSystem, View, Window, current_platform, Context, LayoutId, Platform, Reference, RootView, TextSystem, Window,
WindowContext, WindowHandle, WindowId, WindowContext, WindowHandle, WindowId,
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
@ -68,7 +68,7 @@ impl AppContext {
pub fn open_window<S: 'static>( pub fn open_window<S: 'static>(
&mut self, &mut self,
options: crate::WindowOptions, options: crate::WindowOptions,
build_root_view: impl FnOnce(&mut WindowContext) -> View<S>, build_root_view: impl FnOnce(&mut WindowContext) -> RootView<S>,
) -> WindowHandle<S> { ) -> WindowHandle<S> {
let id = self.windows.insert(None); let id = self.windows.insert(None);
let handle = WindowHandle::new(id); let handle = WindowHandle::new(id);

View file

@ -1,4 +1,4 @@
use super::{Handle, Layout, LayoutId, Pixels, Point, Result, ViewContext, WindowContext}; use super::{Handle, Layout, LayoutId, Pixels, Point, Result, ViewContext};
pub(crate) use smallvec::SmallVec; pub(crate) use smallvec::SmallVec;
use std::{any::Any, cell::RefCell, marker::PhantomData, rc::Rc}; use std::{any::Any, cell::RefCell, marker::PhantomData, rc::Rc};

View file

@ -4,11 +4,11 @@ use gpui3::{
ScrollState, StyleHelpers, View, ViewContext, WindowContext, ScrollState, StyleHelpers, View, ViewContext, WindowContext,
}; };
struct CollabPanel { pub struct CollabPanel {
scroll_state: ScrollState, scroll_state: ScrollState,
} }
pub fn collab_panel(cx: &mut WindowContext) -> View<CollabPanel> { pub fn collab_panel<S: 'static>(cx: &mut WindowContext) -> View<CollabPanel, S> {
view(cx.entity(|cx| CollabPanel::new(cx)), |panel, cx| { view(cx.entity(|cx| CollabPanel::new(cx)), |panel, cx| {
panel.render(cx) panel.render(cx)
}) })

View file

@ -52,7 +52,7 @@ fn main() {
} }
fn storybook<V: 'static>(cx: &mut ViewContext<V>) -> impl Element { fn storybook<V: 'static>(cx: &mut ViewContext<V>) -> impl Element {
workspace().themed(current_theme(cx)) workspace(cx).themed(current_theme(cx))
} }
// Nathan: During the transition to gpui2, we will include the base theme on the legacy Theme struct. // Nathan: During the transition to gpui2, we will include the base theme on the legacy Theme struct.

View file

@ -1,25 +1,35 @@
use crate::{collab_panel::collab_panel, theme::theme}; use crate::{
collab_panel::{collab_panel, CollabPanel},
theme::theme,
};
use gpui3::{ use gpui3::{
div, img, svg, view, Element, ParentElement, ScrollState, StyleHelpers, View, ViewContext, div, img, svg, view, Context, Element, ParentElement, RootView, StyleHelpers, View,
WindowAppearance, WindowContext, ViewContext, WindowContext,
}; };
#[derive(Default)] pub struct Workspace {
struct Workspace { left_panel: View<CollabPanel, Self>,
left_scroll_state: ScrollState, right_panel: View<CollabPanel, Self>,
right_scroll_state: ScrollState,
} }
pub fn workspace(cx: &mut WindowContext) -> View<Workspace> { pub fn workspace(cx: &mut WindowContext) -> RootView<Workspace> {
let workspace = cx.entity(|_| Workspace::default()); view(cx.entity(|cx| Workspace::new(cx)), |workspace, cx| {
view(workspace, |workspace, cx| workspace.render(cx)) workspace.render(cx)
})
} }
impl Workspace { impl Workspace {
fn render<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> { fn new(cx: &mut ViewContext<Self>) -> Self {
Self {
left_panel: collab_panel(cx),
right_panel: collab_panel(cx),
}
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
let theme = theme(cx); let theme = theme(cx);
div() div::<Self>()
.size_full() .size_full()
.flex() .flex()
.flex_col() .flex_col()
@ -29,34 +39,40 @@ impl Workspace {
.items_start() .items_start()
.text_color(theme.lowest.base.default.foreground) .text_color(theme.lowest.base.default.foreground)
.fill(theme.middle.base.default.background) .fill(theme.middle.base.default.background)
.child(titlebar()) .child(titlebar(cx))
.child( .child(
div() div::<Self>()
.flex_1() .flex_1()
.w_full() .w_full()
.flex() .flex()
.flex_row() .flex_row()
.overflow_hidden() .overflow_hidden()
.child(collab_panel(self.left_scroll_state.clone())) .child(self.left_panel.clone())
.child(div().h_full().flex_1()) .child(div().h_full().flex_1())
.child(collab_panel(self.right_scroll_state.clone())), .child(self.right_panel.clone()),
) )
.child(statusbar()) .child(statusbar::statusbar(cx))
} }
} }
struct TitleBar; struct Titlebar;
pub fn titlebar<V: 'static>() -> impl Element<State = V> { pub fn titlebar<S: 'static>(cx: &mut ViewContext<S>) -> impl Element<State = S> {
TitleBar let ref mut this = Titlebar;
let theme = theme(cx);
div()
.flex()
.items_center()
.justify_between()
.w_full()
.h_8()
.fill(theme.lowest.base.default.background)
.child(this.left_group(cx))
.child(this.right_group(cx))
} }
impl TitleBar { impl Titlebar {
fn render<V: 'static>( fn render<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> {
&mut self,
_: &mut V,
cx: &mut ViewContext<V>,
) -> impl Element<State = V> {
let theme = theme(cx); let theme = theme(cx);
div() div()
.flex() .flex()
@ -276,7 +292,7 @@ mod statusbar {
use super::*; use super::*;
pub fn statusbar<V: 'static>(_: &mut V, cx: &mut ViewContext<V>) -> impl Element<State = V> { pub fn statusbar<S: 'static>(cx: &mut ViewContext<S>) -> impl Element<State = S> {
let theme = theme(cx); let theme = theme(cx);
div() div()
.flex() .flex()
@ -285,8 +301,8 @@ mod statusbar {
.w_full() .w_full()
.h_8() .h_8()
.fill(theme.lowest.base.default.background) .fill(theme.lowest.base.default.background)
.child(left_group(cx)) // .child(left_group(cx))
.child(right_group(cx)) // .child(right_group(cx))
} }
fn left_group<V: 'static>(cx: &mut ViewContext<V>) -> impl Element<State = V> { fn left_group<V: 'static>(cx: &mut ViewContext<V>) -> impl Element<State = V> {