Skip to content

Commit 26fa8d9

Browse files
Add the style of right-angle grid-aligned wires in the graph (#2182)
* Verticle and horizontal lines achieved(#2170) * vertical lines alligned with grid dots * fixed vertical lines positioning * Deals with cases 5 and 6 * Fixed case 5 and other problematic zones * edge cases solved * edge cases fixed: HorizontalOut & HorizontalIn * added comments * Changed midX and midY * Clean up if/else statements * Consolidate code * Consolidate further * Add preference for wire style --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 2d90bb0 commit 26fa8d9

File tree

11 files changed

+393
-58
lines changed

11 files changed

+393
-58
lines changed

editor/src/messages/dialog/preferences_dialog/preferences_dialog_message_handler.rs

+50-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::messages::layout::utility_types::widget_prelude::*;
2+
use crate::messages::portfolio::document::node_graph::utility_types::GraphWireStyle;
23
use crate::messages::preferences::SelectionMode;
34
use crate::messages::prelude::*;
45

@@ -32,6 +33,29 @@ impl PreferencesDialogMessageHandler {
3233
const TITLE: &'static str = "Editor Preferences";
3334

3435
fn layout(&self, preferences: &PreferencesMessageHandler) -> Layout {
36+
// =====
37+
// INPUT
38+
// =====
39+
40+
let zoom_with_scroll_tooltip = "Use the scroll wheel for zooming instead of vertically panning (not recommended for trackpads)";
41+
let input_section = vec![TextLabel::new("Input").italic(true).widget_holder()];
42+
let zoom_with_scroll = vec![
43+
CheckboxInput::new(preferences.zoom_with_scroll)
44+
.tooltip(zoom_with_scroll_tooltip)
45+
.on_update(|checkbox_input: &CheckboxInput| {
46+
PreferencesMessage::ModifyLayout {
47+
zoom_with_scroll: checkbox_input.checked,
48+
}
49+
.into()
50+
})
51+
.widget_holder(),
52+
TextLabel::new("Zoom with Scroll").table_align(true).tooltip(zoom_with_scroll_tooltip).widget_holder(),
53+
];
54+
55+
// =========
56+
// SELECTION
57+
// =========
58+
3559
let selection_section = vec![TextLabel::new("Selection").italic(true).widget_holder()];
3660
let selection_mode = RadioInput::new(vec![
3761
RadioEntryData::new(SelectionMode::Touched.to_string())
@@ -65,20 +89,28 @@ impl PreferencesDialogMessageHandler {
6589
.selected_index(Some(preferences.selection_mode as u32))
6690
.widget_holder();
6791

68-
let zoom_with_scroll_tooltip = "Use the scroll wheel for zooming instead of vertically panning (not recommended for trackpads)";
69-
let input_section = vec![TextLabel::new("Input").italic(true).widget_holder()];
70-
let zoom_with_scroll = vec![
71-
CheckboxInput::new(preferences.zoom_with_scroll)
72-
.tooltip(zoom_with_scroll_tooltip)
73-
.on_update(|checkbox_input: &CheckboxInput| {
74-
PreferencesMessage::ModifyLayout {
75-
zoom_with_scroll: checkbox_input.checked,
76-
}
77-
.into()
78-
})
79-
.widget_holder(),
80-
TextLabel::new("Zoom with Scroll").table_align(true).tooltip(zoom_with_scroll_tooltip).widget_holder(),
81-
];
92+
// ================
93+
// NODE GRAPH WIRES
94+
// ================
95+
96+
let node_graph_section_tooltip = "Appearance of the wires running between node connections in the graph";
97+
let node_graph_section = vec![TextLabel::new("Node Graph Wires").tooltip(node_graph_section_tooltip).italic(true).widget_holder()];
98+
let graph_wire_style = RadioInput::new(vec![
99+
RadioEntryData::new(GraphWireStyle::GridAligned.to_string())
100+
.label(GraphWireStyle::GridAligned.to_string())
101+
.tooltip(GraphWireStyle::GridAligned.tooltip_description())
102+
.on_update(move |_| PreferencesMessage::GraphWireStyle { style: GraphWireStyle::GridAligned }.into()),
103+
RadioEntryData::new(GraphWireStyle::Direct.to_string())
104+
.label(GraphWireStyle::Direct.to_string())
105+
.tooltip(GraphWireStyle::Direct.tooltip_description())
106+
.on_update(move |_| PreferencesMessage::GraphWireStyle { style: GraphWireStyle::Direct }.into()),
107+
])
108+
.selected_index(Some(preferences.graph_wire_style as u32))
109+
.widget_holder();
110+
111+
// ============
112+
// EXPERIMENTAL
113+
// ============
82114

83115
let vello_tooltip = "Use the experimental Vello renderer (your browser must support WebGPU)";
84116
let renderer_section = vec![TextLabel::new("Experimental").italic(true).widget_holder()];
@@ -126,10 +158,12 @@ impl PreferencesDialogMessageHandler {
126158
// ];
127159

128160
Layout::WidgetLayout(WidgetLayout::new(vec![
129-
LayoutGroup::Row { widgets: selection_section },
130-
LayoutGroup::Row { widgets: vec![selection_mode] },
131161
LayoutGroup::Row { widgets: input_section },
132162
LayoutGroup::Row { widgets: zoom_with_scroll },
163+
LayoutGroup::Row { widgets: selection_section },
164+
LayoutGroup::Row { widgets: vec![selection_mode] },
165+
LayoutGroup::Row { widgets: node_graph_section },
166+
LayoutGroup::Row { widgets: vec![graph_wire_style] },
133167
LayoutGroup::Row { widgets: renderer_section },
134168
LayoutGroup::Row { widgets: use_vello },
135169
LayoutGroup::Row { widgets: vector_meshes },

editor/src/messages/frontend/frontend_message.rs

+2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ pub enum FrontendMessage {
250250
UpdateNodeGraph {
251251
nodes: Vec<FrontendNode>,
252252
wires: Vec<FrontendNodeWire>,
253+
#[serde(rename = "wiresDirectNotGridAligned")]
254+
wires_direct_not_grid_aligned: bool,
253255
},
254256
UpdateNodeGraphControlBarLayout {
255257
#[serde(rename = "layoutTarget")]

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

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct DocumentMessageData<'a> {
4242
pub persistent_data: &'a PersistentData,
4343
pub executor: &'a mut NodeGraphExecutor,
4444
pub current_tool: &'a ToolType,
45+
pub preferences: &'a PreferencesMessageHandler,
4546
}
4647

4748
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
@@ -172,6 +173,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
172173
persistent_data,
173174
executor,
174175
current_tool,
176+
preferences,
175177
} = data;
176178

177179
let selected_nodes_bounding_box_viewport = self.network_interface.selected_nodes_bounding_box_viewport(&self.breadcrumb_network_path);
@@ -222,6 +224,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
222224
graph_view_overlay_open: self.graph_view_overlay_open,
223225
graph_fade_artwork_percentage: self.graph_fade_artwork_percentage,
224226
navigation_handler: &self.navigation_handler,
227+
preferences,
225228
},
226229
);
227230
}

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct NodeGraphHandlerData<'a> {
3535
pub graph_view_overlay_open: bool,
3636
pub graph_fade_artwork_percentage: f64,
3737
pub navigation_handler: &'a NavigationMessageHandler,
38+
pub preferences: &'a PreferencesMessageHandler,
3839
}
3940

4041
#[derive(Debug, Clone)]
@@ -93,6 +94,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
9394
graph_view_overlay_open,
9495
graph_fade_artwork_percentage,
9596
navigation_handler,
97+
preferences,
9698
} = data;
9799

98100
match message {
@@ -1293,8 +1295,14 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
12931295
let wires = Self::collect_wires(network_interface, breadcrumb_network_path);
12941296
let nodes = self.collect_nodes(network_interface, breadcrumb_network_path);
12951297
let (layer_widths, chain_widths, has_left_input_wire) = network_interface.collect_layer_widths(breadcrumb_network_path);
1298+
let wires_direct_not_grid_aligned = preferences.graph_wire_style.is_direct();
1299+
12961300
responses.add(NodeGraphMessage::UpdateImportsExports);
1297-
responses.add(FrontendMessage::UpdateNodeGraph { nodes, wires });
1301+
responses.add(FrontendMessage::UpdateNodeGraph {
1302+
nodes,
1303+
wires,
1304+
wires_direct_not_grid_aligned,
1305+
});
12981306
responses.add(FrontendMessage::UpdateLayerWidths {
12991307
layer_widths,
13001308
chain_widths,

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

+29
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,32 @@ pub enum Direction {
200200
Left,
201201
Right,
202202
}
203+
204+
#[derive(Copy, Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize, specta::Type)]
205+
pub enum GraphWireStyle {
206+
#[default]
207+
GridAligned = 0,
208+
Direct = 1,
209+
}
210+
211+
impl std::fmt::Display for GraphWireStyle {
212+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
213+
match self {
214+
GraphWireStyle::GridAligned => write!(f, "Grid-Aligned"),
215+
GraphWireStyle::Direct => write!(f, "Direct"),
216+
}
217+
}
218+
}
219+
220+
impl GraphWireStyle {
221+
pub fn tooltip_description(&self) -> &'static str {
222+
match self {
223+
GraphWireStyle::GridAligned => "Wires follow the grid, running in straight lines between nodes",
224+
GraphWireStyle::Direct => "Wires bend to run at an angle directly between nodes",
225+
}
226+
}
227+
228+
pub fn is_direct(&self) -> bool {
229+
*self == GraphWireStyle::Direct
230+
}
231+
}

editor/src/messages/portfolio/portfolio_message_handler.rs

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
106106
persistent_data: &self.persistent_data,
107107
executor: &mut self.executor,
108108
current_tool,
109+
preferences,
109110
};
110111
document.process_message(message, responses, document_inputs)
111112
}
@@ -121,6 +122,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
121122
persistent_data: &self.persistent_data,
122123
executor: &mut self.executor,
123124
current_tool,
125+
preferences,
124126
};
125127
document.process_message(message, responses, document_inputs)
126128
}

editor/src/messages/preferences/preferences_message.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::messages::portfolio::document::node_graph::utility_types::GraphWireStyle;
12
use crate::messages::preferences::SelectionMode;
23
use crate::messages::prelude::*;
34

@@ -13,6 +14,7 @@ pub enum PreferencesMessage {
1314
SelectionMode { selection_mode: SelectionMode },
1415
VectorMeshes { enabled: bool },
1516
ModifyLayout { zoom_with_scroll: bool },
17+
GraphWireStyle { style: GraphWireStyle },
1618
// ImaginateRefreshFrequency { seconds: f64 },
1719
// ImaginateServerHostname { hostname: String },
1820
}

editor/src/messages/preferences/preferences_message_handler.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::messages::input_mapper::key_mapping::MappingVariant;
2+
use crate::messages::portfolio::document::node_graph::utility_types::GraphWireStyle;
23
use crate::messages::preferences::SelectionMode;
34
use crate::messages::prelude::*;
45

@@ -12,6 +13,7 @@ pub struct PreferencesMessageHandler {
1213
pub zoom_with_scroll: bool,
1314
pub use_vello: bool,
1415
pub vector_meshes: bool,
16+
pub graph_wire_style: GraphWireStyle,
1517
}
1618

1719
impl PreferencesMessageHandler {
@@ -37,13 +39,15 @@ impl Default for PreferencesMessageHandler {
3739
imaginate_hostname: host_name,
3840
use_vello,
3941
} = Default::default();
42+
4043
Self {
4144
imaginate_server_hostname: host_name,
4245
imaginate_refresh_frequency: 1.,
4346
selection_mode: SelectionMode::Touched,
4447
zoom_with_scroll: matches!(MappingVariant::default(), MappingVariant::ZoomWithScroll),
4548
use_vello,
4649
vector_meshes: false,
50+
graph_wire_style: GraphWireStyle::default(),
4751
}
4852
}
4953
}
@@ -95,6 +99,10 @@ impl MessageHandler<PreferencesMessage, ()> for PreferencesMessageHandler {
9599
PreferencesMessage::SelectionMode { selection_mode } => {
96100
self.selection_mode = selection_mode;
97101
}
102+
PreferencesMessage::GraphWireStyle { style } => {
103+
self.graph_wire_style = style;
104+
responses.add(NodeGraphMessage::SendGraph);
105+
}
98106
}
99107
// TODO: Reenable when Imaginate is restored (and move back up one line since the auto-formatter doesn't like it in that block)
100108
// PreferencesMessage::ImaginateRefreshFrequency { seconds } => {

0 commit comments

Comments
 (0)