Rework Gradient into a newtype of List<Color> with optional position and midpoint attributes (#4397)

* Rework Gradient into a newtype of List<Color> with optional position and midpoint attributes

* Fix Vello stopless-gradient fallback coverage, empty legacy gradient tables, the node docs gradient swatch, NaN position elision, and wired setter input overwrites
This commit is contained in:
Keavon Chambers
2026-08-03 04:05:02 -07:00
committed by GitHub
parent e52a442504
commit 2f24459344
34 changed files with 1121 additions and 475 deletions

View File

@@ -177,13 +177,9 @@ fn write_inputs(page: &mut std::fs::File, valid_input_types: &[Vec<core_types::T
{
let default_value = default_value.trim_end_matches('.').trim_end_matches(".0"); // Display whole-number floats as integers
let render_color = |color| format!(r#"<span style="padding-right: 100px; border: 2px solid var(--color-fog); background: {color}"></span>"#);
// Compare against the typed default's debug form so the swatch tracks the `Gradient` representation
let black_to_white_gradient = value::TaggedValue::Gradient(Default::default()).to_debug_string();
let default_value = match default_value {
"Color::BLACK" => render_color("black"),
gradient if gradient == black_to_white_gradient => render_color("linear-gradient(to right, black, white)"),
_ => format!("`{default_value}{}`", field.unit.unwrap_or_default()),
let default_value = match field.default_colors {
Some(colors) => color_swatch(colors),
None => format!("`{default_value}{}`", field.unit.unwrap_or_default()),
};
details.push(format!("<p>*Default:*&nbsp;{default_value}</p>"));
@@ -210,6 +206,17 @@ fn write_inputs(page: &mut std::fs::File, valid_input_types: &[Vec<core_types::T
}
}
/// A bordered swatch painted with one color, or with several as the stops of a left-to-right gradient.
fn color_swatch(colors: &[core_types::Color]) -> String {
let hex: Vec<String> = colors.iter().map(|&color| format!("#{}", core_types::color::SRGBA8::from(color).to_rgba_hex())).collect();
let background = match hex.as_slice() {
[single] => single.clone(),
multiple => format!("linear-gradient(to right, {})", multiple.join(", ")),
};
format!(r#"<span style="padding-right: 100px; border: 2px solid var(--color-fog); background: {background}"></span>"#)
}
fn write_outputs(page: &mut std::fs::File, valid_primary_outputs: &[core_types::Type]) {
// Product
let product = "Result";