zed/crates/gpui/playground/src/playground.rs

103 lines
2.6 KiB
Rust
Raw Normal View History

2023-08-11 06:26:58 +00:00
#![allow(dead_code, unused_variables)]
use crate::{element::ParentElement, style::StyleHelpers};
use element::{Element, IntoElement};
2023-08-22 15:07:45 +00:00
use gpui::{
geometry::{pixels, rect::RectF, vector::vec2f},
2023-08-22 15:07:45 +00:00
platform::WindowOptions,
ViewContext,
2023-08-22 15:07:45 +00:00
};
use log::LevelFilter;
use playground_macros::Element;
use simplelog::SimpleLogger;
use themes::{current_theme, rose_pine, Theme, ThemeColors};
2023-08-22 15:07:45 +00:00
use view::view;
2023-07-25 05:27:14 +00:00
2023-08-14 03:20:41 +00:00
mod adapter;
2023-08-11 06:26:58 +00:00
mod color;
2023-08-16 01:29:57 +00:00
mod components;
mod div;
2023-08-14 01:47:49 +00:00
mod element;
mod hoverable;
mod interactive;
2023-08-20 01:51:17 +00:00
mod layout_context;
2023-08-16 19:52:42 +00:00
mod paint_context;
mod pressable;
2023-08-13 23:29:07 +00:00
mod style;
2023-08-16 12:22:47 +00:00
mod text;
2023-08-11 06:26:58 +00:00
mod themes;
2023-08-14 15:26:35 +00:00
mod view;
2023-08-11 06:26:58 +00:00
fn main() {
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
2023-08-11 06:26:58 +00:00
gpui::App::new(()).unwrap().run(|cx| {
2023-08-22 15:07:45 +00:00
cx.add_window(
WindowOptions {
bounds: gpui::platform::WindowBounds::Fixed(RectF::new(
vec2f(0., 0.),
vec2f(400., 300.),
)),
center: true,
..Default::default()
},
|_| {
view(|cx| {
playground(Theme {
colors: rose_pine::dawn(),
})
})
},
2023-08-22 15:07:45 +00:00
);
cx.platform().activate(true);
});
2023-07-25 05:27:14 +00:00
}
fn playground<V: 'static>(theme: Theme) -> impl Element<V> {
workspace().themed(theme)
}
2023-08-22 15:07:45 +00:00
fn workspace<V: 'static>() -> impl Element<V> {
WorkspaceElement
2023-08-22 15:07:45 +00:00
}
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 = &current_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 = &current_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 = &current_theme(cx).colors;
div().flex_grow()
}
}