From 746d78364cef2542ae1d8545f98a5b47470da59d Mon Sep 17 00:00:00 2001 From: YohYamasaki Date: Tue, 19 May 2026 13:16:31 +0900 Subject: [PATCH] Add color converter and debug node to use graphic --- node-graph/libraries/core-types/src/list.rs | 3 +++ .../libraries/graphic-types/src/graphic.rs | 8 +++++- node-graph/nodes/math/src/lib.rs | 25 ++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/node-graph/libraries/core-types/src/list.rs b/node-graph/libraries/core-types/src/list.rs index 7a7df7d6ca..81f57435dd 100644 --- a/node-graph/libraries/core-types/src/list.rs +++ b/node-graph/libraries/core-types/src/list.rs @@ -80,6 +80,9 @@ pub const ATTR_GRADIENT_TYPE: &str = "gradient_type"; /// List data for fill. pub const ATTR_FILL_GRAPHIC: &str = "fill_graphic"; +/// List data for stroke. +pub const ATTR_STROKE_PAINT_GRAPHIC: &str = "stroke_paint_graphic"; + // ======================== // TRAIT: AnyAttributeValue // ======================== diff --git a/node-graph/libraries/graphic-types/src/graphic.rs b/node-graph/libraries/graphic-types/src/graphic.rs index 4d92e302cf..1bfc8195bf 100644 --- a/node-graph/libraries/graphic-types/src/graphic.rs +++ b/node-graph/libraries/graphic-types/src/graphic.rs @@ -171,7 +171,7 @@ fn flatten_graphic_list(content: List, extract_variant: fn(Graphic) } /// Converts a `Fill` enum into the `List` representation used as paint storage. -/// TODO: Remove once all paint sources flow through `List` directly without going through the `Fill` enum. +/// TODO: Remove once all fill paint sources flow through `List` directly without going through the `Fill` enum. pub fn fill_to_graphic_list(fill: &Fill) -> Option> { match fill { Fill::None => None, @@ -188,6 +188,12 @@ pub fn fill_to_graphic_list(fill: &Fill) -> Option> { } } +/// Converts a `Color` into the `List` representation used as paint storage. +/// TODO: Remove once all stroke paint sources flow through `List` directly without going through `Stroke.color`. +pub fn color_to_graphic_list(color: Option) -> Option> { + color.as_ref().map(|color| List::new_from_element((*color).into())) +} + /// Maps from a concrete element type to its corresponding `Graphic` enum variant, /// enabling type-directed casting of typed `List`s from a `Graphic` value. pub trait TryFromGraphic: Clone + Sized { diff --git a/node-graph/nodes/math/src/lib.rs b/node-graph/nodes/math/src/lib.rs index 43ffa38619..5843552006 100644 --- a/node-graph/nodes/math/src/lib.rs +++ b/node-graph/nodes/math/src/lib.rs @@ -1,5 +1,5 @@ use core_types::Context; -use core_types::list::{ATTR_FILL_GRAPHIC, List}; +use core_types::list::{ATTR_FILL_GRAPHIC, ATTR_STROKE_PAINT_GRAPHIC, List}; use core_types::registry::types::{Fraction, Percentage, PixelSize}; use core_types::transform::Footprint; use core_types::{Color, Ctx, num_traits}; @@ -1008,6 +1008,29 @@ fn fill_graphic( vectors } +/// Sets the `stroke_paint_graphic` attribute on each item of the input vector list. +/// Used for testing of gradient and clipping-based stroke rendering until the proper Stroke node refactor lands. +#[node_macro::node(category("Debug"))] +fn stroke_paint_graphic( + _: impl Ctx, + mut vectors: List, + #[implementations( + List, + List, + List>, + List>, + List, + List, + )] + stroke_paint_graphic: P, +) -> List { + let paint_list = stroke_paint_graphic.into_graphic_list(); + for row_idx in 0..vectors.len() { + vectors.set_attribute(ATTR_STROKE_PAINT_GRAPHIC, row_idx, paint_list.clone()); + } + vectors +} + #[cfg(test)] mod test { use super::*;