Skip to content
Snippets Groups Projects
Commit 3f93eb11 authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: custom plugin controls

parent c2a76efa
No related branches found
No related tags found
No related merge requests found
...@@ -26,9 +26,11 @@ class BasicWrapper { ...@@ -26,9 +26,11 @@ class BasicWrapper {
init(target: string | HTMLElement) { init(target: string | HTMLElement) {
this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target)! : target, { this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target)! : target, {
...DefaultPluginSpec, ...DefaultPluginSpec,
initialLayout: { layout: {
isExpanded: false, initial: {
showControls: false isExpanded: false,
showControls: false
}
} }
}); });
......
/** /**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
*/ */
...@@ -10,8 +10,10 @@ require('mol-plugin/skin/light.scss') ...@@ -10,8 +10,10 @@ require('mol-plugin/skin/light.scss')
createPlugin(document.getElementById('app')!, { createPlugin(document.getElementById('app')!, {
...DefaultPluginSpec, ...DefaultPluginSpec,
initialLayout: { layout: {
isExpanded: true, initial: {
showControls: true isExpanded: true,
showControls: true
}
} }
}); });
\ No newline at end of file
...@@ -17,6 +17,7 @@ import { StateBuilder, StateObject } from 'mol-state'; ...@@ -17,6 +17,7 @@ import { StateBuilder, StateObject } from 'mol-state';
import { EvolutionaryConservation } from './annotation'; import { EvolutionaryConservation } from './annotation';
import { LoadParams, SupportedFormats, RepresentationStyle, ModelInfo } from './helpers'; import { LoadParams, SupportedFormats, RepresentationStyle, ModelInfo } from './helpers';
import { RxEventHelper } from 'mol-util/rx-event-helper'; import { RxEventHelper } from 'mol-util/rx-event-helper';
import { ControlsWrapper } from './ui/controls';
require('mol-plugin/skin/light.scss') require('mol-plugin/skin/light.scss')
class MolStarProteopediaWrapper { class MolStarProteopediaWrapper {
...@@ -33,9 +34,14 @@ class MolStarProteopediaWrapper { ...@@ -33,9 +34,14 @@ class MolStarProteopediaWrapper {
init(target: string | HTMLElement) { init(target: string | HTMLElement) {
this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target)! : target, { this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target)! : target, {
...DefaultPluginSpec, ...DefaultPluginSpec,
initialLayout: { layout: {
isExpanded: false, initial: {
showControls: false isExpanded: false,
showControls: false
},
controls: {
right: ControlsWrapper
}
} }
}); });
......
/**
* Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import * as React from 'react';
import { PluginUIComponent } from 'mol-plugin/ui/base';
import { CurrentObject } from 'mol-plugin/ui/plugin';
import { AnimationControls } from 'mol-plugin/ui/state/animation';
import { CameraSnapshots } from 'mol-plugin/ui/camera';
export class ControlsWrapper extends PluginUIComponent {
render() {
return <div className='msp-scrollable-container msp-right-controls'>
<CurrentObject />
<AnimationControls />
<CameraSnapshots />
</div>;
}
}
\ No newline at end of file
...@@ -99,7 +99,7 @@ export class PluginContext { ...@@ -99,7 +99,7 @@ export class PluginContext {
initViewer(canvas: HTMLCanvasElement, container: HTMLDivElement) { initViewer(canvas: HTMLCanvasElement, container: HTMLDivElement) {
try { try {
this.layout.setRoot(container); this.layout.setRoot(container);
if (this.spec.initialLayout) this.layout.setProps(this.spec.initialLayout); if (this.spec.layout && this.spec.layout.initial) this.layout.setProps(this.spec.layout.initial);
(this.canvas3d as Canvas3D) = Canvas3D.create(canvas, container); (this.canvas3d as Canvas3D) = Canvas3D.create(canvas, container);
PluginCommands.Canvas3D.SetSettings.dispatch(this, { settings: { backgroundColor: Color(0xFCFBF9) } }); PluginCommands.Canvas3D.SetSettings.dispatch(this, { settings: { backgroundColor: Color(0xFCFBF9) } });
this.canvas3d.animate(); this.canvas3d.animate();
......
...@@ -176,7 +176,7 @@ export class PluginLayout extends PluginComponent<PluginLayoutStateProps> { ...@@ -176,7 +176,7 @@ export class PluginLayout extends PluginComponent<PluginLayoutStateProps> {
} }
constructor(private context: PluginContext) { constructor(private context: PluginContext) {
super({ ...PD.getDefaultValues(PluginLayoutStateParams), ...context.spec.initialLayout }); super({ ...PD.getDefaultValues(PluginLayoutStateParams), ...(context.spec.layout && context.spec.layout.initial) });
PluginCommands.Layout.Update.subscribe(context, e => this.updateProps(e.state)); PluginCommands.Layout.Update.subscribe(context, e => this.updateProps(e.state));
......
...@@ -16,7 +16,14 @@ interface PluginSpec { ...@@ -16,7 +16,14 @@ interface PluginSpec {
behaviors: PluginSpec.Behavior[], behaviors: PluginSpec.Behavior[],
animations?: PluginStateAnimation[], animations?: PluginStateAnimation[],
customParamEditors?: [StateAction | StateTransformer, StateTransformParameters.Class][], customParamEditors?: [StateAction | StateTransformer, StateTransformParameters.Class][],
initialLayout?: PluginLayoutStateProps layout?: {
initial?: PluginLayoutStateProps,
controls?: {
left?: React.ComponentClass | 'none',
right?: React.ComponentClass | 'none',
bottom?: React.ComponentClass | 'none'
}
}
} }
namespace PluginSpec { namespace PluginSpec {
...@@ -38,4 +45,10 @@ namespace PluginSpec { ...@@ -38,4 +45,10 @@ namespace PluginSpec {
export function Behavior<T extends StateTransformer>(transformer: T, defaultParams?: StateTransformer.Params<T>): Behavior { export function Behavior<T extends StateTransformer>(transformer: T, defaultParams?: StateTransformer.Params<T>): Behavior {
return { transformer, defaultParams }; return { transformer, defaultParams };
} }
export interface LayoutControls {
left?: React.ComponentClass | 'none',
right?: React.ComponentClass | 'none',
bottom?: React.ComponentClass | 'none'
}
} }
\ No newline at end of file
...@@ -43,35 +43,44 @@ class Layout extends PluginUIComponent { ...@@ -43,35 +43,44 @@ class Layout extends PluginUIComponent {
this.subscribe(this.plugin.layout.events.updated, () => this.forceUpdate()); this.subscribe(this.plugin.layout.events.updated, () => this.forceUpdate());
} }
region(kind: 'left' | 'right' | 'bottom' | 'main', element: JSX.Element) { region(kind: 'left' | 'right' | 'bottom' | 'main', Element: React.ComponentClass) {
return <div className={`msp-layout-region msp-layout-${kind}`}> return <div className={`msp-layout-region msp-layout-${kind}`}>
<div className='msp-layout-static'> <div className='msp-layout-static'>
{element} <Element />
</div> </div>
</div>; </div>;
} }
render() { render() {
const layout = this.plugin.layout.state; const layout = this.plugin.layout.state;
const spec = this.plugin.spec.layout && this.plugin.spec.layout.controls;
return <div className='msp-plugin'> return <div className='msp-plugin'>
<div className={`msp-plugin-content ${layout.isExpanded ? 'msp-layout-expanded' : 'msp-layout-standard msp-layout-standard-outside'}`}> <div className={`msp-plugin-content ${layout.isExpanded ? 'msp-layout-expanded' : 'msp-layout-standard msp-layout-standard-outside'}`}>
<div className={layout.showControls ? 'msp-layout-hide-top' : 'msp-layout-hide-top msp-layout-hide-right msp-layout-hide-bottom msp-layout-hide-left'}> <div className={layout.showControls ? 'msp-layout-hide-top' : 'msp-layout-hide-top msp-layout-hide-right msp-layout-hide-bottom msp-layout-hide-left'}>
{this.region('main', <ViewportWrapper />)} {this.region('main', ViewportWrapper)}
{layout.showControls && this.region('left', <State />)} {layout.showControls && spec && spec.left !== 'none' && this.region('left', (spec && spec.left) || State)}
{layout.showControls && this.region('right', <div className='msp-scrollable-container msp-right-controls'> {layout.showControls && spec && spec.right !== 'none' && this.region('right', (spec && spec.right) || ControlsWrapper)}
<CurrentObject /> {layout.showControls && spec && spec.bottom !== 'none' && this.region('bottom', (spec && spec.bottom) || Log)}
<AnimationControls />
<CameraSnapshots />
<StateSnapshots />
</div>)}
{layout.showControls && this.region('bottom', <Log />)}
</div> </div>
</div> </div>
</div>; </div>;
} }
} }
export class ViewportWrapper extends PluginUIComponent {
export class ControlsWrapper extends PluginUIComponent {
render() {
return <div className='msp-scrollable-container msp-right-controls'>
<CurrentObject />
<AnimationControls />
<CameraSnapshots />
<StateSnapshots />
</div>;
}
}
export class ViewportWrapper extends PluginUIComponent {
render() { render() {
return <> return <>
<Viewport /> <Viewport />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment