Skip to content

Commit a2ec8e2

Browse files
committed
fix(View): support user-provided interactor styles
1 parent 246b8eb commit a2ec8e2

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/core/View.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export default class View extends Component {
135135

136136
if (props.interactive) {
137137
this.interactor = props.interactor;
138-
this.style = vtkInteractorStyleManipulator.newInstance();
138+
this.defaultStyle = vtkInteractorStyleManipulator.newInstance();
139+
this.style = this.defaultStyle;
139140
}
140141

141142
// Create orientation widget
@@ -192,6 +193,11 @@ export default class View extends Component {
192193
};
193194
this.debouncedCubeBounds = debounce(this.updateCubeBounds, 50);
194195

196+
this.setInteractorStyle = (style) => {
197+
this.style = style;
198+
this.interactor.setInteractorStyle(style);
199+
};
200+
195201
// Internal functions
196202
this.hasFocus = false;
197203
this.handleKey = (e) => {
@@ -413,7 +419,10 @@ export default class View extends Component {
413419

414420
this.selector.delete();
415421
this.orientationWidget.delete();
422+
this.defaultStyle.delete();
416423

424+
this.defaultStyle = null;
425+
this.style = null;
417426
this.renderer = null;
418427
this.selector = null;
419428
this.orientationWidget = null;

src/core/ViewContainer.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@ class ViewController extends Component {
2222
} else {
2323
this.renderWindow = vtkRenderWindow.newInstance();
2424
this.openglRenderWindow = vtkOpenGLRenderWindow.newInstance();
25+
}
26+
27+
this.onEnter = this.onEnter.bind(this);
28+
this.onResize = this.onResize.bind(this);
29+
}
30+
31+
componentDidMount() {
32+
if (!this.props.root) {
2533
this.renderWindow.addView(this.openglRenderWindow);
2634

2735
this.interactor = vtkRenderWindowInteractor.newInstance();
28-
if (props.interactive) {
36+
if (this.props.interactive) {
2937
this.interactor.setView(this.openglRenderWindow);
3038
this.interactor.initialize();
3139
}
32-
// this.interactor.setInteractorStyle(this.style);
3340
}
34-
3541
this.renderWindow.addRenderer(this.renderer);
3642

37-
this.onEnter = this.onEnter.bind(this);
38-
this.onResize = this.onResize.bind(this);
39-
}
40-
41-
componentDidMount() {
4243
const view = this.viewRef.current;
4344
const container = view.containerRef.current;
4445
container.addEventListener('pointerenter', this.onEnter);

0 commit comments

Comments
 (0)