WIP
This commit is contained in:
parent
a8bb3dd9a3
commit
6d2b27689d
6 changed files with 34 additions and 42 deletions
|
@ -4,3 +4,6 @@ mod svg;
|
||||||
mod text;
|
mod text;
|
||||||
|
|
||||||
pub use div::*;
|
pub use div::*;
|
||||||
|
pub use img::*;
|
||||||
|
pub use svg::*;
|
||||||
|
pub use text::*;
|
||||||
|
|
|
@ -1123,7 +1123,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_platform() -> MacPlatform {
|
fn build_platform() -> MacPlatform {
|
||||||
let mut platform = MacPlatform::new();
|
let platform = MacPlatform::new();
|
||||||
platform.0.borrow_mut().pasteboard = unsafe { NSPasteboard::pasteboardWithUniqueName(nil) };
|
platform.0.borrow_mut().pasteboard = unsafe { NSPasteboard::pasteboardWithUniqueName(nil) };
|
||||||
platform
|
platform
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
use crate::theme::{theme, Theme};
|
use crate::theme::{theme, Theme};
|
||||||
use gpui2::{
|
use gpui3::{
|
||||||
elements::{div, div::ScrollState, img, svg},
|
div, img, svg, ArcCow, Element, IntoAnyElement, ParentElement, ScrollState, Styled, ViewContext,
|
||||||
style::{StyleHelpers, Styleable},
|
|
||||||
ArcCow, Element, IntoElement, ParentElement, ViewContext,
|
|
||||||
};
|
};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
#[derive(Element)]
|
|
||||||
pub struct CollabPanelElement<V: 'static> {
|
pub struct CollabPanelElement<V: 'static> {
|
||||||
view_type: PhantomData<V>,
|
view_type: PhantomData<V>,
|
||||||
scroll_state: ScrollState,
|
scroll_state: ScrollState,
|
||||||
|
@ -22,7 +19,7 @@ pub fn collab_panel<V: 'static>(scroll_state: ScrollState) -> CollabPanelElement
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: 'static> CollabPanelElement<V> {
|
impl<V: 'static> CollabPanelElement<V> {
|
||||||
fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
|
|
||||||
// Panel
|
// Panel
|
||||||
|
@ -117,10 +114,10 @@ impl<V: 'static> CollabPanelElement<V> {
|
||||||
|
|
||||||
fn list_section_header(
|
fn list_section_header(
|
||||||
&self,
|
&self,
|
||||||
label: impl IntoElement<V>,
|
label: impl IntoAnyElement<V>,
|
||||||
expanded: bool,
|
expanded: bool,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
) -> impl Element<V> {
|
) -> impl Element {
|
||||||
div()
|
div()
|
||||||
.h_7()
|
.h_7()
|
||||||
.px_2()
|
.px_2()
|
||||||
|
@ -146,9 +143,9 @@ impl<V: 'static> CollabPanelElement<V> {
|
||||||
fn list_item(
|
fn list_item(
|
||||||
&self,
|
&self,
|
||||||
avatar_uri: impl Into<ArcCow<'static, str>>,
|
avatar_uri: impl Into<ArcCow<'static, str>>,
|
||||||
label: impl IntoElement<V>,
|
label: impl IntoAnyElement<V>,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
) -> impl Element<V> {
|
) -> impl Element {
|
||||||
div()
|
div()
|
||||||
.h_7()
|
.h_7()
|
||||||
.px_2()
|
.px_2()
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
use crate::theme::{Theme, Themed};
|
use crate::theme::{Theme, Themed};
|
||||||
use gpui3::Element;
|
use gpui3::Element;
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
pub trait ElementExt: Element {
|
pub trait ElementExt: Element {
|
||||||
fn themed(self, theme: Theme) -> Themed<V, Self>
|
fn themed(self, theme: Theme) -> Themed<Self>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: 'static, E: Element> ElementExt for E {
|
impl<E: Element> ElementExt for E {
|
||||||
fn themed(self, theme: Theme) -> Themed<V, Self>
|
fn themed(self, theme: Theme) -> Themed<Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
Themed {
|
Themed { child: self, theme }
|
||||||
child: self,
|
|
||||||
theme,
|
|
||||||
view_type: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use gpui3::{
|
use gpui3::{
|
||||||
serde_json, AppContext, Element, Hsla, IntoAnyElement, Layout, Vector2F, ViewContext,
|
serde_json, AppContext, Element, Hsla, IntoAnyElement, Layout, LayoutId, Vector2F, ViewContext,
|
||||||
WindowContext,
|
WindowContext,
|
||||||
};
|
};
|
||||||
use serde::{de::Visitor, Deserialize, Deserializer};
|
use serde::{de::Visitor, Deserialize, Deserializer};
|
||||||
|
@ -131,25 +131,24 @@ where
|
||||||
deserializer.deserialize_map(SyntaxVisitor)
|
deserializer.deserialize_map(SyntaxVisitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Themed<V: 'static, E: Element<V>> {
|
pub struct Themed<E> {
|
||||||
pub(crate) theme: Theme,
|
pub(crate) theme: Theme,
|
||||||
pub(crate) child: E,
|
pub(crate) child: E,
|
||||||
pub(crate) view_type: PhantomData<V>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: 'static, E: Element<V>> Element<V> for Themed<V, E> {
|
impl<E: Element> Element for Themed<E> {
|
||||||
type FrameState = E::FrameState;
|
type FrameState = E::FrameState;
|
||||||
|
|
||||||
fn layout(
|
fn layout(
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
state: &mut E::State,
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<E::State>,
|
||||||
) -> anyhow::Result<(gpui2::LayoutId, Self::FrameState)>
|
) -> anyhow::Result<(LayoutId, Self::FrameState)>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
cx.push_theme(self.theme.clone());
|
cx.push_theme(self.theme.clone());
|
||||||
let result = self.child.layout(view, cx);
|
let result = self.child.layout(state, cx);
|
||||||
cx.pop_theme();
|
cx.pop_theme();
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
use crate::{collab_panel::collab_panel, theme::theme};
|
use crate::{collab_panel::collab_panel, theme::theme};
|
||||||
use gpui3::{div, Element, IntoAnyElement, ParentElement, ScrollState, Styled, ViewContext};
|
use gpui3::{div, img, svg, Element, ParentElement, ScrollState, Styled, ViewContext};
|
||||||
|
|
||||||
#[derive(Element, Default)]
|
#[derive(Default)]
|
||||||
struct WorkspaceElement {
|
struct WorkspaceElement {
|
||||||
left_scroll_state: ScrollState,
|
left_scroll_state: ScrollState,
|
||||||
right_scroll_state: ScrollState,
|
right_scroll_state: ScrollState,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn workspace<V: 'static>() -> impl Element<V> {
|
pub fn workspace<V: 'static>() -> impl Element {
|
||||||
WorkspaceElement::default()
|
WorkspaceElement::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkspaceElement {
|
impl WorkspaceElement {
|
||||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
|
|
||||||
div()
|
div()
|
||||||
|
@ -41,15 +41,14 @@ impl WorkspaceElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Element)]
|
|
||||||
struct TitleBar;
|
struct TitleBar;
|
||||||
|
|
||||||
pub fn titlebar<V: 'static>() -> impl Element<V> {
|
pub fn titlebar<V: 'static>() -> impl Element {
|
||||||
TitleBar
|
TitleBar
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TitleBar {
|
impl TitleBar {
|
||||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
@ -62,7 +61,7 @@ impl TitleBar {
|
||||||
.child(self.right_group(cx))
|
.child(self.right_group(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
@ -136,7 +135,7 @@ impl TitleBar {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
@ -264,15 +263,14 @@ impl TitleBar {
|
||||||
|
|
||||||
// ================================================================================ //
|
// ================================================================================ //
|
||||||
|
|
||||||
#[derive(Element)]
|
|
||||||
struct StatusBar;
|
struct StatusBar;
|
||||||
|
|
||||||
pub fn statusbar<V: 'static>() -> impl Element<V> {
|
pub fn statusbar<V: 'static>() -> impl Element {
|
||||||
StatusBar
|
StatusBar
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StatusBar {
|
impl StatusBar {
|
||||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
@ -285,7 +283,7 @@ impl StatusBar {
|
||||||
.child(self.right_group(cx))
|
.child(self.right_group(cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
@ -382,7 +380,7 @@ impl StatusBar {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||||
let theme = theme(cx);
|
let theme = theme(cx);
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue