WIP - Next: implement Element derive macro
This commit is contained in:
parent
6d2b27689d
commit
dfeb702544
21 changed files with 980 additions and 119 deletions
|
@ -1,6 +1,7 @@
|
|||
use crate::theme::{theme, Theme};
|
||||
use gpui3::{
|
||||
div, img, svg, ArcCow, Element, IntoAnyElement, ParentElement, ScrollState, Styled, ViewContext,
|
||||
div, img, svg, ArcCow, Element, IntoAnyElement, ParentElement, ScrollState, StyleHelpers,
|
||||
ViewContext,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
|
@ -117,7 +118,7 @@ impl<V: 'static> CollabPanelElement<V> {
|
|||
label: impl IntoAnyElement<V>,
|
||||
expanded: bool,
|
||||
theme: &Theme,
|
||||
) -> impl Element {
|
||||
) -> impl Element<State = V> {
|
||||
div()
|
||||
.h_7()
|
||||
.px_2()
|
||||
|
@ -145,16 +146,16 @@ impl<V: 'static> CollabPanelElement<V> {
|
|||
avatar_uri: impl Into<ArcCow<'static, str>>,
|
||||
label: impl IntoAnyElement<V>,
|
||||
theme: &Theme,
|
||||
) -> impl Element {
|
||||
) -> impl Element<State = V> {
|
||||
div()
|
||||
.h_7()
|
||||
.px_2()
|
||||
.flex()
|
||||
.items_center()
|
||||
.hover()
|
||||
.fill(theme.lowest.variant.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.variant.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.variant.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.variant.pressed.background)
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
use crate::theme::Theme;
|
||||
use ::theme as legacy_theme;
|
||||
use element_ext::ElementExt;
|
||||
use gpui3::{Element, ViewContext};
|
||||
use legacy_theme::ThemeSettings;
|
||||
|
||||
use log::LevelFilter;
|
||||
use simplelog::SimpleLogger;
|
||||
|
||||
|
@ -22,7 +21,9 @@ mod workspace;
|
|||
fn main() {
|
||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||
|
||||
gpui3::App::new().run(|cx| cx.open_window(Default::default(), |cx| todo!()));
|
||||
gpui3::App::new().run(|cx| {
|
||||
let window: gpui3::WindowHandle<()> = cx.open_window(Default::default(), |cx| todo!());
|
||||
});
|
||||
|
||||
// gpui3::App::new(Assets).unwrap().run(|cx| {
|
||||
// let mut store = SettingsStore::default();
|
||||
|
@ -56,19 +57,20 @@ fn storybook<V: 'static>(cx: &mut ViewContext<V>) -> impl Element {
|
|||
|
||||
// Nathan: During the transition to gpui2, we will include the base theme on the legacy Theme struct.
|
||||
fn current_theme<V: 'static>(cx: &mut ViewContext<V>) -> Theme {
|
||||
settings::get::<ThemeSettings>(cx)
|
||||
.theme
|
||||
.deserialized_base_theme
|
||||
.lock()
|
||||
.get_or_insert_with(|| {
|
||||
let theme: Theme =
|
||||
serde_json::from_value(settings::get::<ThemeSettings>(cx).theme.base_theme.clone())
|
||||
.unwrap();
|
||||
Box::new(theme)
|
||||
})
|
||||
.downcast_ref::<Theme>()
|
||||
.unwrap()
|
||||
.clone()
|
||||
todo!()
|
||||
// settings::get::<ThemeSettings>(cx)
|
||||
// .theme
|
||||
// .deserialized_base_theme
|
||||
// .lock()
|
||||
// .get_or_insert_with(|| {
|
||||
// let theme: Theme =
|
||||
// serde_json::from_value(settings::get::<ThemeSettings>(cx).theme.base_theme.clone())
|
||||
// .unwrap();
|
||||
// Box::new(theme)
|
||||
// })
|
||||
// .downcast_ref::<Theme>()
|
||||
// .unwrap()
|
||||
// .clone()
|
||||
}
|
||||
|
||||
use rust_embed::RustEmbed;
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
use gpui3::{
|
||||
serde_json, AppContext, Element, Hsla, IntoAnyElement, Layout, LayoutId, Vector2F, ViewContext,
|
||||
WindowContext,
|
||||
};
|
||||
use gpui3::{Element, Hsla, Layout, LayoutId, ViewContext, WindowContext};
|
||||
use serde::{de::Visitor, Deserialize, Deserializer};
|
||||
use std::{collections::HashMap, fmt, marker::PhantomData};
|
||||
use theme::ThemeSettings;
|
||||
use std::{collections::HashMap, fmt};
|
||||
|
||||
#[derive(Deserialize, Clone, Default, Debug)]
|
||||
pub struct Theme {
|
||||
|
@ -137,6 +133,7 @@ pub struct Themed<E> {
|
|||
}
|
||||
|
||||
impl<E: Element> Element for Themed<E> {
|
||||
type State = E::State;
|
||||
type FrameState = E::FrameState;
|
||||
|
||||
fn layout(
|
||||
|
@ -147,43 +144,45 @@ impl<E: Element> Element for Themed<E> {
|
|||
where
|
||||
Self: Sized,
|
||||
{
|
||||
cx.push_theme(self.theme.clone());
|
||||
// cx.push_theme(self.theme.clone());
|
||||
let result = self.child.layout(state, cx);
|
||||
cx.pop_theme();
|
||||
// cx.pop_theme();
|
||||
result
|
||||
}
|
||||
|
||||
fn paint(
|
||||
&mut self,
|
||||
view: &mut V,
|
||||
layout: &Layout,
|
||||
state: &mut Self::FrameState,
|
||||
cx: &mut ViewContext<V>,
|
||||
layout: Layout,
|
||||
state: &mut Self::State,
|
||||
frame_state: &mut Self::FrameState,
|
||||
cx: &mut ViewContext<Self::State>,
|
||||
) where
|
||||
Self: Sized,
|
||||
{
|
||||
cx.push_theme(self.theme.clone());
|
||||
self.child.paint(view, layout, state, cx);
|
||||
cx.pop_theme();
|
||||
// todo!
|
||||
// cx.push_theme(self.theme.clone());
|
||||
self.child.paint(layout, state, frame_state, cx);
|
||||
// cx.pop_theme();
|
||||
}
|
||||
}
|
||||
|
||||
fn preferred_theme<V: 'static>(cx: &AppContext) -> Theme {
|
||||
settings::get::<ThemeSettings>(cx)
|
||||
.theme
|
||||
.deserialized_base_theme
|
||||
.lock()
|
||||
.get_or_insert_with(|| {
|
||||
let theme: Theme =
|
||||
serde_json::from_value(settings::get::<ThemeSettings>(cx).theme.base_theme.clone())
|
||||
.unwrap();
|
||||
Box::new(theme)
|
||||
})
|
||||
.downcast_ref::<Theme>()
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
// fn preferred_theme<V: 'static>(cx: &AppContext) -> Theme {
|
||||
// settings::get::<ThemeSettings>(cx)
|
||||
// .theme
|
||||
// .deserialized_base_theme
|
||||
// .lock()
|
||||
// .get_or_insert_with(|| {
|
||||
// let theme: Theme =
|
||||
// serde_json::from_value(settings::get::<ThemeSettings>(cx).theme.base_theme.clone())
|
||||
// .unwrap();
|
||||
// Box::new(theme)
|
||||
// })
|
||||
// .downcast_ref::<Theme>()
|
||||
// .unwrap()
|
||||
// .clone()
|
||||
// }
|
||||
|
||||
pub fn theme<'a>(cx: &'a WindowContext) -> &'a Theme {
|
||||
cx.theme::<Theme>()
|
||||
todo!()
|
||||
// cx.theme::<Theme>()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{collab_panel::collab_panel, theme::theme};
|
||||
use gpui3::{div, img, svg, Element, ParentElement, ScrollState, Styled, ViewContext};
|
||||
use gpui3::{div, img, svg, Element, ParentElement, ScrollState, StyleHelpers, ViewContext};
|
||||
|
||||
#[derive(Default)]
|
||||
struct WorkspaceElement {
|
||||
|
@ -7,12 +7,16 @@ struct WorkspaceElement {
|
|||
right_scroll_state: ScrollState,
|
||||
}
|
||||
|
||||
pub fn workspace<V: 'static>() -> impl Element {
|
||||
pub fn workspace() -> impl Element {
|
||||
WorkspaceElement::default()
|
||||
}
|
||||
|
||||
impl WorkspaceElement {
|
||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
|
||||
fn render<V: 'static>(
|
||||
&mut self,
|
||||
_: &mut V,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> impl Element<State = V> {
|
||||
let theme = theme(cx);
|
||||
|
||||
div()
|
||||
|
@ -43,12 +47,16 @@ impl WorkspaceElement {
|
|||
|
||||
struct TitleBar;
|
||||
|
||||
pub fn titlebar<V: 'static>() -> impl Element {
|
||||
pub fn titlebar<V: 'static>() -> impl Element<State = V> {
|
||||
TitleBar
|
||||
}
|
||||
|
||||
impl TitleBar {
|
||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
|
||||
fn render<V: 'static>(
|
||||
&mut self,
|
||||
_: &mut V,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> impl Element<State = V> {
|
||||
let theme = theme(cx);
|
||||
div()
|
||||
.flex()
|
||||
|
@ -61,7 +69,7 @@ impl TitleBar {
|
|||
.child(self.right_group(cx))
|
||||
}
|
||||
|
||||
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> {
|
||||
let theme = theme(cx);
|
||||
div()
|
||||
.flex()
|
||||
|
@ -111,10 +119,10 @@ impl TitleBar {
|
|||
.justify_center()
|
||||
.px_2()
|
||||
.rounded_md()
|
||||
.hover()
|
||||
.fill(theme.lowest.base.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.base.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.base.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.base.pressed.background)
|
||||
.child(div().text_sm().child("project")),
|
||||
)
|
||||
.child(
|
||||
|
@ -126,16 +134,16 @@ impl TitleBar {
|
|||
.px_2()
|
||||
.rounded_md()
|
||||
.text_color(theme.lowest.variant.default.foreground)
|
||||
.hover()
|
||||
.fill(theme.lowest.base.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.base.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.base.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.base.pressed.background)
|
||||
.child(div().text_sm().child("branch")),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> {
|
||||
let theme = theme(cx);
|
||||
div()
|
||||
.flex()
|
||||
|
@ -173,10 +181,10 @@ impl TitleBar {
|
|||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.hover()
|
||||
.fill(theme.lowest.base.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.base.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.base.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.base.pressed.background)
|
||||
.child(
|
||||
svg()
|
||||
.path("icons/microphone.svg")
|
||||
|
@ -193,10 +201,10 @@ impl TitleBar {
|
|||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.hover()
|
||||
.fill(theme.lowest.base.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.base.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.base.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.base.pressed.background)
|
||||
.child(
|
||||
svg()
|
||||
.path("icons/radix/speaker-loud.svg")
|
||||
|
@ -213,10 +221,10 @@ impl TitleBar {
|
|||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.hover()
|
||||
.fill(theme.lowest.base.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.base.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.base.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.base.pressed.background)
|
||||
.child(
|
||||
svg()
|
||||
.path("icons/radix/desktop.svg")
|
||||
|
@ -238,10 +246,10 @@ impl TitleBar {
|
|||
.justify_center()
|
||||
.rounded_md()
|
||||
.gap_0p5()
|
||||
.hover()
|
||||
.fill(theme.lowest.base.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.base.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.base.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.base.pressed.background)
|
||||
.child(
|
||||
img()
|
||||
.uri("https://avatars.githubusercontent.com/u/1714999?v=4")
|
||||
|
@ -265,12 +273,16 @@ impl TitleBar {
|
|||
|
||||
struct StatusBar;
|
||||
|
||||
pub fn statusbar<V: 'static>() -> impl Element {
|
||||
pub fn statusbar<V: 'static>() -> impl Element<State = V> {
|
||||
StatusBar
|
||||
}
|
||||
|
||||
impl StatusBar {
|
||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element {
|
||||
fn render<V: 'static>(
|
||||
&mut self,
|
||||
_: &mut V,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> impl Element<State = V> {
|
||||
let theme = theme(cx);
|
||||
div()
|
||||
.flex()
|
||||
|
@ -283,7 +295,7 @@ impl StatusBar {
|
|||
.child(self.right_group(cx))
|
||||
}
|
||||
|
||||
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||
fn left_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> {
|
||||
let theme = theme(cx);
|
||||
div()
|
||||
.flex()
|
||||
|
@ -358,10 +370,10 @@ impl StatusBar {
|
|||
.gap_0p5()
|
||||
.px_1()
|
||||
.text_color(theme.lowest.variant.default.foreground)
|
||||
.hover()
|
||||
.fill(theme.lowest.base.hovered.background)
|
||||
.active()
|
||||
.fill(theme.lowest.base.pressed.background)
|
||||
// .hover()
|
||||
// .fill(theme.lowest.base.hovered.background)
|
||||
// .active()
|
||||
// .fill(theme.lowest.base.pressed.background)
|
||||
.child(
|
||||
svg()
|
||||
.path("icons/error.svg")
|
||||
|
@ -380,7 +392,7 @@ impl StatusBar {
|
|||
)
|
||||
}
|
||||
|
||||
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element {
|
||||
fn right_group<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl Element<State = V> {
|
||||
let theme = theme(cx);
|
||||
div()
|
||||
.flex()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue