Skip to content

Commit

Permalink
feat(UI): Add standard menu toogle icon
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jan 31, 2018
1 parent 29107a7 commit 0df5e3f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 21 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/ItkVtkImageViewer.mcss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
z-index: 100;
}

.logo {
position: absolute;
top: 5px;
right: 5px;
height: 2em;
width: 2em;
cursor: pointer;
z-index: 100;
}

.toggleButton {
position: absolute;
top: 5px;
Expand All @@ -45,6 +55,23 @@
z-index: 100;
}

.toggleButtonBrightBG {
composes: toggleButton;
}

.toggleButtonDarkBG {
position: absolute;
top: 5px;
left: 5px;
height: 1em;
width: 1em;
cursor: pointer;
z-index: 100;
composes: toggleButton;
filter: invert(100%);
-webkit-filter: invert(100%);
}

.selector {
position: absolute;
top: 5px;
Expand Down
21 changes: 12 additions & 9 deletions src/createViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,29 @@ function applyStyle(el, style) {
const proxyManager = vtkProxyManager.newInstance({ proxyConfiguration });
window.addEventListener('resize', proxyManager.resizeAllViews);

const createViewer = (rootContainer, { image, use2D, viewerState, config }) => {
const createViewer = (
rootContainer,
{ viewerConfig, image, use2D, viewerState }
) => {
userInterface.emptyContainer(rootContainer);

const container = document.createElement('div');
const defaultConfig = {
background: [0, 0, 0],
backgroundColor: [0, 0, 0],
isBackgroundDark: true,
containerStyle: STYLE_CONTAINER,
};
const renderWindowConfiguration = config || defaultConfig;
const config = viewerConfig || defaultConfig;
userInterface.emptyContainer(container);
applyStyle(
container,
renderWindowConfiguration.containerStyle || STYLE_CONTAINER
);
applyStyle(container, config.containerStyle || STYLE_CONTAINER);
rootContainer.appendChild(container);

const view = proxyManager.createProxy('Views', 'ItkVtkView');
view.setContainer(container);
view.setBackground(config.backgroundColor);
view.resize();

userInterface.createToggleUI(rootContainer);
userInterface.createToggleUI(rootContainer, config.isBackgroundDark);

let imageSource = null;
let lookupTable = null;
Expand All @@ -69,7 +71,8 @@ const createViewer = (rootContainer, { image, use2D, viewerState, config }) => {
piecewiseFunction,
representation,
dataArray,
view.getRenderWindow()
view.getRenderWindow(),
config.isBackgroundDark
);
}

Expand Down
File renamed without changes
1 change: 1 addition & 0 deletions src/icons/toggle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 24 additions & 9 deletions src/userInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import vtkURLExtract from 'vtk.js/Sources/Common/Core/URLExtract';
import vtkPiecewiseGaussianWidget from 'vtk.js/Sources/Interaction/Widgets/PiecewiseGaussianWidget';

import style from './ItkVtkImageViewer.mcss';
import toggleIcon from './toggleIcon.png';
import logoIcon from './icons/logo.png';
import toggleIcon from './icons/toggle.svg';

const domElements = {};

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

function getPreset(name) {
return vtkColorMaps.find((p) => p.Name === name);
}

function getLocalStyle(cssClasses, isBackgroundDark) {
const stylePostFix = isBackgroundDark ? 'DarkBG' : 'BrightBG';
const localStyle = {};
cssClasses.forEach((name) => {
localStyle[name] = style[`${name}${stylePostFix}`];
});
return localStyle;
}

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

function getRootContainer(container) {
Expand Down Expand Up @@ -151,7 +159,12 @@ function createUseShadowToggle(
rootContainer.appendChild(domElements.shadowContainer);
}

function createToggleUI(rootContainer) {
function createToggleUI(rootContainer, isBackgroundDark) {
const logo = new Image();
logo.src = logoIcon;
logo.setAttribute('class', style.logo);
rootContainer.appendChild(logo);

function toggleWidgetVisibility() {
if (domElements.widgetContainer.style.display === 'none') {
domElements.widgetContainer.style.display = 'block';
Expand All @@ -164,11 +177,12 @@ function createToggleUI(rootContainer) {
}
}

const toggleButton = new Image();
toggleButton.src = toggleIcon;
toggleButton.setAttribute('class', style.toggleButton);
const toggleButton = document.createElement('div');
const localStyle = getLocalStyle(['toggleButton'], isBackgroundDark);
toggleButton.innerHTML = `<div class="${
localStyle.toggleButton
}">${toggleIcon}</div>`;
toggleButton.addEventListener('click', toggleWidgetVisibility);

rootContainer.appendChild(toggleButton);
}

Expand All @@ -178,7 +192,8 @@ function createVolumeUI(
piecewiseFunctionProxy,
volumeRepresentation,
dataArray,
renderWindow
renderWindow,
isBackgroundDark
) {
const rootContainer = getRootContainer(container);

Expand Down

0 comments on commit 0df5e3f

Please sign in to comment.