mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Replace raw node input indices with compile-time parameter symbols (#4387)
* Remove the dead InputAccessor traits and the uncallable test helper built on them * Replace raw node input indices with macro-generated parameter symbols across the editor * Audit dynamic input index usage, converting to parameter symbols and named input position constants * Abstract the remaining input index plumbing behind ParameterRef APIs and accessors * Build SetInputValue messages as struct literals to keep message enums impl-free * Delete the typed parameter markers in favor of explicit-output test introspection * Wire the interpolation control path input per chain node type * Return no input when a parameter symbol is read against the wrong node's parameter view
This commit is contained in:
@@ -141,24 +141,29 @@ impl<'i, I, O: 'i> Node<'i, I> for Pin<&'i (dyn NodeIO<'i, I, Output = O> + 'i)>
|
||||
}
|
||||
}
|
||||
|
||||
pub trait InputAccessorSource<'a, T>: InputAccessorSourceIdentifier + std::fmt::Debug {
|
||||
fn get_input(&'a self, index: usize) -> Option<&'a T>;
|
||||
fn set_input(&'a mut self, index: usize, value: T);
|
||||
}
|
||||
|
||||
pub trait InputAccessorSourceIdentifier {
|
||||
fn has_identifier(&self, identifier: &str) -> bool;
|
||||
}
|
||||
|
||||
pub trait InputAccessor<'n, Source: 'n>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn new_with_source(source: &'n Source) -> Option<Self>;
|
||||
}
|
||||
|
||||
pub trait NodeInputDecleration {
|
||||
/// A compile-time symbol naming one parameter of one proto node.
|
||||
/// The node macro generates a unit struct implementing this for every parameter, so code can pass the type itself (e.g. `stroke::WeightInput`) instead of a raw input index.
|
||||
pub trait NodeParameter {
|
||||
/// The proto node this parameter belongs to.
|
||||
const NODE_IDENTIFIER: ProtoNodeIdentifier;
|
||||
/// Position of this parameter among the node's inputs.
|
||||
/// Prefer passing the symbol to an API that accepts it; reach for this only at genuinely index-based boundaries.
|
||||
const INDEX: usize;
|
||||
fn identifier() -> ProtoNodeIdentifier;
|
||||
type Result;
|
||||
}
|
||||
|
||||
/// A runtime reference to one parameter of one proto node, for heterogeneous tables and runtime-chosen parameters.
|
||||
/// Convert a symbol with `.into()`; unlike a raw index, the node identifier and index always stay paired.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParameterRef {
|
||||
pub node_identifier: ProtoNodeIdentifier,
|
||||
pub input_index: usize,
|
||||
}
|
||||
|
||||
impl<P: NodeParameter> From<P> for ParameterRef {
|
||||
fn from(_: P) -> Self {
|
||||
ParameterRef {
|
||||
node_identifier: P::NODE_IDENTIFIER,
|
||||
input_index: P::INDEX,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user