2023-09-20 20:32:55 +00:00
|
|
|
#![allow(dead_code, unused_variables)]
|
|
|
|
|
2023-10-04 08:51:47 +00:00
|
|
|
mod assets;
|
2023-10-04 16:49:06 +00:00
|
|
|
mod stories;
|
|
|
|
mod story;
|
|
|
|
mod story_selector;
|
2023-09-26 19:42:58 +00:00
|
|
|
mod themes;
|
2023-09-20 20:32:55 +00:00
|
|
|
|
2023-10-04 17:33:28 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use clap::Parser;
|
2023-10-21 14:01:47 +00:00
|
|
|
use gpui2::{
|
2023-10-26 17:41:42 +00:00
|
|
|
div, px, size, AnyView, AppContext, Bounds, ViewContext, VisualContext, WindowBounds,
|
2023-10-25 13:50:50 +00:00
|
|
|
WindowOptions,
|
2023-10-04 17:33:28 +00:00
|
|
|
};
|
|
|
|
use log::LevelFilter;
|
2023-10-25 18:37:55 +00:00
|
|
|
use settings2::{default_settings, Settings, SettingsStore};
|
2023-10-04 17:33:28 +00:00
|
|
|
use simplelog::SimpleLogger;
|
2023-10-18 20:21:04 +00:00
|
|
|
use story_selector::ComponentStory;
|
2023-10-25 18:37:55 +00:00
|
|
|
use theme2::{ThemeRegistry, ThemeSettings};
|
2023-10-22 16:25:24 +00:00
|
|
|
use ui::{prelude::*, themed};
|
2023-10-04 17:33:28 +00:00
|
|
|
|
|
|
|
use crate::assets::Assets;
|
|
|
|
use crate::story_selector::StorySelector;
|
|
|
|
|
2023-09-20 20:32:55 +00:00
|
|
|
// gpui2::actions! {
|
|
|
|
// storybook,
|
|
|
|
// [ToggleInspector]
|
|
|
|
// }
|
|
|
|
|
2023-10-04 17:33:28 +00:00
|
|
|
#[derive(Parser)]
|
|
|
|
#[command(author, version, about, long_about = None)]
|
|
|
|
struct Args {
|
|
|
|
#[arg(value_enum)]
|
|
|
|
story: Option<StorySelector>,
|
|
|
|
|
|
|
|
/// The name of the theme to use in the storybook.
|
|
|
|
///
|
|
|
|
/// If not provided, the default theme will be used.
|
|
|
|
#[arg(long)]
|
|
|
|
theme: Option<String>,
|
|
|
|
}
|
|
|
|
|
2023-09-20 20:32:55 +00:00
|
|
|
fn main() {
|
2023-09-30 02:53:24 +00:00
|
|
|
// unsafe { backtrace_on_stack_overflow::enable() };
|
2023-09-30 01:21:08 +00:00
|
|
|
|
2023-09-20 20:32:55 +00:00
|
|
|
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
|
|
|
|
2023-10-04 17:33:28 +00:00
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
let story_selector = args.story.clone();
|
2023-10-09 20:53:28 +00:00
|
|
|
let theme_name = args.theme.unwrap_or("One Dark".to_string());
|
2023-10-25 13:50:50 +00:00
|
|
|
let theme = themes::load_theme(theme_name.clone()).unwrap();
|
2023-10-09 19:52:57 +00:00
|
|
|
|
2023-10-04 08:51:47 +00:00
|
|
|
let asset_source = Arc::new(Assets);
|
2023-10-21 14:01:47 +00:00
|
|
|
gpui2::App::production(asset_source).run(move |cx| {
|
2023-10-24 11:31:01 +00:00
|
|
|
load_embedded_fonts(cx).unwrap();
|
2023-10-24 10:32:30 +00:00
|
|
|
|
2023-10-25 18:37:55 +00:00
|
|
|
let mut store = SettingsStore::default();
|
|
|
|
store
|
|
|
|
.set_default_settings(default_settings().as_ref(), cx)
|
|
|
|
.unwrap();
|
|
|
|
cx.set_global(store);
|
|
|
|
|
|
|
|
theme2::init(cx);
|
|
|
|
|
2023-10-18 20:21:04 +00:00
|
|
|
let selector =
|
|
|
|
story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));
|
|
|
|
|
2023-10-25 18:37:55 +00:00
|
|
|
let theme_registry = cx.global::<ThemeRegistry>();
|
2023-10-25 13:50:50 +00:00
|
|
|
|
2023-10-25 18:37:55 +00:00
|
|
|
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
|
|
|
theme_settings.active_theme = theme_registry.get(&theme_name).unwrap();
|
|
|
|
ThemeSettings::override_global(theme_settings, cx);
|
2023-10-25 13:50:50 +00:00
|
|
|
|
2023-10-23 09:34:35 +00:00
|
|
|
cx.set_global(theme.clone());
|
|
|
|
ui::settings::init(cx);
|
|
|
|
|
2023-10-18 20:21:04 +00:00
|
|
|
let window = cx.open_window(
|
|
|
|
WindowOptions {
|
|
|
|
bounds: WindowBounds::Fixed(Bounds {
|
|
|
|
origin: Default::default(),
|
|
|
|
size: size(px(1700.), px(980.)).into(),
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
move |cx| {
|
2023-10-26 17:41:42 +00:00
|
|
|
cx.build_view(
|
|
|
|
|cx| StoryWrapper::new(selector.story(cx), theme),
|
2023-10-18 20:21:04 +00:00
|
|
|
StoryWrapper::render,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
);
|
2023-09-30 16:01:59 +00:00
|
|
|
|
|
|
|
cx.activate(true);
|
2023-09-21 04:26:46 +00:00
|
|
|
});
|
2023-09-20 20:32:55 +00:00
|
|
|
}
|
|
|
|
|
2023-10-04 22:25:43 +00:00
|
|
|
#[derive(Clone)]
|
2023-10-04 17:33:28 +00:00
|
|
|
pub struct StoryWrapper {
|
2023-10-12 20:11:59 +00:00
|
|
|
story: AnyView,
|
2023-10-09 19:52:57 +00:00
|
|
|
theme: Theme,
|
2023-10-04 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl StoryWrapper {
|
2023-10-12 20:11:59 +00:00
|
|
|
pub(crate) fn new(story: AnyView, theme: Theme) -> Self {
|
2023-10-22 16:25:24 +00:00
|
|
|
Self { story, theme }
|
2023-10-04 17:33:28 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 10:46:52 +00:00
|
|
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Component<Self> {
|
2023-10-22 16:25:24 +00:00
|
|
|
themed(self.theme.clone(), cx, |cx| {
|
|
|
|
div()
|
|
|
|
.flex()
|
|
|
|
.flex_col()
|
|
|
|
.size_full()
|
|
|
|
.child(self.story.clone())
|
2023-10-04 17:33:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-24 12:11:13 +00:00
|
|
|
fn load_embedded_fonts(cx: &AppContext) -> gpui2::Result<()> {
|
2023-10-24 14:59:01 +00:00
|
|
|
let font_paths = cx.asset_source().list("fonts")?;
|
2023-10-24 10:32:30 +00:00
|
|
|
let mut embedded_fonts = Vec::new();
|
2023-10-24 14:59:01 +00:00
|
|
|
for font_path in font_paths {
|
2023-10-24 10:32:30 +00:00
|
|
|
if font_path.ends_with(".ttf") {
|
2023-10-24 15:47:41 +00:00
|
|
|
let font_bytes = cx.asset_source().load(&font_path)?.to_vec();
|
2023-10-24 10:32:30 +00:00
|
|
|
embedded_fonts.push(Arc::from(font_bytes));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-24 11:31:01 +00:00
|
|
|
cx.text_system().add_fonts(&embedded_fonts)
|
2023-10-24 10:32:30 +00:00
|
|
|
}
|