New node: Assign Colors (#1938)

* New node: Assign Colors

* Simplify the Procedural String Lights demo artwork

* Add "Group" node to the node catalog

* Better comment styling in profiling action
This commit is contained in:
Keavon Chambers
2024-08-15 05:52:46 -07:00
committed by GitHub
parent 12ebc6f972
commit fa981a0897
12 changed files with 573 additions and 231 deletions

View File

@@ -55,6 +55,22 @@ impl core::hash::Hash for GraphicGroup {
}
}
impl GraphicGroup {
pub const EMPTY: Self = Self {
elements: Vec::new(),
transform: DAffine2::IDENTITY,
alpha_blending: AlphaBlending::new(),
};
pub fn new(elements: Vec<GraphicElement>) -> Self {
Self {
elements,
transform: DAffine2::IDENTITY,
alpha_blending: AlphaBlending::new(),
}
}
}
/// The possible forms of graphical content held in a Vec by the `elements` field of [`GraphicElement`].
/// Can be another recursively nested [`GraphicGroup`], a [`VectorData`] shape, an [`ImageFrame`], or an [`Artboard`].
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
@@ -74,6 +90,50 @@ impl Default for GraphicElement {
}
}
impl GraphicElement {
pub fn as_group(&self) -> Option<&GraphicGroup> {
match self {
GraphicElement::GraphicGroup(group) => Some(group),
_ => None,
}
}
pub fn as_group_mut(&mut self) -> Option<&mut GraphicGroup> {
match self {
GraphicElement::GraphicGroup(group) => Some(group),
_ => None,
}
}
pub fn as_vector_data(&self) -> Option<&VectorData> {
match self {
GraphicElement::VectorData(data) => Some(data),
_ => None,
}
}
pub fn as_vector_data_mut(&mut self) -> Option<&mut VectorData> {
match self {
GraphicElement::VectorData(data) => Some(data),
_ => None,
}
}
pub fn as_raster(&self) -> Option<&Raster> {
match self {
GraphicElement::Raster(raster) => Some(raster),
_ => None,
}
}
pub fn as_raster_mut(&mut self) -> Option<&mut Raster> {
match self {
GraphicElement::Raster(raster) => Some(raster),
_ => None,
}
}
}
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
pub enum Raster {
/// A bitmap image with a finite position and extent, equivalent to the SVG <image> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image
@@ -301,11 +361,3 @@ where
}
}
}
impl GraphicGroup {
pub const EMPTY: Self = Self {
elements: Vec::new(),
transform: DAffine2::IDENTITY,
alpha_blending: AlphaBlending::new(),
};
}