diff --git a/Cargo.lock b/Cargo.lock index 16ff87f3dac774c2162ac01d35d039399732e7a6..599bfd5a2ed2b66637ba9bc9fdcf67048861104a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -974,7 +974,7 @@ dependencies = [ "collections", "editor", "gpui", - "itertools", + "itertools 0.10.5", "language", "outline", "project", @@ -1924,7 +1924,7 @@ dependencies = [ "cranelift-codegen", "cranelift-entity", "cranelift-frontend", - "itertools", + "itertools 0.10.5", "log", "smallvec", "wasmparser", @@ -2345,7 +2345,7 @@ dependencies = [ "git", "gpui", "indoc", - "itertools", + "itertools 0.10.5", "language", "lazy_static", "log", @@ -3135,7 +3135,7 @@ dependencies = [ "futures 0.3.28", "gpui_macros", "image", - "itertools", + "itertools 0.10.5", "lazy_static", "log", "media", @@ -3749,6 +3749,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -5478,7 +5487,7 @@ dependencies = [ "globset", "gpui", "ignore", - "itertools", + "itertools 0.10.5", "language", "lazy_static", "log", @@ -5602,7 +5611,7 @@ checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes 1.4.0", "heck 0.3.3", - "itertools", + "itertools 0.10.5", "lazy_static", "log", "multimap", @@ -5621,7 +5630,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "600d2f334aa05acb02a755e217ef1ab6dea4d51b58b7846588b747edec04efba" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "syn 1.0.109", @@ -5634,7 +5643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "syn 1.0.109", @@ -7252,7 +7261,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c12bc9199d1db8234678b7051747c07f517cdcf019262d1847b94ec8b1aee3e" dependencies = [ - "itertools", + "itertools 0.10.5", "nom", "unicode_categories", ] @@ -7378,6 +7387,7 @@ dependencies = [ "anyhow", "derive_more", "gpui2", + "itertools 0.11.0", "log", "refineable", "rust-embed", @@ -7656,7 +7666,7 @@ dependencies = [ "dirs 4.0.0", "futures 0.3.28", "gpui", - "itertools", + "itertools 0.10.5", "lazy_static", "libc", "mio-extras", @@ -7687,7 +7697,7 @@ dependencies = [ "editor", "futures 0.3.28", "gpui", - "itertools", + "itertools 0.10.5", "language", "lazy_static", "libc", @@ -8863,7 +8873,7 @@ dependencies = [ "futures 0.3.28", "gpui", "indoc", - "itertools", + "itertools 0.10.5", "language", "language_selector", "log", @@ -9696,7 +9706,7 @@ dependencies = [ "gpui", "indoc", "install_cli", - "itertools", + "itertools 0.10.5", "language", "lazy_static", "log", diff --git a/crates/storybook/Cargo.toml b/crates/storybook/Cargo.toml index 32b0b989e39ddb6e33a4a14913982afa05d67ce2..69801a94863779d25fdc1a5d53d7d501790f722b 100644 --- a/crates/storybook/Cargo.toml +++ b/crates/storybook/Cargo.toml @@ -12,6 +12,7 @@ path = "src/storybook.rs" anyhow.workspace = true derive_more.workspace = true gpui2 = { path = "../gpui2" } +itertools = "0.11.0" log.workspace = true refineable = { path = "../refineable" } rust-embed.workspace = true diff --git a/crates/storybook/src/gpui3/mod.rs b/crates/storybook/src/gpui3/mod.rs index 9f32b8abf383c241fd169a46da7c2462bc8060d1..b17f45e6173c0d99c6d88bdd6314a77e2c005111 100644 --- a/crates/storybook/src/gpui3/mod.rs +++ b/crates/storybook/src/gpui3/mod.rs @@ -3,26 +3,28 @@ mod color; mod element; mod elements; mod geometry; +mod ordered; +mod scene; mod style; mod taffy; mod window; +use self::editor::Editor; use anyhow::Result; -pub use gpui2::ArcCow; -use gpui2::Reference; - pub use app::*; pub use color::*; pub use element::*; pub use elements::*; pub use geometry::*; +pub use gpui2::ArcCow; +use gpui2::Reference; +use ordered::*; +pub use scene::*; pub use style::*; pub use taffy::LayoutId; use taffy::TaffyLayoutEngine; pub use window::*; -use self::editor::Editor; - pub trait Context { type EntityContext<'a, 'w, T: 'static>; diff --git a/crates/storybook/src/gpui3/ordered.rs b/crates/storybook/src/gpui3/ordered.rs new file mode 100644 index 0000000000000000000000000000000000000000..934a8d1c63310344f401b1693dd56cdf03184baa --- /dev/null +++ b/crates/storybook/src/gpui3/ordered.rs @@ -0,0 +1,24 @@ +pub struct Ordered

{ + pub order: u32, + pub primitive: P, +} + +impl

Ord for Ordered

{ + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.order.cmp(&other.order) + } +} + +impl

PartialOrd for Ordered

{ + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl

Eq for Ordered

{} + +impl

PartialEq for Ordered

{ + fn eq(&self, other: &Self) -> bool { + self.order == other.order + } +} diff --git a/crates/storybook/src/gpui3/scene.rs b/crates/storybook/src/gpui3/scene.rs new file mode 100644 index 0000000000000000000000000000000000000000..50184ef03b7d56b5d0e2ba7678f63d4af0d78cdd --- /dev/null +++ b/crates/storybook/src/gpui3/scene.rs @@ -0,0 +1,45 @@ +use super::Ordered; + +/// A platform neutral representation of all geometry to be drawn for the current frame. +pub struct Scene { + quads: Vec>, + glyphs: Vec>, +} + +impl Scene { + pub fn new() -> Self { + Scene { + quads: Vec::new(), + glyphs: Vec::new(), + } + } + + pub fn add(&mut self, order: u32, primitive: impl Into) { + match primitive.into() { + Primitive::Quad(primitive) => self.quads.push(Ordered { order, primitive }), + Primitive::Glyph(primitive) => self.glyphs.push(Ordered { order, primitive }), + } + } + + pub fn draw(&mut self) { + self.quads.sort_unstable(); + self.glyphs.sort_unstable(); + } +} + +pub enum Primitive { + Quad(Quad), + Glyph(Glyph), + // Icon(Icon), + // Image(Image), + // Shadow(Shadow), + // Curve(Curve), +} + +#[derive(Eq, Ord, PartialEq, PartialOrd)] +pub struct Quad {} +pub struct Glyph {} +// pub struct Icon {} +// pub struct Image {} +// pub struct Shadow {} +// pub struct Curve {}