Replace Footprint/() call arguments with dynamically-bound Contexts (#2232)

* Implement experimental Context struct and traits

* Add Ctx super trait

* Checkpoint

* Return Any instead of DynAny

* Fix send implementation for inputs with lifetimes

* Port more nodes

* Uncomment nodes

* Port more nodes

* Port vector nodes

* Partial progress (the stuff I'm more sure about)

* Partial progress (the stuff that's not compiling and I'm not sure about)

* Fix more errors

* First pass of fixing errors introduced by rebase

* Port wasm application io

* Fix brush node types

* Add type annotation

* Fix warnings and wasm compilation

* Change types for Document Node definitions

* Improve debugging for footprint not found errors

* Forward context in append artboard node

* Fix thumbnails

* Fix loading most demo artwork

* Wrap output type of all nodes in future

* Encode futures as part of the type

* Fix document node definitions for future types

* Remove Clippy warnings

* Fix more things

* Fix opening demo art with manual composition upgrading

* Set correct type for manual composition

* Fix brush

* Fix tests

* Update docs for deps

* Fix up some node signature issues

* Code review

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
Co-authored-by: hypercube <0hypercube@gmail.com>
This commit is contained in:
Dennis Kobert
2025-03-01 23:54:52 +01:00
committed by Keavon Chambers
parent 0c1e96b9c6
commit 4ff2bdb04f
43 changed files with 1338 additions and 1545 deletions

View File

@@ -1,8 +1,8 @@
pub use self::color::{Color, Luma, SRGBA8};
use crate::raster::image::ImageFrameTable;
use crate::registry::types::Percentage;
use crate::transform::Footprint;
use crate::vector::VectorDataTable;
use crate::Ctx;
use crate::GraphicGroupTable;
use bytemuck::{Pod, Zeroable};
@@ -182,6 +182,9 @@ pub trait Alpha {
}
fn multiplied_alpha(&self, alpha: Self::AlphaChannel) -> Self;
}
pub trait AlphaMut: Alpha {
fn set_alpha(&mut self, value: Self::AlphaChannel);
}
pub trait Depth {
type DepthChannel: Channel;
@@ -228,6 +231,12 @@ pub trait Bitmap {
type Pixel: Pixel;
fn width(&self) -> u32;
fn height(&self) -> u32;
fn dimensions(&self) -> (u32, u32) {
(self.width(), self.height())
}
fn dim(&self) -> (u32, u32) {
self.dimensions()
}
fn get_pixel(&self, x: u32, y: u32) -> Option<Self::Pixel>;
}
@@ -316,51 +325,31 @@ impl SetBlendMode for ImageFrameTable<Color> {
}
#[node_macro::node(category("Style"))]
async fn blend_mode<F: 'n + Send, T: SetBlendMode>(
fn blend_mode<T: SetBlendMode>(
_: impl Ctx,
#[implementations(
(),
(),
(),
Footprint,
GraphicGroupTable,
VectorDataTable,
ImageFrameTable<Color>,
)]
footprint: F,
#[implementations(
() -> GraphicGroupTable,
() -> VectorDataTable,
() -> ImageFrameTable<Color>,
Footprint -> GraphicGroupTable,
Footprint -> VectorDataTable,
Footprint -> ImageFrameTable<Color>,
)]
value: impl Node<F, Output = T>,
mut value: T,
blend_mode: BlendMode,
) -> T {
let mut value = value.eval(footprint).await;
value.set_blend_mode(blend_mode);
value
}
#[node_macro::node(category("Style"))]
async fn opacity<F: 'n + Send, T: MultiplyAlpha>(
fn opacity<T: MultiplyAlpha>(
_: impl Ctx,
#[implementations(
(),
(),
(),
Footprint,
GraphicGroupTable,
VectorDataTable,
ImageFrameTable<Color>,
)]
footprint: F,
#[implementations(
() -> GraphicGroupTable,
() -> VectorDataTable,
() -> ImageFrameTable<Color>,
Footprint -> GraphicGroupTable,
Footprint -> VectorDataTable,
Footprint -> ImageFrameTable<Color>,
)]
value: impl Node<F, Output = T>,
mut value: T,
#[default(100.)] factor: Percentage,
) -> T {
let mut value = value.eval(footprint).await;
let opacity_multiplier = factor / 100.;
value.multiply_alpha(opacity_multiplier);
value