diff --git a/Cargo.toml b/Cargo.toml index f5c4896..0555315 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,8 +39,11 @@ repository.workspace = true readme.workspace = true [dependencies] +# Local dependencies typst_element = { version = "0.1.0", path = "crates/typst_element" } typst_vello = { version = "0.1.0", path = "crates/typst_vello" } +velyst_macros = { version = "0.1.0", path = "crates/velyst_macros" } + bevy = { workspace = true } bevy_vello = { workspace = true } typst = { workspace = true } @@ -49,7 +52,6 @@ comemo = { workspace = true } chrono = { version = "0.4.24", default-features = false, features = ["clock", "std"] } ecow = { workspace = true } thiserror = { workspace = true } -velyst_macros = { version = "0.1.0", path = "crates/velyst_macros" } [features] default = ["embed-fonts"] diff --git a/src/lib.rs b/src/lib.rs index 26bac95..b857d34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ pub mod prelude { pub use crate::asset::TypstAsset; pub use crate::renderer::{ TypstAssetHandle, TypstContent, TypstContext, TypstFunc, TypstLabel, TypstPath, - VelystCommandExt, VelystScene, VelystSet, + VelystAppExt, VelystScene, VelystSet, }; pub use crate::world::{TypstWorld, TypstWorldRef}; pub use velyst_macros::{TypstFunc, TypstPath}; diff --git a/src/renderer.rs b/src/renderer.rs index 765a7e2..d8f5b04 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -12,10 +12,10 @@ impl Plugin for VelystRendererPlugin { app.configure_sets( Update, ( - VelystSet::Layout, - VelystSet::Render, VelystSet::AssetLoading, VelystSet::Compile, + VelystSet::Layout, + VelystSet::Render, ) .chain(), ); @@ -25,17 +25,17 @@ impl Plugin for VelystRendererPlugin { /// Velyst rendering pipeline. #[derive(SystemSet, Debug, Clone, Copy, Eq, PartialEq, Hash)] pub enum VelystSet { - /// Layout [`Content`] into a [`TypstScene`] which gets stored inside [`VelystScene`]. - Layout, - /// Render [`TypstScene`] into a [`VelloScene`]. - Render, /// Loading and reloading of [`TypstAsset`]. AssetLoading, /// Compile [`TypstFunc`] into a [`TypstContent`]. Compile, + /// Layout [`Content`] into a [`TypstScene`] which gets stored inside [`VelystScene`]. + Layout, + /// Render [`TypstScene`] into a [`VelloScene`]. + Render, } -pub trait VelystCommandExt { +pub trait VelystAppExt { /// Load [`TypstAsset`] using [`TypstPath::path()`] and detect changes made towards the asset. fn register_typst_asset(&mut self) -> &mut Self; @@ -46,7 +46,7 @@ pub trait VelystCommandExt { fn render_typst_func(&mut self) -> &mut Self; } -impl VelystCommandExt for App { +impl VelystAppExt for App { fn register_typst_asset(&mut self) -> &mut Self { self.add_systems( PreStartup, @@ -147,18 +147,23 @@ fn layout_typst_content( /// System implementation for rendering [`VelystScene`] into [`VelloScene`]. fn render_velyst_scene( mut commands: Commands, - mut q_scenes: Query<(&mut VelloScene, &mut Style)>, + mut q_scenes: Query<(&mut VelloScene, &mut Style, &mut Visibility)>, mut scene: ResMut>, func: Res, ) { let scene = scene.bypass_change_detection(); - if let Some((mut vello_scene, mut style)) = scene.entity.and_then(|e| q_scenes.get_mut(e).ok()) + if let Some((mut vello_scene, mut style, mut viz)) = + scene.entity.and_then(|e| q_scenes.get_mut(e).ok()) { + // Scene **vello_scene = scene.render(); let size = scene.size(); + // Style style.width = Val::Px(size.x as f32); style.height = Val::Px(size.y as f32); + // Visibility + *viz = scene.visibility; } else { scene.entity = Some( commands @@ -167,7 +172,13 @@ fn render_velyst_scene( coordinate_space: CoordinateSpace::ScreenSpace, ..default() }) - .insert((NodeBundle::default(), func.render_layers())) + .insert(( + NodeBundle { + visibility: scene.visibility, + ..default() + }, + func.render_layers(), + )) .id(), ); } @@ -329,10 +340,12 @@ impl Default for TypstContent { /// Storage of a [`TypstScene`] in a resource as well as /// caching the render and interaction entities. #[derive(Resource, Deref, DerefMut)] -pub struct VelystScene { +pub struct VelystScene { #[deref] /// Underlying [`TypstScene`] data. scene: TypstScene, + /// Visibility of the scene. + pub visibility: Visibility, /// Entity that contains [`VelloSceneBundle`] for rendering the typst scene. entity: Option, /// Cached entities mapped by [`TypLabel`]. @@ -343,18 +356,7 @@ pub struct VelystScene { phantom: PhantomData, } -impl Default for VelystScene { - fn default() -> Self { - Self { - scene: default(), - entity: None, - cached_entities: default(), - phantom: PhantomData, - } - } -} - -impl VelystScene { +impl VelystScene { pub fn new(scene: TypstScene) -> Self { Self { scene, ..default() } } @@ -369,6 +371,18 @@ impl VelystScene { } } +impl Default for VelystScene { + fn default() -> Self { + Self { + scene: default(), + visibility: Visibility::Inherited, + entity: None, + cached_entities: default(), + phantom: PhantomData, + } + } +} + #[derive(Component, Deref, DerefMut)] pub struct TypstLabel(TypLabel);