Skip to content

Commit

Permalink
feat(createViewer): Add toggle UI collapsed observer
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jul 29, 2018
1 parent 528f362 commit 27b7db3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/createViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,34 @@ const createViewer = (
transferFunctionWidget.setDataArray(image.getPointData().getScalars());
}

const toggleUserInterfaceButton = document.getElementById(`${viewerDOMId}-toggleUserInterfaceButton`);

publicAPI.setUserInterfaceCollapsed = (collapse) => {
const toggleUserInterfaceButton = document.getElementById(`${viewerDOMId}-toggleUserInterfaceButton`);
const collapsed = toggleUserInterfaceButton.getAttribute('collapsed') === '';
if (collapse && !collapsed || !collapse && collapsed) {
toggleUserInterfaceButton.click();
}
}

const toggleUserInterfaceCollapsedHandlers = [];
const toggleUserInterfaceButtonListener = (event) => {
const collapsed = toggleUserInterfaceButton.getAttribute('collapsed') === '';
toggleUserInterfaceCollapsedHandlers.forEach((handler) => {
handler.call(null, collapsed);
})
}
toggleUserInterfaceButton.addEventListener('click', toggleUserInterfaceButtonListener)

publicAPI.subscribeToggleUserInterfaceCollapsed = (handler) => {
const index = toggleUserInterfaceCollapsedHandlers.length;
toggleUserInterfaceCollapsedHandlers.push(handler);
function unsubscribe() {
toggleUserInterfaceCollapsedHandlers[index] = null;
}
return Object.freeze({ unsubscribe });
}


let annotationsEnabled = true;
publicAPI.setAnnotationsEnabled = (annotations) => {
const toggleAnnotationButton = document.getElementById(`${viewerDOMId}-toggleAnnotationButton`);
Expand Down
1 change: 0 additions & 1 deletion src/userInterface/createMainUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import getContrastSensitiveStyle from './getContrastSensitiveStyle';

import style from './ItkVtkImageViewer.mcss';

import preventDefaults from './preventDefaults';
import toggleIcon from './icons/toggle.svg';
import screenshotIcon from './icons/screenshot.svg';
import volumeRenderingIcon from './icons/volume-rendering.svg';
Expand Down

0 comments on commit 27b7db3

Please sign in to comment.