2023-08-11 06:26:58 +00:00
|
|
|
#![allow(dead_code, unused_variables)]
|
2023-09-05 18:16:21 +00:00
|
|
|
|
2023-09-22 02:41:53 +00:00
|
|
|
mod collab_panel;
|
|
|
|
mod stories;
|
2023-09-22 15:38:01 +00:00
|
|
|
mod story;
|
2023-09-22 02:41:53 +00:00
|
|
|
mod workspace;
|
|
|
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
2023-08-30 22:12:14 +00:00
|
|
|
use ::theme as legacy_theme;
|
2023-09-22 02:41:53 +00:00
|
|
|
use clap::Parser;
|
|
|
|
use gpui2::{serde_json, vec2f, view, Element, IntoElement, RectF, ViewContext, WindowBounds};
|
2023-08-30 22:12:14 +00:00
|
|
|
use legacy_theme::ThemeSettings;
|
2023-07-14 21:34:31 +00:00
|
|
|
use log::LevelFilter;
|
2023-08-30 17:09:34 +00:00
|
|
|
use settings::{default_settings, SettingsStore};
|
2023-07-14 21:34:31 +00:00
|
|
|
use simplelog::SimpleLogger;
|
2023-09-22 20:57:33 +00:00
|
|
|
use stories::components::breadcrumb::BreadcrumbStory;
|
2023-09-22 02:41:53 +00:00
|
|
|
use stories::components::facepile::FacepileStory;
|
2023-09-22 20:57:33 +00:00
|
|
|
use stories::components::toolbar::ToolbarStory;
|
2023-09-22 03:42:18 +00:00
|
|
|
use stories::components::traffic_lights::TrafficLightsStory;
|
2023-09-22 02:41:53 +00:00
|
|
|
use stories::elements::avatar::AvatarStory;
|
2023-09-22 18:06:09 +00:00
|
|
|
use strum::EnumString;
|
2023-09-21 23:25:35 +00:00
|
|
|
use ui::{ElementExt, Theme};
|
2023-07-25 05:27:14 +00:00
|
|
|
|
2023-09-08 04:24:02 +00:00
|
|
|
gpui2::actions! {
|
|
|
|
storybook,
|
|
|
|
[ToggleInspector]
|
|
|
|
}
|
|
|
|
|
2023-09-22 02:41:53 +00:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2023-09-22 15:38:01 +00:00
|
|
|
enum StorySelector {
|
2023-09-22 02:41:53 +00:00
|
|
|
Element(ElementStory),
|
|
|
|
Component(ComponentStory),
|
|
|
|
}
|
|
|
|
|
2023-09-22 15:38:01 +00:00
|
|
|
impl FromStr for StorySelector {
|
2023-09-22 02:41:53 +00:00
|
|
|
type Err = anyhow::Error;
|
|
|
|
|
2023-09-22 18:06:09 +00:00
|
|
|
fn from_str(raw_story_name: &str) -> std::result::Result<Self, Self::Err> {
|
|
|
|
let story = raw_story_name.to_ascii_lowercase();
|
|
|
|
|
|
|
|
if let Some((_, story)) = story.split_once("elements/") {
|
|
|
|
let element_story = ElementStory::from_str(story)
|
|
|
|
.with_context(|| format!("story not found for element '{story}'"))?;
|
|
|
|
|
|
|
|
return Ok(Self::Element(element_story));
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some((_, story)) = story.split_once("components/") {
|
|
|
|
let component_story = ComponentStory::from_str(story)
|
|
|
|
.with_context(|| format!("story not found for component '{story}'"))?;
|
|
|
|
|
|
|
|
return Ok(Self::Component(component_story));
|
2023-09-22 02:41:53 +00:00
|
|
|
}
|
2023-09-22 18:06:09 +00:00
|
|
|
|
|
|
|
Err(anyhow!("story not found for '{raw_story_name}'"))
|
2023-09-22 02:41:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-22 18:06:09 +00:00
|
|
|
#[derive(Debug, Clone, Copy, EnumString)]
|
|
|
|
#[strum(serialize_all = "snake_case")]
|
2023-09-22 02:41:53 +00:00
|
|
|
enum ElementStory {
|
|
|
|
Avatar,
|
|
|
|
}
|
|
|
|
|
2023-09-22 18:06:09 +00:00
|
|
|
#[derive(Debug, Clone, Copy, EnumString)]
|
|
|
|
#[strum(serialize_all = "snake_case")]
|
2023-09-22 02:41:53 +00:00
|
|
|
enum ComponentStory {
|
2023-09-22 20:57:33 +00:00
|
|
|
Breadcrumb,
|
2023-09-22 02:41:53 +00:00
|
|
|
Facepile,
|
2023-09-22 20:57:33 +00:00
|
|
|
Toolbar,
|
2023-09-22 03:42:18 +00:00
|
|
|
TrafficLights,
|
2023-09-22 02:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
struct Args {
|
2023-09-22 15:38:01 +00:00
|
|
|
story: Option<StorySelector>,
|
2023-09-22 02:41:53 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:46:09 +00:00
|
|
|
fn main() {
|
|
|
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
2023-08-11 06:26:58 +00:00
|
|
|
|
2023-09-22 02:41:53 +00:00
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
gpui2::App::new(Assets).unwrap().run(move |cx| {
|
2023-08-30 17:09:34 +00:00
|
|
|
let mut store = SettingsStore::default();
|
|
|
|
store
|
|
|
|
.set_default_settings(default_settings().as_ref(), cx)
|
|
|
|
.unwrap();
|
|
|
|
cx.set_global(store);
|
2023-08-30 22:12:14 +00:00
|
|
|
legacy_theme::init(Assets, cx);
|
2023-09-05 18:16:21 +00:00
|
|
|
// load_embedded_fonts(cx.platform().as_ref());
|
2023-08-30 17:09:34 +00:00
|
|
|
|
2023-08-22 15:07:45 +00:00
|
|
|
cx.add_window(
|
2023-08-30 22:12:14 +00:00
|
|
|
gpui2::WindowOptions {
|
2023-09-11 14:36:49 +00:00
|
|
|
bounds: WindowBounds::Fixed(RectF::new(vec2f(0., 0.), vec2f(1600., 900.))),
|
2023-08-22 15:07:45 +00:00
|
|
|
center: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
2023-09-22 02:41:53 +00:00
|
|
|
|cx| match args.story {
|
2023-09-22 15:38:01 +00:00
|
|
|
Some(StorySelector::Element(ElementStory::Avatar)) => {
|
2023-09-22 02:41:53 +00:00
|
|
|
view(|cx| render_story(&mut ViewContext::new(cx), AvatarStory::default()))
|
|
|
|
}
|
2023-09-22 20:57:33 +00:00
|
|
|
Some(StorySelector::Component(ComponentStory::Breadcrumb)) => {
|
|
|
|
view(|cx| render_story(&mut ViewContext::new(cx), BreadcrumbStory::default()))
|
|
|
|
}
|
2023-09-22 15:38:01 +00:00
|
|
|
Some(StorySelector::Component(ComponentStory::Facepile)) => {
|
2023-09-22 02:41:53 +00:00
|
|
|
view(|cx| render_story(&mut ViewContext::new(cx), FacepileStory::default()))
|
|
|
|
}
|
2023-09-22 20:57:33 +00:00
|
|
|
Some(StorySelector::Component(ComponentStory::Toolbar)) => {
|
|
|
|
view(|cx| render_story(&mut ViewContext::new(cx), ToolbarStory::default()))
|
|
|
|
}
|
2023-09-22 15:38:01 +00:00
|
|
|
Some(StorySelector::Component(ComponentStory::TrafficLights)) => view(|cx| {
|
2023-09-22 03:42:18 +00:00
|
|
|
render_story(&mut ViewContext::new(cx), TrafficLightsStory::default())
|
|
|
|
}),
|
2023-09-22 02:41:53 +00:00
|
|
|
None => {
|
|
|
|
view(|cx| render_story(&mut ViewContext::new(cx), WorkspaceElement::default()))
|
|
|
|
}
|
2023-09-08 04:24:02 +00:00
|
|
|
},
|
2023-08-22 15:07:45 +00:00
|
|
|
);
|
2023-08-14 20:46:09 +00:00
|
|
|
cx.platform().activate(true);
|
|
|
|
});
|
2023-07-25 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 02:41:53 +00:00
|
|
|
fn render_story<V: 'static, S: IntoElement<V>>(
|
|
|
|
cx: &mut ViewContext<V>,
|
|
|
|
story: S,
|
|
|
|
) -> impl Element<V> {
|
|
|
|
story.into_element().themed(current_theme(cx))
|
2023-08-30 17:09:34 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:50:07 +00:00
|
|
|
// Nathan: During the transition to gpui2, we will include the base theme on the legacy Theme struct.
|
2023-08-30 17:09:34 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2023-09-22 18:06:09 +00:00
|
|
|
use anyhow::{anyhow, Context, Result};
|
2023-08-30 22:12:14 +00:00
|
|
|
use gpui2::AssetSource;
|
2023-08-30 17:09:34 +00:00
|
|
|
use rust_embed::RustEmbed;
|
2023-09-22 02:41:53 +00:00
|
|
|
use workspace::WorkspaceElement;
|
2023-08-30 17:09:34 +00:00
|
|
|
|
|
|
|
#[derive(RustEmbed)]
|
2023-08-30 22:12:14 +00:00
|
|
|
#[folder = "../../assets"]
|
2023-08-30 17:09:34 +00:00
|
|
|
#[include = "themes/**/*"]
|
2023-09-05 18:16:21 +00:00
|
|
|
#[include = "fonts/**/*"]
|
2023-09-05 22:40:52 +00:00
|
|
|
#[include = "icons/**/*"]
|
2023-08-30 17:09:34 +00:00
|
|
|
#[exclude = "*.DS_Store"]
|
|
|
|
pub struct Assets;
|
|
|
|
|
|
|
|
impl AssetSource for Assets {
|
|
|
|
fn load(&self, path: &str) -> Result<std::borrow::Cow<[u8]>> {
|
|
|
|
Self::get(path)
|
|
|
|
.map(|f| f.data)
|
|
|
|
.ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn list(&self, path: &str) -> Vec<std::borrow::Cow<'static, str>> {
|
|
|
|
Self::iter().filter(|p| p.starts_with(path)).collect()
|
|
|
|
}
|
2023-08-28 21:13:59 +00:00
|
|
|
}
|
2023-09-05 18:16:21 +00:00
|
|
|
|
|
|
|
// fn load_embedded_fonts(platform: &dyn gpui2::Platform) {
|
|
|
|
// let font_paths = Assets.list("fonts");
|
|
|
|
// let mut embedded_fonts = Vec::new();
|
|
|
|
// for font_path in &font_paths {
|
|
|
|
// if font_path.ends_with(".ttf") {
|
|
|
|
// let font_path = &*font_path;
|
|
|
|
// let font_bytes = Assets.load(font_path).unwrap().to_vec();
|
|
|
|
// embedded_fonts.push(Arc::from(font_bytes));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// platform.fonts().add_fonts(&embedded_fonts).unwrap();
|
|
|
|
// }
|