Skip to content

Commit

Permalink
feat(WidgetManager): customize cursor styles
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Mar 25, 2024
1 parent 723c19a commit 14fabed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Sources/Widgets/Core/WidgetManager/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ export interface vtkWidgetManager extends vtkObject {
* Release the focus.
*/
releaseFocus(): void;

/**
* Sets the default cursor styles.
*
* Known style keys:
* - default: when not interacting with a widget
* - hover: when hovering over a widget.
*
* If a known style key is not present, the cursor style will not be changed.
* @param {Record<string, string>} cursorStyles
*/
setCursorStyles(cursorStyles: Record<string, string>): boolean;

/**
* Retrieves the current cursor styles.
*/
getCursorStyles(): Record<string, string>;
}

export interface IWidgetManagerInitialValues {
Expand Down
22 changes: 18 additions & 4 deletions Sources/Widgets/Core/WidgetManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ function vtkWidgetManager(publicAPI, model) {
}

// Default cursor behavior
model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
const cursorStyles = publicAPI.getCursorStyles();
const style = widget ? 'hover' : 'default';
const cursor = cursorStyles[style];
if (cursor) {
model._apiSpecificRenderWindow.setCursor(cursor);
}

model.activeWidget = null;
let wantRender = false;
Expand Down Expand Up @@ -461,7 +466,7 @@ function vtkWidgetManager(publicAPI, model) {
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
const defaultValues = (initialValues = {}) => ({
// _camera: null,
// _selector: null,
// _currentUpdateSelectionCallID: null,
Expand All @@ -476,16 +481,25 @@ const DEFAULT_VALUES = {
previousSelectedData: null,
widgetInFocus: null,
captureOn: CaptureOn.MOUSE_MOVE,
};
...initialValues,

cursorStyles: initialValues.cursorStyles
? { ...initialValues.cursorStyles }
: {
default: 'default',
hover: 'pointer',
},
});

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);
Object.assign(model, defaultValues(initialValues));

macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, [
'captureOn',
'cursorStyles',
{ type: 'enum', name: 'viewType', enum: ViewTypes },
]);
macro.get(publicAPI, model, [
Expand Down

0 comments on commit 14fabed

Please sign in to comment.