Add color converter and debug node to use graphic

This commit is contained in:
YohYamasaki
2026-05-19 13:16:31 +09:00
parent 3fd61169ae
commit 746d78364c
3 changed files with 34 additions and 2 deletions

View File

@@ -80,6 +80,9 @@ pub const ATTR_GRADIENT_TYPE: &str = "gradient_type";
/// List<Graphic> data for fill.
pub const ATTR_FILL_GRAPHIC: &str = "fill_graphic";
/// List<Graphic> data for stroke.
pub const ATTR_STROKE_PAINT_GRAPHIC: &str = "stroke_paint_graphic";
// ========================
// TRAIT: AnyAttributeValue
// ========================

View File

@@ -171,7 +171,7 @@ fn flatten_graphic_list<T>(content: List<Graphic>, extract_variant: fn(Graphic)
}
/// Converts a `Fill` enum into the `List<Graphic>` representation used as paint storage.
/// TODO: Remove once all paint sources flow through `List<Graphic>` directly without going through the `Fill` enum.
/// TODO: Remove once all fill paint sources flow through `List<Graphic>` directly without going through the `Fill` enum.
pub fn fill_to_graphic_list(fill: &Fill) -> Option<List<Graphic>> {
match fill {
Fill::None => None,
@@ -188,6 +188,12 @@ pub fn fill_to_graphic_list(fill: &Fill) -> Option<List<Graphic>> {
}
}
/// Converts a `Color` into the `List<Graphic>` representation used as paint storage.
/// TODO: Remove once all stroke paint sources flow through `List<Graphic>` directly without going through `Stroke.color`.
pub fn color_to_graphic_list(color: Option<Color>) -> Option<List<Graphic>> {
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 {