Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'gpui2' into zed2
Marshall Bowersbb35583998f4
diff --cc crates/storybook2/src/storybook2.rsindex 6aba3f5c26b,bbd62230cc2..2d348baac2c--- a/crates/storybook2/src/storybook2.rs+++ b/crates/storybook2/src/storybook2.rs@@@ -9,9 -9,9 +9,9 @@@ mod themesuse std::sync::Arc;use clap::Parser;-use gpui3::{- div, px, size, view, AnyView, AppContext, AssetSource, BorrowAppContext, Bounds, Context,- Element, ViewContext, WindowBounds, WindowOptions,+use gpui2::{- div, px, size, view, AnyView, Bounds, Context, Element, ViewContext, WindowBounds,- WindowOptions,++ div, px, size, view, AnyView, AppContext, AssetSource, Bounds, Context, Element, ViewContext,++ WindowBounds, WindowOptions,};use log::LevelFilter;use simplelog::SimpleLogger;@@@ -52,7 -53,9 +52,9 @@@ fn main()let theme = themes::load_theme(theme_name).unwrap();let asset_source = Arc::new(Assets);- gpui3::App::production(asset_source).run(move |cx| {+ gpui2::App::production(asset_source).run(move |cx| {+ load_embedded_fonts(cx).unwrap();+let selector =story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));@@@ -101,15 -114,16 +103,16 @@@ impl StoryWrapper}}- // 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();- // }-fn load_embedded_fonts(cx: &AppContext) -> gpui3::Result<()> {++fn load_embedded_fonts(cx: &AppContext) -> gpui2::Result<()> {+ let font_paths = Assets.list(&"fonts".into())?;+ 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)?.to_vec();+ embedded_fonts.push(Arc::from(font_bytes));+ }+ }++ cx.text_system().add_fonts(&embedded_fonts)+ }diff --cc crates/ui2/src/components/modal.rsindex a8acaf41b4e,00000000000..9871036d23fmode 100644,000000..100644--- a/crates/ui2/src/components/modal.rs+++ b/crates/ui2/src/components/modal.rs@@@ -1,87 -1,0 +1,87 @@@+use std::marker::PhantomData;++use gpui2::AnyElement;+use smallvec::SmallVec;++use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label};++#[derive(Element)]+pub struct Modal<S: 'static + Send + Sync> {+ id: ElementId,+ state_type: PhantomData<S>,+ title: Option<SharedString>,+ primary_action: Option<Button<S>>,+ secondary_action: Option<Button<S>>,+ children: SmallVec<[AnyElement<S>; 2]>,+}++impl<S: 'static + Send + Sync> Modal<S> {+ pub fn new(id: impl Into<ElementId>) -> Self {+ Self {+ id: id.into(),+ state_type: PhantomData,+ title: None,+ primary_action: None,+ secondary_action: None,+ children: SmallVec::new(),+ }+ }++ pub fn title(mut self, title: impl Into<SharedString>) -> Self {+ self.title = Some(title.into());+ self+ }++ pub fn primary_action(mut self, action: Button<S>) -> Self {+ self.primary_action = Some(action);+ self+ }++ pub fn secondary_action(mut self, action: Button<S>) -> Self {+ self.secondary_action = Some(action);+ self+ }++ fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {+ let color = ThemeColor::new(cx);++ v_stack()+ .id(self.id.clone())+ .w_96()+ // .rounded_xl()+ .bg(color.background)+ .border()+ .border_color(color.border)+ .shadow_2xl()+ .child(+ h_stack()+ .justify_between()+ .p_1()+ .border_b()+ .border_color(color.border)+ .child(div().children(self.title.clone().map(|t| Label::new(t))))- .child(IconButton::new(Icon::Close)),++ .child(IconButton::new("close", Icon::Close)),+ )+ .child(v_stack().p_1().children(self.children.drain(..)))+ .when(+ self.primary_action.is_some() || self.secondary_action.is_some(),+ |this| {+ this.child(+ h_stack()+ .border_t()+ .border_color(color.border)+ .p_1()+ .justify_end()+ .children(self.secondary_action.take())+ .children(self.primary_action.take()),+ )+ },+ )+ }+}++impl<S: 'static + Send + Sync> ParentElement for Modal<S> {+ fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<Self::ViewState>; 2]> {+ &mut self.children+ }+}