mirror of
https://github.com/zed-industries/zed.git
synced 2024-10-28 01:07:09 +00:00
WIP
This commit is contained in:
parent
a56fab8c11
commit
a0b6e500cf
6 changed files with 58 additions and 59 deletions
|
@ -1,10 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
div::div,
|
div::div,
|
||||||
element::{Element, ParentElement},
|
element::{IntoElement, ParentElement},
|
||||||
interactive::Interactive,
|
interactive::Interactive,
|
||||||
style::StyleHelpers,
|
style::StyleHelpers,
|
||||||
text::ArcCow,
|
text::ArcCow,
|
||||||
themes::rose_pine,
|
themes::Theme,
|
||||||
};
|
};
|
||||||
use gpui::{platform::MouseButton, ViewContext};
|
use gpui::{platform::MouseButton, ViewContext};
|
||||||
use playground_macros::Element;
|
use playground_macros::Element;
|
||||||
|
@ -81,10 +81,11 @@ impl<V: 'static, D: 'static> Button<V, D> {
|
||||||
&mut self,
|
&mut self,
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut ViewContext<V>,
|
cx: &mut ViewContext<V>,
|
||||||
) -> impl Element<V> + Interactive<V> {
|
) -> impl IntoElement<V> + Interactive<V> {
|
||||||
// TODO: Drive theme from the context
|
let colors = &cx.theme::<Theme>().colors;
|
||||||
|
|
||||||
let button = div()
|
let button = div()
|
||||||
.fill(rose_pine::dawn().error(0.5))
|
.fill(colors.error(0.5))
|
||||||
.h_4()
|
.h_4()
|
||||||
.children(self.label.clone());
|
.children(self.label.clone());
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ use crate::element::PaintContext;
|
||||||
pub trait Interactive<V: 'static> {
|
pub trait Interactive<V: 'static> {
|
||||||
fn interaction_handlers(&mut self) -> &mut InteractionHandlers<V>;
|
fn interaction_handlers(&mut self) -> &mut InteractionHandlers<V>;
|
||||||
|
|
||||||
// One line change.
|
|
||||||
fn on_mouse_down(
|
fn on_mouse_down(
|
||||||
mut self,
|
mut self,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
#![allow(dead_code, unused_variables)]
|
#![allow(dead_code, unused_variables)]
|
||||||
use crate::{element::ParentElement, style::StyleHelpers};
|
use element::Element;
|
||||||
use element::{Element, IntoElement};
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
geometry::{pixels, rect::RectF, vector::vec2f},
|
geometry::{rect::RectF, vector::vec2f},
|
||||||
platform::WindowOptions,
|
platform::WindowOptions,
|
||||||
ViewContext,
|
|
||||||
};
|
};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use playground_macros::Element;
|
|
||||||
use simplelog::SimpleLogger;
|
use simplelog::SimpleLogger;
|
||||||
use themes::{current_theme, rose_pine, Theme, ThemeColors};
|
use themes::{rose_pine, Theme, ThemeColors};
|
||||||
use view::view;
|
use view::view;
|
||||||
|
use workspace::workspace;
|
||||||
|
|
||||||
mod adapter;
|
mod adapter;
|
||||||
mod color;
|
mod color;
|
||||||
|
@ -26,6 +24,7 @@ mod style;
|
||||||
mod text;
|
mod text;
|
||||||
mod themes;
|
mod themes;
|
||||||
mod view;
|
mod view;
|
||||||
|
mod workspace;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||||
|
@ -55,48 +54,3 @@ fn main() {
|
||||||
fn playground<V: 'static>(theme: Theme) -> impl Element<V> {
|
fn playground<V: 'static>(theme: Theme) -> impl Element<V> {
|
||||||
workspace().themed(theme)
|
workspace().themed(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn workspace<V: 'static>() -> impl Element<V> {
|
|
||||||
WorkspaceElement
|
|
||||||
}
|
|
||||||
|
|
||||||
use crate as playground;
|
|
||||||
#[derive(Element)]
|
|
||||||
struct WorkspaceElement;
|
|
||||||
|
|
||||||
impl WorkspaceElement {
|
|
||||||
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
|
|
||||||
use div::div;
|
|
||||||
let theme = &cx.theme::<Theme>().colors;
|
|
||||||
// one line change1!
|
|
||||||
div()
|
|
||||||
.full()
|
|
||||||
.flex()
|
|
||||||
.flex_col()
|
|
||||||
.fill(theme.base(0.5))
|
|
||||||
.child(self.title_bar(cx))
|
|
||||||
.child(self.stage(cx))
|
|
||||||
.child(self.status_bar(cx))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
|
||||||
use div::div;
|
|
||||||
|
|
||||||
let theme = ¤t_theme(cx).colors;
|
|
||||||
div().h(pixels(cx.titlebar_height())).fill(theme.base(0.))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn status_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
|
||||||
use div::div;
|
|
||||||
|
|
||||||
let theme = ¤t_theme(cx).colors;
|
|
||||||
div().h(pixels(cx.titlebar_height())).fill(theme.base(0.))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stage<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
|
||||||
use div::div;
|
|
||||||
|
|
||||||
let theme = ¤t_theme(cx).colors;
|
|
||||||
div().flex_grow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub struct Theme {
|
||||||
pub colors: ThemeColors,
|
pub colors: ThemeColors,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_theme<'a>(cx: &'a WindowContext) -> &'a Theme {
|
pub fn theme<'a>(cx: &'a WindowContext) -> &'a Theme {
|
||||||
cx.theme::<Theme>()
|
cx.theme::<Theme>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
45
crates/gpui/playground/src/workspace.rs
Normal file
45
crates/gpui/playground/src/workspace.rs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
use crate::div::div;
|
||||||
|
use crate::element::{IntoElement, ParentElement};
|
||||||
|
use crate::style::StyleHelpers;
|
||||||
|
use crate::themes::theme;
|
||||||
|
use crate::{element::Element, themes::Theme};
|
||||||
|
use gpui::geometry::pixels;
|
||||||
|
use gpui::ViewContext;
|
||||||
|
use playground_macros::Element;
|
||||||
|
|
||||||
|
use crate as playground;
|
||||||
|
#[derive(Element)]
|
||||||
|
struct WorkspaceElement;
|
||||||
|
|
||||||
|
pub fn workspace<V: 'static>() -> impl Element<V> {
|
||||||
|
WorkspaceElement
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WorkspaceElement {
|
||||||
|
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
||||||
|
let theme = &cx.theme::<Theme>().colors;
|
||||||
|
div()
|
||||||
|
.full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.fill(theme.base(0.5))
|
||||||
|
.child(self.title_bar(cx))
|
||||||
|
.child(self.stage(cx))
|
||||||
|
.child(self.status_bar(cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
||||||
|
let colors = &theme(cx).colors;
|
||||||
|
div().h(pixels(cx.titlebar_height())).fill(colors.base(0.))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn status_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
||||||
|
let colors = &theme(cx).colors;
|
||||||
|
div().h(pixels(cx.titlebar_height())).fill(colors.base(0.))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stage<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
||||||
|
let colors = &theme(cx).colors;
|
||||||
|
div().flex_grow()
|
||||||
|
}
|
||||||
|
}
|
|
@ -69,7 +69,7 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
|
||||||
view: &mut V,
|
view: &mut V,
|
||||||
cx: &mut playground::element::LayoutContext<V>,
|
cx: &mut playground::element::LayoutContext<V>,
|
||||||
) -> anyhow::Result<(playground::element::LayoutId, Self::PaintState)> {
|
) -> anyhow::Result<(playground::element::LayoutId, Self::PaintState)> {
|
||||||
let mut rendered_element = self.render(view, cx).into_any();
|
let mut rendered_element = self.render(view, cx).into_element().into_any();
|
||||||
let layout_id = rendered_element.layout(view, cx)?;
|
let layout_id = rendered_element.layout(view, cx)?;
|
||||||
Ok((layout_id, rendered_element))
|
Ok((layout_id, rendered_element))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue