Skip to content

Commit 36dc451

Browse files
committed
Move Vec<NodeId> to Table<NodeId>
1 parent bb5a6a2 commit 36dc451

7 files changed

Lines changed: 45 additions & 13 deletions

File tree

editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'st
170170
Table<Color>,
171171
Table<GradientStops>,
172172
Table<String>,
173+
Table<NodeId>,
173174
Table<f64>,
174175
Table<u8>,
175176
GradientStops,
@@ -791,6 +792,26 @@ impl TableRowLayout for AlphaBlending {
791792
}
792793
}
793794

795+
impl TableRowLayout for NodeId {
796+
fn type_name() -> &'static str {
797+
"NodeId"
798+
}
799+
fn identifier(&self) -> String {
800+
format!("Node {self}")
801+
}
802+
fn cell_widget(&self, _target: PathStep) -> WidgetInstance {
803+
let node_id = *self;
804+
TextButton::new("Go to Node")
805+
.tooltip_description("Click to select the node with this ID in the graph.")
806+
.on_update(move |_| NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into())
807+
.narrow(true)
808+
.widget_instance()
809+
}
810+
fn element_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
811+
vec![LayoutGroup::row(vec![self.cell_widget(PathStep::Element(0))])]
812+
}
813+
}
814+
794815
impl TableRowLayout for Option<NodeId> {
795816
fn type_name() -> &'static str {
796817
"NodeId"
@@ -830,6 +851,7 @@ macro_rules! known_table_row_types {
830851
Table<Color>,
831852
Table<GradientStops>,
832853
Table<String>,
854+
Table<NodeId>,
833855
Table<f64>,
834856
Table<u8>,
835857
GradientStops,

node-graph/graph-craft/src/document.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub enum DocumentNodeMetadata {
216216
impl DocumentNodeMetadata {
217217
pub fn ty(&self) -> Type {
218218
match self {
219-
DocumentNodeMetadata::DocumentNodePath => concrete!(Vec<NodeId>),
219+
DocumentNodeMetadata::DocumentNodePath => concrete!(core_types::table::Table<NodeId>),
220220
}
221221
}
222222
}
@@ -930,7 +930,10 @@ impl NodeNetwork {
930930
let (tagged_value, exposed) = match previous_export {
931931
NodeInput::Value { tagged_value, exposed } => (tagged_value, exposed),
932932
NodeInput::Reflection(reflect) => match reflect {
933-
DocumentNodeMetadata::DocumentNodePath => (TaggedValue::NodePath(path.to_vec()).into(), false),
933+
DocumentNodeMetadata::DocumentNodePath => {
934+
let table: core_types::table::Table<NodeId> = path.iter().copied().map(core_types::table::TableRow::new_from_element).collect();
935+
(TaggedValue::NodeIdTable(table).into(), false)
936+
}
934937
},
935938
previous_export => {
936939
*export = previous_export;

node-graph/graph-craft/src/document/value.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,14 @@ tagged_value! {
175175
U64(u64),
176176
Bool(bool),
177177
String(String),
178-
// ========================
179-
// LISTS OF PRIMITIVE TYPES
180-
// ========================
181-
NodePath(Vec<NodeId>),
182178
// ===========
183179
// TABLE TYPES
184180
// ===========
185181
StringTable(Table<String>),
186182
#[serde(deserialize_with = "core_types::misc::migrate_vec_f64_to_table")] // TODO: Eventually remove this migration document upgrade code
187183
#[serde(alias = "VecF64", alias = "VecF32", alias = "F64Array4")]
188184
F64Table(Table<f64>),
185+
NodeIdTable(Table<NodeId>),
189186
#[serde(deserialize_with = "graphic_types::migrations::migrate_vector")] // TODO: Eventually remove this migration document upgrade code
190187
#[serde(alias = "VectorData")]
191188
Vector(Table<Vector>),

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
9797
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Option<f64>]),
9898
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Option<NodeId>]),
9999
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<String>]),
100+
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<NodeId>]),
100101
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<f64>]),
101102
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<u8>]),
102103
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Graphic]),
@@ -153,6 +154,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
153154
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Image<Color>]),
154155
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<GradientStops>]),
155156
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<String>]),
157+
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<NodeId>]),
156158
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<f64>]),
157159
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<u8>]),
158160
#[cfg(target_family = "wasm")]

node-graph/nodes/gcore/src/context_modification.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ async fn context_modification<T>(
2828
Context -> DVec2,
2929
Context -> Option<NodeId>,
3030
Context -> Table<String>,
31+
Context -> Table<NodeId>,
3132
Context -> Table<f64>,
3233
Context -> Table<u8>,
3334
Context -> Table<Vector>,

node-graph/nodes/graphic/src/graphic.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@ where
173173
/// Used as the value source for stamping the `editor:layer` attribute on each row of a layer's output,
174174
/// which lets editor tools (e.g. selection, click target routing) trace data back to its owning layer.
175175
#[node_macro::node(category(""))]
176-
pub fn parent_layer(_: impl Ctx, node_path: Vec<NodeId>) -> Option<NodeId> {
176+
pub fn parent_layer(_: impl Ctx, node_path: Table<NodeId>) -> Option<NodeId> {
177177
// Get the penultimate element of the node path, or None if the path is too short
178-
node_path.get(node_path.len().wrapping_sub(2)).copied()
178+
let index = node_path.len().wrapping_sub(2);
179+
node_path.element(index).copied()
179180
}
180181

181182
/// Writes a per-row attribute column on the input table. The value-producing input is evaluated once per row,
@@ -247,11 +248,14 @@ pub async fn legacy_layer_extend<T: 'n + Send + Clone>(
247248
#[expose]
248249
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)]
249250
new: Table<T>,
250-
nested_node_path: Vec<NodeId>,
251+
nested_node_path: Table<NodeId>,
251252
) -> Table<T> {
252253
// Get the penultimate element of the node path, or None if the path is too short
253254
// This is used to get the ID of the user-facing parent layer-style node (which encapsulates this internal node).
254-
let layer = nested_node_path.get(nested_node_path.len().wrapping_sub(2)).copied();
255+
let layer = {
256+
let index = nested_node_path.len().wrapping_sub(2);
257+
nested_node_path.element(index).copied()
258+
};
255259

256260
let mut base = base;
257261
for mut row in new.into_iter() {

node-graph/nodes/vector/src/vector_modification_nodes.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ use vector_types::vector::VectorModification;
77

88
/// Applies a differential modification to a vector path, associating changes made by the Pen and Path tools to indices of edited points and segments.
99
#[node_macro::node(category(""))]
10-
async fn path_modify(_ctx: impl Ctx, mut vector: Table<Vector>, modification: Box<VectorModification>, node_path: Vec<NodeId>) -> Table<Vector> {
10+
async fn path_modify(_ctx: impl Ctx, mut vector: Table<Vector>, modification: Box<VectorModification>, node_path: Table<NodeId>) -> Table<Vector> {
1111
use core_types::table::TableRow;
1212

1313
if vector.is_empty() {
1414
vector.push(TableRow::default());
1515
}
1616
modification.apply(vector.element_mut(0).expect("push should give one item"));
1717

18-
// Update the source node id
19-
let this_node_path = node_path.iter().rev().nth(1).copied();
18+
// Update the source node id (penultimate element in the path, identifying the user-facing layer node)
19+
let this_node_path = {
20+
let index = node_path.len().wrapping_sub(2);
21+
node_path.element(index).copied()
22+
};
2023
let existing: Option<NodeId> = vector.attribute_cloned_or_default("editor:layer", 0);
2124
vector.set_attribute("editor:layer", 0, existing.or(this_node_path));
2225

0 commit comments

Comments
 (0)