New nodes: Colors to Gradient, Flatten Color, and Flatten Gradient (#3835)

* New nodes: Colors to Gradient, Flatten Color, and Flatten Gradient

* Fix Data panel not showing GradientStops

* Fix wrong category
This commit is contained in:
Keavon Chambers
2026-02-26 03:44:12 -08:00
committed by GitHub
parent da7437c023
commit cde7d5f951
3 changed files with 169 additions and 38 deletions

View File

@@ -204,6 +204,102 @@ pub trait IntoGraphicTable {
flatten_table(&mut output, content);
output
}
/// Deeply flattens any color content within a graphic table, discarding non-color content, and returning a table of only color elements.
fn into_flattened_color_table(self) -> Table<Color>
where
Self: std::marker::Sized,
{
let content = self.into_graphic_table();
fn flatten_table(output_color_table: &mut Table<Color>, current_graphic_table: Table<Graphic>) {
for current_graphic_row in current_graphic_table.iter() {
let current_graphic = current_graphic_row.element.clone();
let source_node_id = *current_graphic_row.source_node_id;
match current_graphic {
// If we're allowed to recurse, flatten any tables we encounter
Graphic::Graphic(mut current_graphic_table) => {
// Apply the parent graphic's transform to all child elements
for graphic in current_graphic_table.iter_mut() {
*graphic.transform = *current_graphic_row.transform * *graphic.transform;
}
flatten_table(output_color_table, current_graphic_table);
}
// Push any leaf Color elements we encounter
Graphic::Color(color_table) => {
for current_color_row in color_table.iter() {
output_color_table.push(TableRow {
element: *current_color_row.element,
transform: *current_graphic_row.transform * *current_color_row.transform,
alpha_blending: AlphaBlending {
blend_mode: current_color_row.alpha_blending.blend_mode,
opacity: current_graphic_row.alpha_blending.opacity * current_color_row.alpha_blending.opacity,
fill: current_color_row.alpha_blending.fill,
clip: current_color_row.alpha_blending.clip,
},
source_node_id,
});
}
}
_ => {}
}
}
}
let mut output = Table::new();
flatten_table(&mut output, content);
output
}
/// Deeply flattens any gradient content within a graphic table, discarding non-gradient content, and returning a table of only gradient elements.
fn into_flattened_gradient_table(self) -> Table<GradientStops>
where
Self: std::marker::Sized,
{
let content = self.into_graphic_table();
fn flatten_table(output_gradient_table: &mut Table<GradientStops>, current_graphic_table: Table<Graphic>) {
for current_graphic_row in current_graphic_table.iter() {
let current_graphic = current_graphic_row.element.clone();
let source_node_id = *current_graphic_row.source_node_id;
match current_graphic {
// If we're allowed to recurse, flatten any tables we encounter
Graphic::Graphic(mut current_graphic_table) => {
// Apply the parent graphic's transform to all child elements
for graphic in current_graphic_table.iter_mut() {
*graphic.transform = *current_graphic_row.transform * *graphic.transform;
}
flatten_table(output_gradient_table, current_graphic_table);
}
// Push any leaf GradientStops elements we encounter
Graphic::Gradient(gradient_table) => {
for current_gradient_row in gradient_table.iter() {
output_gradient_table.push(TableRow {
element: current_gradient_row.element.clone(),
transform: *current_graphic_row.transform * *current_gradient_row.transform,
alpha_blending: AlphaBlending {
blend_mode: current_gradient_row.alpha_blending.blend_mode,
opacity: current_graphic_row.alpha_blending.opacity * current_gradient_row.alpha_blending.opacity,
fill: current_gradient_row.alpha_blending.fill,
clip: current_gradient_row.alpha_blending.clip,
},
source_node_id,
});
}
}
_ => {}
}
}
}
let mut output = Table::new();
flatten_table(&mut output, content);
output
}
}
impl IntoGraphicTable for Table<Graphic> {