mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
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:
committed by
Dennis Kobert
parent
b78e4b107e
commit
86d4106592
@@ -8,7 +8,7 @@ use std::sync::atomic::AtomicU64;
|
||||
use syn::punctuated::Punctuated;
|
||||
use syn::visit::Visit;
|
||||
use syn::visit_mut::VisitMut;
|
||||
use syn::{GenericArgument, GenericParam, Ident, Lifetime, PatIdent, PathArguments, Type, TypeParam, TypeParamBound};
|
||||
use syn::{Expr, ExprPath, GenericArgument, GenericParam, Ident, Lifetime, PatIdent, PathArguments, Token, Type, TypeParam, TypeParamBound};
|
||||
|
||||
pub(crate) mod classify;
|
||||
mod entries;
|
||||
@@ -348,6 +348,20 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
||||
})
|
||||
.collect();
|
||||
|
||||
let default_colors: Vec<_> = regular_fields
|
||||
.iter()
|
||||
.map(|field| match field.ty.regular() {
|
||||
Some(RegularParsedField {
|
||||
value_source: ParsedValueSource::Default(data),
|
||||
..
|
||||
}) => match color_constant_paths(data) {
|
||||
Some(paths) => quote!(Some(&[#(#paths),*])),
|
||||
None => quote!(None),
|
||||
},
|
||||
_ => quote!(None),
|
||||
})
|
||||
.collect();
|
||||
|
||||
let default_types: Vec<_> = regular_fields
|
||||
.iter()
|
||||
.map(|field| match &field.ty {
|
||||
@@ -682,6 +696,7 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
||||
hidden: #input_hidden,
|
||||
exposed: #exposed,
|
||||
value_source: #value_sources,
|
||||
default_colors: #default_colors,
|
||||
default_type: #default_types,
|
||||
number_soft_min: #number_soft_min_values,
|
||||
number_soft_max: #number_soft_max_values,
|
||||
@@ -2959,3 +2974,22 @@ pub(crate) fn generate_node_impl(crate_ident: &CrateIdent, parsed: &ParsedNodeFn
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn color_constant_paths(tokens: &TokenStream2) -> Option<Vec<ExprPath>> {
|
||||
use syn::parse::Parser;
|
||||
|
||||
let expressions = Punctuated::<Expr, Token![,]>::parse_terminated.parse2(tokens.clone()).ok()?;
|
||||
if expressions.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
expressions
|
||||
.into_iter()
|
||||
.map(|expression| {
|
||||
let Expr::Path(path) = expression else { return None };
|
||||
let segments = &path.path.segments;
|
||||
let is_color_constant = path.qself.is_none() && segments.len() == 2 && segments[0].ident == "Color" && segments.iter().all(|segment| segment.arguments.is_none());
|
||||
is_color_constant.then_some(path)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -267,6 +267,16 @@ pub enum ParsedFieldType {
|
||||
Node(NodeParsedField),
|
||||
}
|
||||
|
||||
impl ParsedFieldType {
|
||||
/// The shared value-field data, present for every value field but not a lazy `Node`.
|
||||
pub fn regular(&self) -> Option<&RegularParsedField> {
|
||||
match self {
|
||||
ParsedFieldType::Regular(field) => Some(field),
|
||||
ParsedFieldType::Node(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A single numeric endpoint within a `#[soft(..)]` or `#[hard(..)]` bounds range.
|
||||
/// Accepts both integer literals (e.g. `1`, `-1`) and float literals (e.g. `1.`, `-500.`).
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user