Skip to content

Commit 9907a38

Browse files
committed
transcribe 0hypercube's frontend help code
1 parent a932eae commit 9907a38

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

editor/src/messages/frontend/frontend_message.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -152,6 +152,22 @@ pub struct BoxSelection {
152152
pub end_y: u32,
153153
}
154154

155+
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
156+
pub struct LasooSelection {
157+
pub points: String,
158+
}
159+
160+
impl FromIterator<glam::DVec2> for LasooSelection {
161+
fn from_iter<I: IntoIterator<Item = glam::DVec2>>(iter: I) -> Self {
162+
let mut points = String::new();
163+
for coordinate in iter {
164+
use std::fmt::Write;
165+
write!(&mut points, "{},{} ", coordinate.x, coordinate.y).unwrap();
166+
}
167+
LasooSelection { points }
168+
}
169+
}
170+
155171
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
156172
#[serde(tag = "type", content = "data")]
157173
pub enum ContextMenuData {

frontend/src/components/views/Graph.svelte

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,12 @@
777777
></div>
778778
{/if}
779779

780+
{#if $nodeGraph.lasoo}
781+
<svg class="lasoo-selection" style:clip-path={`polygon(${$nodeGraph.lasoo.points})`}>
782+
<polygon points={$nodeGraph.lasoo.points} stroke="#00a8ff" stroke-width="1px" fill="rgba(0, 168, 255, 0.05)" />
783+
</svg>
784+
{/if}
785+
780786
<style lang="scss" global>
781787
.graph {
782788
position: relative;
@@ -1369,4 +1375,14 @@
13691375
background: rgba(0, 168, 255, 0.05);
13701376
border: 1px solid #00a8ff;
13711377
}
1378+
1379+
.lasoo-selection {
1380+
position: absolute;
1381+
pointer-events: none;
1382+
z-index: 2;
1383+
top: 0;
1384+
left: 0;
1385+
width: 100%;
1386+
height: 100%;
1387+
}
13721388
</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
}
@@ -154,6 +158,10 @@ export class Box {
154158
readonly endY!: number;
155159
}
156160

161+
export class Lasoo {
162+
readonly points!: string;
163+
}
164+
157165
export type FrontendClickTargets = {
158166
readonly nodeClickTargets: string[];
159167
readonly layerClickTargets: string[];
@@ -1665,6 +1673,7 @@ export const messageMakers: Record<string, MessageMaker> = {
16651673
TriggerVisitLink,
16661674
UpdateActiveDocument,
16671675
UpdateBox,
1676+
UpdateLasoo,
16681677
UpdateClickTargets,
16691678
UpdateContextMenuInformation,
16701679
UpdateDialogButtons,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type Editor } from "@graphite/editor";
44
import type { NodeGraphError } from "@graphite/messages";
55
import {
66
type Box,
7+
type Lasoo,
78
type FrontendClickTargets,
89
type ContextMenuInformation,
910
type FrontendNode,
@@ -12,6 +13,7 @@ import {
1213
ClearAllNodeGraphWires,
1314
SendUIMetadata,
1415
UpdateBox,
16+
UpdateLasoo,
1517
UpdateClickTargets,
1618
UpdateContextMenuInformation,
1719
UpdateInSelectedNetwork,
@@ -32,6 +34,7 @@ import {
3234
export function createNodeGraphState(editor: Editor) {
3335
const { subscribe, update } = writable({
3436
box: undefined as Box | undefined,
37+
lasoo: undefined as Lasoo | undefined,
3538
clickTargets: undefined as FrontendClickTargets | undefined,
3639
contextMenuInformation: undefined as ContextMenuInformation | undefined,
3740
error: undefined as NodeGraphError | undefined,
@@ -68,6 +71,12 @@ export function createNodeGraphState(editor: Editor) {
6871
return state;
6972
});
7073
});
74+
editor.subscriptions.subscribeJsMessage(UpdateLasoo, (updateLasoo) => {
75+
update((state) => {
76+
state.lasoo = updateLasoo.lasoo;
77+
return state;
78+
});
79+
});
7180
editor.subscriptions.subscribeJsMessage(UpdateClickTargets, (UpdateClickTargets) => {
7281
update((state) => {
7382
state.clickTargets = UpdateClickTargets.clickTargets;

0 commit comments

Comments
 (0)