Skip to content

Commit 075e5d6

Browse files
committed
Improve data type organization
1 parent c13647a commit 075e5d6

7 files changed

Lines changed: 92 additions & 71 deletions

File tree

editor/src/messages/frontend/frontend_message.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
33
use crate::messages::input_mapper::utility_types::misc::ActionShortcut;
44
use crate::messages::layout::utility_types::widget_prelude::*;
55
use crate::messages::portfolio::document::node_graph::utility_types::{
6-
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphErrorDiagnostic, Transform,
6+
ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphErrorDiagnostic, NodeGraphSelectionBox, NodeGraphTransform,
7+
WirePathInProgress,
78
};
89
use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, LayerPanelEntry, RawBuffer};
9-
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
10+
use crate::messages::portfolio::document::utility_types::wires::WirePathUpdate;
1011
use crate::messages::prelude::*;
1112
use glam::IVec2;
1213
use graph_craft::document::NodeId;
@@ -167,9 +168,9 @@ pub enum FrontendMessage {
167168
#[serde(rename = "inSelectedNetwork")]
168169
in_selected_network: bool,
169170
},
170-
UpdateBox {
171-
#[serde(rename = "box")]
172-
box_selection: Option<BoxSelection>,
171+
UpdateNodeGraphSelectionBox {
172+
#[serde(rename = "selectionBox")]
173+
selection_box: Option<NodeGraphSelectionBox>,
173174
},
174175
UpdateContextMenuInformation {
175176
#[serde(rename = "contextMenuInformation")]
@@ -298,7 +299,7 @@ pub enum FrontendMessage {
298299
selected: Vec<NodeId>,
299300
},
300301
UpdateNodeGraphTransform {
301-
transform: Transform,
302+
transform: NodeGraphTransform,
302303
},
303304
UpdateNodeThumbnail {
304305
id: NodeId,
@@ -318,8 +319,8 @@ pub enum FrontendMessage {
318319
diff: Vec<WidgetDiff>,
319320
},
320321
UpdateWirePathInProgress {
321-
#[serde(rename = "wirePath")]
322-
wire_path: Option<WirePath>,
322+
#[serde(rename = "wirePathInProgress")]
323+
wire_path_in_progress: Option<WirePathInProgress>,
323324
},
324325
UpdateWelcomeScreenButtonsLayout {
325326
diff: Vec<WidgetDiff>,

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::node_graph::document_node_definitions;
2-
use super::node_graph::utility_types::Transform;
2+
use super::node_graph::utility_types::NodeGraphTransform;
33
use super::utility_types::error::EditorError;
44
use super::utility_types::misc::{GroupFolderType, SNAP_FUNCTIONS_FOR_BOUNDING_BOXES, SNAP_FUNCTIONS_FOR_PATHS, SnappingOptions, SnappingState};
55
use super::utility_types::network_interface::{self, NodeNetworkInterface, TransactionStatus};
@@ -22,6 +22,7 @@ use crate::messages::portfolio::document::utility_types::network_interface::{Flo
2222
use crate::messages::portfolio::document::utility_types::nodes::RawBuffer;
2323
use crate::messages::portfolio::utility_types::{FontCatalog, PanelType, PersistentData};
2424
use crate::messages::prelude::*;
25+
2526
use crate::messages::tool::common_functionality::graph_modification_utils::{self, get_blend_mode, get_fill, get_opacity};
2627
use crate::messages::tool::tool_messages::select_tool::SelectToolPointerKeys;
2728
use crate::messages::tool::tool_messages::tool_prelude::Key;
@@ -485,15 +486,15 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
485486
responses.add(NodeGraphMessage::SelectedNodesSet {
486487
nodes: self.node_graph_handler.selection_before_pointer_down.clone(),
487488
});
488-
responses.add(FrontendMessage::UpdateBox { box_selection: None });
489+
responses.add(FrontendMessage::UpdateNodeGraphSelectionBox { selection_box: None });
489490
}
490491
// Abort wire in progress of being connected
491492
else if self.node_graph_handler.wire_in_progress_from_connector.is_some() {
492493
self.node_graph_handler.wire_in_progress_from_connector = None;
493494
self.node_graph_handler.wire_in_progress_to_connector = None;
494495
self.node_graph_handler.wire_in_progress_type = FrontendGraphDataType::General;
495496

496-
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
497+
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path_in_progress: None });
497498
responses.add(DocumentMessage::AbortTransaction);
498499
}
499500
// Close the context menu if it's open
@@ -1525,7 +1526,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
15251526
responses.add(NodeGraphMessage::UpdateImportsExports);
15261527

15271528
responses.add(FrontendMessage::UpdateNodeGraphTransform {
1528-
transform: Transform {
1529+
transform: NodeGraphTransform {
15291530
scale: transform.matrix2.x_axis.x,
15301531
x: transform.translation.x,
15311532
y: transform.translation.y,

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::node_properties;
2-
use super::utility_types::{BoxSelection, ContextMenuInformation, DragStart, FrontendNode};
2+
use super::utility_types::{ContextMenuInformation, DragStart, FrontendNode, NodeGraphSelectionBox};
33
use crate::consts::GRID_SIZE;
44
use crate::messages::clipboard::utility_types::ClipboardContent;
55
use crate::messages::input_mapper::utility_types::macros::{action_shortcut, action_shortcut_manual};
@@ -9,14 +9,14 @@ use crate::messages::portfolio::document::graph_operation::utility_types::Modify
99
use crate::messages::portfolio::document::node_graph::document_node_definitions::{
1010
DefinitionIdentifier, NodePropertiesContext, resolve_document_node_type, resolve_network_node_type, resolve_proto_node_type,
1111
};
12-
use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction, FrontendGraphDataType, NodeGraphErrorDiagnostic};
12+
use crate::messages::portfolio::document::node_graph::utility_types::{ContextMenuData, Direction, FrontendGraphDataType, NodeGraphErrorDiagnostic, WirePathInProgress};
1313
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
1414
use crate::messages::portfolio::document::utility_types::misc::GroupFolderType;
1515
use crate::messages::portfolio::document::utility_types::network_interface::{
1616
self, FlowType, InputConnector, NodeNetworkInterface, NodeTemplate, NodeTypePersistentMetadata, OutputConnector, Previewing,
1717
};
1818
use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers, LayerPanelEntry};
19-
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePath, WirePathUpdate, build_vector_wire};
19+
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePathUpdate, build_vector_wire};
2020
use crate::messages::prelude::*;
2121
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
2222
use crate::messages::tool::common_functionality::graph_modification_utils::get_clip_mode;
@@ -329,7 +329,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
329329
self.wire_in_progress_to_connector = None;
330330
self.wire_in_progress_type = FrontendGraphDataType::General;
331331
}
332-
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
332+
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path_in_progress: None });
333333
responses.add(FrontendMessage::UpdateContextMenuInformation {
334334
context_menu_information: self.context_menu.clone(),
335335
});
@@ -790,7 +790,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
790790
responses.add(NodeGraphMessage::SelectedNodesSet {
791791
nodes: self.selection_before_pointer_down.clone(),
792792
});
793-
responses.add(FrontendMessage::UpdateBox { box_selection: None });
793+
responses.add(FrontendMessage::UpdateNodeGraphSelectionBox { selection_box: None });
794794
return;
795795
}
796796
// Abort dragging a wire
@@ -800,7 +800,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
800800
self.wire_in_progress_type = FrontendGraphDataType::General;
801801

802802
responses.add(DocumentMessage::AbortTransaction);
803-
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
803+
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path_in_progress: None });
804+
804805
return;
805806
}
806807

@@ -885,7 +886,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
885886
responses.add(FrontendMessage::UpdateContextMenuInformation {
886887
context_menu_information: self.context_menu.clone(),
887888
});
888-
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
889+
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path_in_progress: None });
889890
}
890891

891892
// Toggle visibility of clicked node and return
@@ -1094,14 +1095,14 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
10941095
to_connector_is_layer,
10951096
GraphWireStyle::Direct,
10961097
);
1097-
let path_string = vector_wire.to_svg();
1098-
let wire_path = WirePath {
1099-
path_string,
1098+
let wire_path = WirePathInProgress {
1099+
wire: vector_wire.to_svg(),
11001100
data_type: self.wire_in_progress_type,
11011101
thick: false,
1102-
dashed: false,
11031102
};
1104-
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: Some(wire_path) });
1103+
responses.add(FrontendMessage::UpdateWirePathInProgress {
1104+
wire_path_in_progress: Some(wire_path),
1105+
});
11051106
}
11061107
} else if let Some((drag_start, dragged)) = &mut self.drag_start {
11071108
if drag_start.start_x != point.x || drag_start.start_y != point.y {
@@ -1431,8 +1432,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
14311432
self.reordering_import = None;
14321433

14331434
responses.add(DocumentMessage::EndTransaction);
1434-
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
1435-
responses.add(FrontendMessage::UpdateBox { box_selection: None });
1435+
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path_in_progress: None });
1436+
responses.add(FrontendMessage::UpdateNodeGraphSelectionBox { selection_box: None });
14361437
responses.add(FrontendMessage::UpdateImportReorderIndex { index: None });
14371438
responses.add(FrontendMessage::UpdateExportReorderIndex { index: None });
14381439
self.update_node_graph_hints(responses);
@@ -1926,23 +1927,14 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
19261927
}
19271928
NodeGraphMessage::UpdateBoxSelection => {
19281929
if let Some((box_selection_start, _)) = self.box_selection_start {
1929-
// The mouse button was released but we missed the pointer up event
1930-
// if ((e.buttons & 1) === 0) {
1931-
// completeBoxSelection();
1932-
// boxSelection = undefined;
1933-
// } else if ((e.buttons & 2) !== 0) {
1934-
// editor.handle.selectNodes(new BigUint64Array(previousSelection));
1935-
// boxSelection = undefined;
1936-
// }
1937-
19381930
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
19391931
log::error!("Could not get network metadata in UpdateBoxSelection");
19401932
return;
19411933
};
19421934

19431935
let box_selection_start_viewport = network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.transform_point2(box_selection_start);
19441936

1945-
let box_selection = Some(BoxSelection {
1937+
let selection_box = Some(NodeGraphSelectionBox {
19461938
start_x: box_selection_start_viewport.x.max(0.) as u32,
19471939
start_y: box_selection_start_viewport.y.max(0.) as u32,
19481940
end_x: ipp.mouse.position.x.max(0.) as u32,
@@ -1987,7 +1979,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
19871979
nodes: nodes.into_iter().collect::<Vec<_>>(),
19881980
});
19891981
}
1990-
responses.add(FrontendMessage::UpdateBox { box_selection })
1982+
responses.add(FrontendMessage::UpdateNodeGraphSelectionBox { selection_box })
19911983
}
19921984
}
19931985
NodeGraphMessage::UpdateImportsExports => {

editor/src/messages/portfolio/document/node_graph/utility_types.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ pub struct DragStart {
119119
}
120120

121121
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
122-
pub struct Transform {
122+
pub struct NodeGraphTransform {
123123
pub scale: f64,
124124
pub x: f64,
125125
pub y: f64,
126126
}
127127

128128
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
129-
pub struct BoxSelection {
129+
pub struct NodeGraphSelectionBox {
130130
#[serde(rename = "startX")]
131131
pub start_x: u32,
132132
#[serde(rename = "startY")]
@@ -137,6 +137,14 @@ pub struct BoxSelection {
137137
pub end_y: u32,
138138
}
139139

140+
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
141+
pub struct WirePathInProgress {
142+
pub wire: String,
143+
#[serde(rename = "dataType")]
144+
pub data_type: FrontendGraphDataType,
145+
pub thick: bool,
146+
}
147+
140148
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
141149
#[serde(tag = "type", content = "data")]
142150
pub enum ContextMenuData {

frontend/src/components/views/Graph.svelte

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
import TextButton from "@graphite/components/widgets/buttons/TextButton.svelte";
1515
import TextLabel from "@graphite/components/widgets/labels/TextLabel.svelte";
1616
17+
// These components will continue to be rendered in svelte after the first stage of native node graph rendering.
18+
// - Import and export ports
19+
// - Wires to import and export
20+
// - Wire in progress
21+
// - Add Node context menu
22+
// - Toggle Layer context menu
23+
// - Error dialog
24+
// - Node/Input/Output Tooltips
25+
// - Solo drag grip tooltip
26+
27+
// These elements will be not be rendered in svelte when rendering the native node graph. They are rendered below all other components
28+
// - Dot grid background
29+
// - Nodes/Layers
30+
// - Wires between nodes/layers
31+
1732
const GRID_COLLAPSE_SPACING = 10;
1833
const GRID_SIZE = 24;
1934
const FADE_TRANSITION = { duration: 200, easing: cubicInOut };
@@ -618,11 +633,10 @@
618633
{/each}
619634
{#if $nodeGraph.wirePathInProgress}
620635
<path
621-
d={$nodeGraph.wirePathInProgress?.pathString}
636+
d={$nodeGraph.wirePathInProgress?.wire}
622637
style:--data-line-width={`${$nodeGraph.wirePathInProgress.thick ? 8 : 2}px`}
623638
style:--data-color={`var(--color-data-${$nodeGraph.wirePathInProgress.dataType.toLowerCase()})`}
624639
style:--data-color-dim={`var(--color-data-${$nodeGraph.wirePathInProgress.dataType.toLowerCase()}-dim)`}
625-
style:--data-dasharray={`3,${$nodeGraph.wirePathInProgress.dashed ? 2 : 0}`}
626640
/>
627641
{/if}
628642
</svg>
@@ -768,13 +782,13 @@
768782
</div>
769783

770784
<!-- Box selection widget -->
771-
{#if $nodeGraph.box}
785+
{#if $nodeGraph.selectionBox}
772786
<div
773787
class="box-selection"
774-
style:left={`${Math.min($nodeGraph.box.startX, $nodeGraph.box.endX)}px`}
775-
style:top={`${Math.min($nodeGraph.box.startY, $nodeGraph.box.endY)}px`}
776-
style:width={`${Math.abs($nodeGraph.box.startX - $nodeGraph.box.endX)}px`}
777-
style:height={`${Math.abs($nodeGraph.box.startY - $nodeGraph.box.endY)}px`}
788+
style:left={`${Math.min($nodeGraph.selectionBox.startX, $nodeGraph.selectionBox.endX)}px`}
789+
style:top={`${Math.min($nodeGraph.selectionBox.startY, $nodeGraph.selectionBox.endY)}px`}
790+
style:width={`${Math.abs($nodeGraph.selectionBox.startX - $nodeGraph.selectionBox.endX)}px`}
791+
style:height={`${Math.abs($nodeGraph.selectionBox.startY - $nodeGraph.selectionBox.endY)}px`}
778792
></div>
779793
{/if}
780794

frontend/src/messages.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,24 @@ export type XY = { x: number; y: number };
2525
// for details about how to transform the JSON from wasm-bindgen into classes.
2626
// ============================================================================
2727

28-
export class UpdateBox extends JsMessage {
29-
readonly box!: Box | undefined;
30-
}
31-
3228
export class UpdateClickTargets extends JsMessage {
3329
readonly clickTargets!: FrontendClickTargets | undefined;
3430
}
3531

32+
export class NodeGraphSelectionBox {
33+
readonly startX!: number;
34+
35+
readonly startY!: number;
36+
37+
readonly endX!: number;
38+
39+
readonly endY!: number;
40+
}
41+
42+
export class UpdateNodeGraphSelectionBox extends JsMessage {
43+
readonly selectionBox!: NodeGraphSelectionBox | undefined;
44+
}
45+
3646
export class UpdateImportsExports extends JsMessage {
3747
readonly imports!: (FrontendGraphOutput | undefined)[];
3848

@@ -138,8 +148,14 @@ export class UpdateOpenDocumentsList extends JsMessage {
138148
readonly openDocuments!: OpenDocument[];
139149
}
140150

151+
export class WirePathInProgress {
152+
readonly wire!: string;
153+
readonly thick!: boolean;
154+
readonly dataType!: FrontendGraphDataType;
155+
}
156+
141157
export class UpdateWirePathInProgress extends JsMessage {
142-
readonly wirePath!: WirePath | undefined;
158+
readonly wirePathInProgress!: WirePathInProgress | undefined;
143159
}
144160

145161
export class OpenDocument {
@@ -157,16 +173,6 @@ export class DocumentDetails {
157173
readonly isSaved!: boolean;
158174
}
159175

160-
export class Box {
161-
readonly startX!: number;
162-
163-
readonly startY!: number;
164-
165-
readonly endX!: number;
166-
167-
readonly endY!: number;
168-
}
169-
170176
export type FrontendClickTargets = {
171177
readonly nodeClickTargets: string[];
172178
readonly layerClickTargets: string[];
@@ -1694,7 +1700,6 @@ export const messageMakers: Record<string, MessageMaker> = {
16941700
TriggerSelectionWrite,
16951701
TriggerVisitLink,
16961702
UpdateActiveDocument,
1697-
UpdateBox,
16981703
UpdateClickTargets,
16991704
UpdateContextMenuInformation,
17001705
UpdateDataPanelLayout,
@@ -1726,6 +1731,7 @@ export const messageMakers: Record<string, MessageMaker> = {
17261731
UpdateNodeGraphErrorDiagnostic,
17271732
UpdateNodeGraphNodes,
17281733
UpdateNodeGraphSelection,
1734+
UpdateNodeGraphSelectionBox,
17291735
UpdateNodeGraphTransform,
17301736
UpdateNodeGraphWires,
17311737
UpdateNodeThumbnail,

0 commit comments

Comments
 (0)