Sidebar.Controls.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @author TyLindberg / https://github.com/TyLindberg
  3. */
  4. Sidebar.Controls = function ( editor ) {
  5. var config = editor.config;
  6. var signals = editor.signals;
  7. var container = new UI.Panel();
  8. container.add( new UI.Text( 'CONTROLS' ) );
  9. // Use this to add a line break above the panel
  10. container.add( new UI.Break(), new UI.Break() );
  11. var controlNames = [
  12. 'translate',
  13. 'rotate',
  14. 'scale'
  15. ];
  16. for ( var i = 0; i < controlNames.length; i++ ) {
  17. let name = controlNames[ i ];
  18. let configName = 'controls/' + name;
  19. let controlRow = new UI.Row();
  20. let controlInput = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
  21. config.setKey( configName, controlInput.getValue()[ 0 ] );
  22. } );
  23. controlInput.dom.addEventListener( 'focus', function () {
  24. controlInput.dom.select();
  25. } );
  26. if( config.getKey( configName ) !== undefined ) {
  27. controlInput.setValue( config.getKey( configName ) );
  28. }
  29. controlInput.dom.maxLength = 1;
  30. controlRow.add( new UI.Text( name.charAt( 0 ).toUpperCase() + name.slice( 1 ) ).setWidth( '90px' ) );
  31. controlRow.add( controlInput );
  32. container.add( controlRow );
  33. }
  34. return container;
  35. };