Skip to content

Commit f4959b9

Browse files
committed
transcribe 0hypercube's frontend help code
1 parent e721e25 commit f4959b9

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

editor/src/messages/frontend/frontend_message.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::utility_types::{DocumentDetails, MouseCursorIcon, OpenDocument};
22
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
33
use crate::messages::layout::utility_types::widget_prelude::*;
44
use crate::messages::portfolio::document::node_graph::utility_types::{
5-
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, Transform,
5+
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, LasooSelection, Transform,
66
};
77
use crate::messages::portfolio::document::utility_types::nodes::{JsRawBuffer, LayerPanelEntry, RawBuffer};
88
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
@@ -152,6 +152,10 @@ pub enum FrontendMessage {
152152
#[serde(rename = "box")]
153153
box_selection: Option<BoxSelection>,
154154
},
155+
UpdateLasoo {
156+
#[serde(rename = "lasoo")]
157+
lasoo_selection: Option<LasooSelection>,
158+
},
155159
UpdateContextMenuInformation {
156160
#[serde(rename = "contextMenuInformation")]
157161
context_menu_information: Option<ContextMenuInformation>,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ pub struct BoxSelection {
160160
pub end_y: u32,
161161
}
162162

163+
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
164+
pub struct LasooSelection {
165+
pub points: String,
166+
}
167+
168+
impl FromIterator<glam::DVec2> for LasooSelection {
169+
fn from_iter<I: IntoIterator<Item = glam::DVec2>>(iter: I) -> Self {
170+
let mut points = String::new();
171+
for coordinate in iter {
172+
use std::fmt::Write;
173+
write!(&mut points, "{},{} ", coordinate.x, coordinate.y).unwrap();
174+
}
175+
LasooSelection { points }
176+
}
177+
}
178+
163179
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
164180
pub enum ContextMenuData {
165181
ToggleLayer {

frontend/src/components/views/Graph.svelte

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,12 @@
787787
></div>
788788
{/if}
789789

790+
{#if $nodeGraph.lasoo}
791+
<svg class="lasoo-selection" style:clip-path={`polygon(${$nodeGraph.lasoo.points})`}>
792+
<polygon points={$nodeGraph.lasoo.points} stroke="#00a8ff" stroke-width="1px" fill="rgba(0, 168, 255, 0.05)" />
793+
</svg>
794+
{/if}
795+
790796
<style lang="scss" global>
791797
.graph {
792798
position: relative;
@@ -1375,4 +1381,14 @@
13751381
background: rgba(0, 168, 255, 0.05);
13761382
border: 1px solid #00a8ff;
13771383
}
1384+
1385+
.lasoo-selection {
1386+
position: absolute;
1387+
pointer-events: none;
1388+
z-index: 2;
1389+
top: 0;
1390+
left: 0;
1391+
width: 100%;
1392+
height: 100%;
1393+
}
13781394
</style>

frontend/src/messages.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export class UpdateBox extends JsMessage {
2929
readonly box!: Box | undefined;
3030
}
3131

32+
export class UpdateLasoo extends JsMessage {
33+
readonly lasoo!: Lasoo | undefined;
34+
}
35+
3236
export class UpdateClickTargets extends JsMessage {
3337
readonly clickTargets!: FrontendClickTargets | undefined;
3438
}
@@ -169,6 +173,10 @@ export class Box {
169173
readonly endY!: number;
170174
}
171175

176+
export class Lasoo {
177+
readonly points!: string;
178+
}
179+
172180
export type FrontendClickTargets = {
173181
readonly nodeClickTargets: string[];
174182
readonly layerClickTargets: string[];
@@ -1669,6 +1677,7 @@ export const messageMakers: Record<string, MessageMaker> = {
16691677
TriggerVisitLink,
16701678
UpdateActiveDocument,
16711679
UpdateBox,
1680+
UpdateLasoo,
16721681
UpdateClickTargets,
16731682
UpdateContextMenuInformation,
16741683
UpdateDialogButtons,

frontend/src/state-providers/node-graph.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { writable } from "svelte/store";
33
import { type Editor } from "@graphite/editor";
44
import {
55
type Box,
6+
type Lasoo,
67
type FrontendClickTargets,
78
type ContextMenuInformation,
89
type FrontendNode,
@@ -11,6 +12,7 @@ import {
1112
ClearAllNodeGraphWires,
1213
SendUIMetadata,
1314
UpdateBox,
15+
UpdateLasoo,
1416
UpdateClickTargets,
1517
UpdateContextMenuInformation,
1618
UpdateInSelectedNetwork,
@@ -30,6 +32,7 @@ import {
3032
export function createNodeGraphState(editor: Editor) {
3133
const { subscribe, update } = writable({
3234
box: undefined as Box | undefined,
35+
lasoo: undefined as Lasoo | undefined,
3336
clickTargets: undefined as FrontendClickTargets | undefined,
3437
contextMenuInformation: undefined as ContextMenuInformation | undefined,
3538
layerWidths: new Map<bigint, number>(),
@@ -65,6 +68,12 @@ export function createNodeGraphState(editor: Editor) {
6568
return state;
6669
});
6770
});
71+
editor.subscriptions.subscribeJsMessage(UpdateLasoo, (updateLasoo) => {
72+
update((state) => {
73+
state.lasoo = updateLasoo.lasoo;
74+
return state;
75+
});
76+
});
6877
editor.subscriptions.subscribeJsMessage(UpdateClickTargets, (UpdateClickTargets) => {
6978
update((state) => {
7079
state.clickTargets = UpdateClickTargets.clickTargets;

0 commit comments

Comments
 (0)