Skip to content

Commit 279890c

Browse files
committed
position gl camera via new cameramodifiers
1 parent 0acb1bf commit 279890c

File tree

6 files changed

+49
-8
lines changed

6 files changed

+49
-8
lines changed

apps/vps-web/src/main.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ if (url.pathname === '/run-flow') {
126126
examplePage();
127127
} else if (url.pathname === '/gl') {
128128
import('./app/gl-app.element').then((module) => {
129-
new module.GLAppElement('#app-root');
129+
new module.GLAppElement('#app-root', undefined, undefined, undefined, {
130+
xOffset: 20,
131+
yOffset: 20,
132+
widthSubtract: 40,
133+
heightSubtract: 40,
134+
});
130135
});
131136
} else if (url.pathname === '/ocwg' || url.pathname === '/ocif') {
132137
ocwgPage();

libs/app-canvas/src/app/app.element.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export class AppElement<T extends BaseNodeInfo, TFlowEngine = unknown> {
163163
{
164164
hasNodeTypeSideBar: options?.hasNodeTypeSideBar,
165165
nodeTypeSideBarSelector: options?.nodeTypeSideBarSelector,
166+
cameraModifiers: options?.cameraModifiers,
166167
}
167168
);
168169
this.canvas = canvasApp.canvas;

libs/app-canvas/src/app/gl-app.element.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import { exportTldraw } from './exporters/export-tldraw';
104104
import { downloadFile } from './utils/create-download-link';
105105
import { StorageProvider } from './storage/StorageProvider';
106106
import { mandelbrotFlow } from './default-flows/mandelbrot-flow';
107+
import { CameraModifiers } from './interfaces/app-flow-options';
107108

108109
const defaultGLFlowId = 'gl';
109110

@@ -154,7 +155,8 @@ export class GLAppElement extends AppElement<GLNodeInfo> {
154155
appRootSelector: string,
155156
storageProvider?: StorageProvider<GLNodeInfo>,
156157
heightSpaceForHeaderFooterToolbars?: number,
157-
widthSpaceForSideToobars?: number
158+
widthSpaceForSideToobars?: number,
159+
cameraModifiers?: CameraModifiers
158160
) {
159161
const template = document.createElement('template');
160162
template.innerHTML = `<div>
@@ -171,7 +173,10 @@ export class GLAppElement extends AppElement<GLNodeInfo> {
171173
undefined,
172174
heightSpaceForHeaderFooterToolbars,
173175
widthSpaceForSideToobars,
174-
getGLNodeTaskFactory
176+
getGLNodeTaskFactory,
177+
{
178+
cameraModifiers: cameraModifiers,
179+
}
175180
);
176181

177182
if (!this.rootElement) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
export interface APPFlowOptions {
22
hasNodeTypeSideBar?: boolean;
33
nodeTypeSideBarSelector?: string;
4+
cameraModifiers?: CameraModifiers;
5+
}
6+
7+
export interface CameraModifiers {
8+
xOffset: number;
9+
yOffset: number;
10+
widthSubtract?: number;
11+
heightSubtract?: number;
412
}

libs/visual-programming-system/src/canvas-app/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ export class FlowCanvas<T extends BaseNodeInfo, TFlowEngine = unknown>
189189
public getRootFlowCanvas = () => this.rootFlowCanvas;
190190

191191
private canvasAttributes: Map<string, string> = new Map();
192-
192+
private cameraModifiers?: {
193+
xOffset: number;
194+
yOffset: number;
195+
widthSubtract?: number;
196+
heightSubtract?: number;
197+
} = undefined;
193198
constructor(
194199
rootElement: HTMLElement,
195200
disableInteraction?: boolean,
@@ -219,6 +224,7 @@ export class FlowCanvas<T extends BaseNodeInfo, TFlowEngine = unknown>
219224
this.rootFlowCanvas = rootFlowCanvas;
220225
this.isNodeContainer = isNodeContainer ?? false;
221226
this.disableInteraction = disableInteraction ?? false;
227+
this.cameraModifiers = options?.cameraModifiers;
222228

223229
this.heightSpaceForHeaderFooterToolbars =
224230
heightSpaceForHeaderFooterToolbars;
@@ -1301,8 +1307,12 @@ export class FlowCanvas<T extends BaseNodeInfo, TFlowEngine = unknown>
13011307
if (this.hasNodeTypeSideBar) {
13021308
offsetNodesidebar = 280;
13031309
}
1304-
const width = maxX - minX + (120 + offsetNodesidebar) / helperScale;
1305-
const height = maxY - minY + 240 / helperScaleHeight;
1310+
const widhtModifier = this.cameraModifiers?.widthSubtract ?? 120;
1311+
const heightModifier = this.cameraModifiers?.heightSubtract ?? 240;
1312+
1313+
const width =
1314+
maxX - minX + (widhtModifier + offsetNodesidebar) / helperScale;
1315+
const height = maxY - minY + heightModifier / helperScaleHeight;
13061316

13071317
let scale = rootWidth / width;
13081318
const scaleX = scale;
@@ -1344,9 +1354,15 @@ export class FlowCanvas<T extends BaseNodeInfo, TFlowEngine = unknown>
13441354
// const boudingBoxCorrectionY =
13451355
// -boundingBox.y - (heightSpaceForHeaderFooterToolbars ?? 0); // 100; //-150 //-boundingBox.y; // -500; //boundingBox.y;
13461356

1347-
const boudingBoxCorrectionX = -(this.widthSpaceForSideToobars ?? 0); // 32; //-230; //-boundingBox.x; // 400; //;
1357+
const boudingBoxCorrectionX = -(
1358+
this.widthSpaceForSideToobars ??
1359+
this.cameraModifiers?.xOffset ??
1360+
0
1361+
); // 32; //-230; //-boundingBox.x; // 400; //;
13481362
const boudingBoxCorrectionY = -(
1349-
this.heightSpaceForHeaderFooterToolbars ?? 0
1363+
this.heightSpaceForHeaderFooterToolbars ??
1364+
this.cameraModifiers?.yOffset ??
1365+
0
13501366
); // 100; //-150 //-boundingBox.y; // -500; //boundingBox.y;
13511367

13521368
let xOffsetNodesidebar = 0;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
export interface FlowCanvasOptions {
22
hasNodeTypeSideBar?: boolean;
33
nodeTypeSideBarSelector?: string;
4+
cameraModifiers?: {
5+
xOffset: number;
6+
yOffset: number;
7+
widthSubtract?: number;
8+
heightSubtract?: number;
9+
};
410
}

0 commit comments

Comments
 (0)