camera.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { PluginCommands } from 'mol-plugin/command';
  7. import * as React from 'react';
  8. import { PluginUIComponent } from './base';
  9. import { ParamDefinition as PD } from 'mol-util/param-definition';
  10. import { ParameterControls } from './controls/parameters';
  11. import { Icon } from './controls/common';
  12. export class CameraSnapshots extends PluginUIComponent<{ }, { }> {
  13. render() {
  14. return <div>
  15. <div className='msp-section-header'><Icon name='code' /> Camera Snapshots</div>
  16. <CameraSnapshotControls />
  17. <CameraSnapshotList />
  18. </div>;
  19. }
  20. }
  21. class CameraSnapshotControls extends PluginUIComponent<{ }, { name: string, description: string }> {
  22. static Params = {
  23. name: PD.Text(),
  24. description: PD.Text()
  25. }
  26. state = PD.getDefaultValues(CameraSnapshotControls.Params);
  27. add = () => {
  28. PluginCommands.Camera.Snapshots.Add.dispatch(this.plugin, this.state);
  29. this.setState({ name: '', description: '' })
  30. }
  31. clear = () => {
  32. PluginCommands.Camera.Snapshots.Clear.dispatch(this.plugin, {});
  33. }
  34. render() {
  35. return <div>
  36. <ParameterControls params={CameraSnapshotControls.Params} values={this.state} onEnter={this.add} onChange={p => this.setState({ [p.name]: p.value } as any)} />
  37. <div className='msp-btn-row-group'>
  38. <button className='msp-btn msp-btn-block msp-form-control' onClick={this.add}>Add</button>
  39. <button className='msp-btn msp-btn-block msp-form-control' onClick={this.clear}>Clear</button>
  40. </div>
  41. </div>;
  42. }
  43. }
  44. class CameraSnapshotList extends PluginUIComponent<{ }, { }> {
  45. componentDidMount() {
  46. this.subscribe(this.plugin.events.state.cameraSnapshots.changed, () => this.forceUpdate());
  47. }
  48. apply(id: string) {
  49. return () => PluginCommands.Camera.Snapshots.Apply.dispatch(this.plugin, { id });
  50. }
  51. remove(id: string) {
  52. return () => {
  53. PluginCommands.Camera.Snapshots.Remove.dispatch(this.plugin, { id });
  54. }
  55. }
  56. render() {
  57. return <ul style={{ listStyle: 'none' }} className='msp-state-list'>
  58. {this.plugin.state.cameraSnapshots.state.entries.valueSeq().map(e =><li key={e!.id}>
  59. <button className='msp-btn msp-btn-block msp-form-control' onClick={this.apply(e!.id)}>{e!.name || e!.timestamp} <small>{e!.description}</small></button>
  60. <button onClick={this.remove(e!.id)} className='msp-btn msp-btn-link msp-state-list-remove-button'>
  61. <span className='msp-icon msp-icon-remove' />
  62. </button>
  63. </li>)}
  64. </ul>;
  65. }
  66. }