rive_rs/shapes/
shape_paint_container.rs
use std::cell::Cell;
use crate::core::{Core, Object, ObjectRef, OnAdded};
use crate::dyn_vec::DynVec;
use crate::shapes::paint::{ShapePaint, Stroke};
use crate::shapes::{PathSpace, Shape};
use crate::Artboard;
#[derive(Debug, Default)]
pub struct ShapePaintContainer {
default_path_space: Cell<PathSpace>,
shape_paints: DynVec<Object<ShapePaint>>,
}
impl ShapePaintContainer {
pub fn push_paint(&self, shape_paint: Object<ShapePaint>) {
self.shape_paints.push(shape_paint);
}
pub(crate) fn shape_paints(&self) -> impl Iterator<Item = Object<ShapePaint>> + '_ {
self.shape_paints.iter()
}
pub fn path_space(&self) -> PathSpace {
self.shape_paints
.iter()
.map(|shape_paint| shape_paint.as_ref().path_space())
.fold(self.default_path_space.get(), |a, e| a | e)
}
pub fn add_default_path_space(&self, space: PathSpace) {
self.default_path_space.set(self.default_path_space.get() | space);
}
pub fn invalidate_stroke_effects(&self) {
for paint in self.shape_paints.iter() {
if let Some(stroke) = paint.try_cast::<Stroke>() {
stroke.as_ref().invalidate_effects();
}
}
}
pub fn make_command_path(&self, _space: PathSpace) {
todo!();
}
}
impl TryFrom<Object> for Object<ShapePaintContainer> {
type Error = ();
fn try_from(value: Object) -> Result<Self, Self::Error> {
if let Some(artboard) = value.try_cast::<Artboard>() {
return Ok(artboard.cast());
}
if let Some(shape) = value.try_cast::<Shape>() {
return Ok(shape.cast());
}
Err(())
}
}
impl Core for ShapePaintContainer {}
impl OnAdded for ObjectRef<'_, ShapePaintContainer> {
on_added!();
}