Skip to content

Commit 55a9b1b

Browse files
Merge pull request #94 from BabylonJS/feature/graph-context-menu
Feature/graph context menu
2 parents f3f1da0 + f8742ba commit 55a9b1b

File tree

5 files changed

+293
-15
lines changed

5 files changed

+293
-15
lines changed

babylonjs-editor.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,8 @@ declare module 'babylonjs-editor/editor/gui/tree' {
818818
}
819819
export default class Tree {
820820
name: string;
821+
wholerow: boolean;
822+
keyboard: boolean;
821823
element: JSTree;
822824
onClick: <T>(id: string, data: T) => void;
823825
onDblClick: <T>(id: string, data: T) => void;

src/editor/gui/edition.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,30 @@ export default class Edition {
146146
};
147147

148148
const folder = parent.addFolder(name);
149-
/*
150-
TODO: Fix CSS Issue with color element
151-
folder.addColor(target, 'color').name('Color').onChange((value: number[]) => {
152-
this.getController('r', folder).setValue(value[0] / 255);
153-
this.getController('g', folder).setValue(value[1] / 255);
154-
this.getController('b', folder).setValue(value[2] / 255);
155-
});
156-
*/
149+
const picker = {
150+
callback: () => {
151+
const input = document.createElement('input');
152+
input.type = 'color';
153+
input.value = color.toHexString();
154+
input.addEventListener('input', ev => {
155+
const result = Color3.FromHexString(input.value);
156+
color.r = result.r;
157+
color.g = result.g;
158+
color.b = result.b;
159+
this.updateDisplay();
160+
});
161+
input.addEventListener('change', ev => {
162+
const result = Color3.FromHexString(input.value);
163+
color.r = result.r;
164+
color.g = result.g;
165+
color.b = result.b;
166+
this.updateDisplay();
167+
});
168+
input.click();
169+
}
170+
};
171+
172+
folder.add(picker, 'callback').name('Color Picker');
157173
folder.add(color, 'r').min(0).max(1).step(0.01).onChange(() => callback && callback());
158174
folder.add(color, 'g').min(0).max(1).step(0.01).onChange(() => callback && callback());
159175
folder.add(color, 'b').min(0).max(1).step(0.01).onChange(() => callback && callback());

src/editor/gui/tree.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface ContextMenuItem {
2020
export default class Tree {
2121
// Public members
2222
public name: string;
23+
public wholerow: boolean = false;
24+
public keyboard: boolean = false;
2325
public element: JSTree = null;
2426

2527
public onClick: <T>(id: string, data: T) => void;
@@ -166,6 +168,17 @@ export default class Tree {
166168
* @param parentId the parent id
167169
*/
168170
public build (parentId: string): void {
171+
const plugins = [
172+
'contextmenu', 'dnd', 'search',
173+
'state', 'types'
174+
];
175+
176+
if (this.wholerow)
177+
plugins.push('wholerow')
178+
179+
if (this.keyboard)
180+
plugins.push('hotkeys');
181+
169182
this.element = $('#' + parentId).jstree({
170183
core: {
171184
check_callback: true,
@@ -178,10 +191,7 @@ export default class Tree {
178191
return this.onCanDrag && this.onCanDrag(node.id, node.data);
179192
}
180193
},
181-
plugins: [
182-
'contextmenu', 'dnd', 'search',
183-
'state', 'types'
184-
],
194+
plugins: plugins,
185195
search: {
186196
show_only_matches: true,
187197
show_only_matches_children: true

src/extensions/behavior/graph-nodes/typings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ export abstract class LiteGraphNode {
77
public mode: number;
88
public color: string;
99
public bgColor: string;
10+
public readonly type: string;
11+
1012
public properties: { [index: string]: string | number | boolean };
13+
public outputs: any[];
1114

15+
public pos: number[];
1216
public size: number[] = [60, 20];
1317
public shape: string = 'round';
1418

@@ -83,6 +87,9 @@ export abstract class LiteGraphNode {
8387

8488
public onDrawBackground? (ctx: CanvasRenderingContext2D): void;
8589

90+
public onGetOutputs? (): string[][];
91+
public onGetInputs? (): string[][];
92+
8693
/**
8794
* Returns the target node
8895
* @param name the name of the node

0 commit comments

Comments
 (0)