mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-21 23:48:12 +08:00
New nodes: Sort, Filter, Reverse, Shift, Shuffle, Number Sequence, List Indices, List Slice, Read Number (#4347)
This commit is contained in:
@@ -46,6 +46,33 @@ fn read_gradient(ctx: impl Ctx + ExtractVarArgs) -> Item<Gradient> {
|
||||
var_arg.downcast_ref().cloned().unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Reads the current number from within a **Map** node's loop.
|
||||
#[node_macro::node(category("Context"))]
|
||||
fn read_number(ctx: impl Ctx + ExtractVarArgs) -> Item<f64> {
|
||||
let Ok(var_arg) = ctx.vararg(0) else { return Default::default() };
|
||||
let var_arg = var_arg as &dyn std::any::Any;
|
||||
|
||||
if let Some(item) = var_arg.downcast_ref::<Item<f64>>() {
|
||||
return item.clone();
|
||||
}
|
||||
|
||||
// Numeric lists carry several possible element types, so probe each and widen to f64, keeping the item's attributes
|
||||
if let Some(item) = var_arg.downcast_ref::<Item<f32>>() {
|
||||
let (element, attributes) = item.clone().into_parts();
|
||||
return Item::from_parts(element as f64, attributes);
|
||||
}
|
||||
if let Some(item) = var_arg.downcast_ref::<Item<u32>>() {
|
||||
let (element, attributes) = item.clone().into_parts();
|
||||
return Item::from_parts(element as f64, attributes);
|
||||
}
|
||||
if let Some(item) = var_arg.downcast_ref::<Item<u64>>() {
|
||||
let (element, attributes) = item.clone().into_parts();
|
||||
return Item::from_parts(element as f64, attributes);
|
||||
}
|
||||
|
||||
Default::default()
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Context"), path(core_types::vector))]
|
||||
async fn read_position(
|
||||
ctx: impl Ctx + ExtractPosition,
|
||||
|
||||
Reference in New Issue
Block a user