File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -337,6 +337,9 @@ UI.FloatNumber = function ( position ) {
337
337
this . dom . style . fontSize = '12px' ;
338
338
this . dom . style . textDecoration = 'underline' ;
339
339
340
+ this . min = - Infinity ;
341
+ this . max = Infinity ;
342
+
340
343
this . onChangeCallback = null ;
341
344
342
345
var scope = this ;
@@ -357,10 +360,12 @@ UI.FloatNumber = function ( position ) {
357
360
358
361
var onMouseMove = function ( event ) {
359
362
360
- var dx = event . screenX - onMouseDownScreenX ;
361
- var dy = event . screenY - onMouseDownScreenY ;
363
+ var distance = ( event . screenX - onMouseDownScreenX ) - ( event . screenY - onMouseDownScreenY ) ;
364
+ var amount = event . shiftKey ? 10 : 100 ;
365
+
366
+ var number = onMouseDownValue + ( distance / amount ) ;
362
367
363
- scope . dom . textContent = ( onMouseDownValue + ( dx - dy ) / ( event . shiftKey ? 10 : 100 ) ) . toFixed ( 2 ) ;
368
+ scope . dom . textContent = Math . min ( scope . max , Math . max ( scope . min , number ) ) . toFixed ( 2 ) ;
364
369
scope . onChangeCallback ( ) ;
365
370
366
371
}
@@ -394,6 +399,20 @@ UI.FloatNumber.prototype.setValue = function ( value ) {
394
399
395
400
} ;
396
401
402
+ UI . FloatNumber . prototype . setMin = function ( value ) {
403
+
404
+ this . min = value ;
405
+ return this ;
406
+
407
+ } ;
408
+
409
+ UI . FloatNumber . prototype . setMax = function ( value ) {
410
+
411
+ this . max = value ;
412
+ return this ;
413
+
414
+ } ;
415
+
397
416
UI . FloatNumber . prototype . onChange = function ( callback ) {
398
417
399
418
this . onChangeCallback = callback ;
Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ Sidebar.Properties.Material = function ( signals ) {
27
27
container . add ( new UI . HorizontalRule ( ) ) ;
28
28
29
29
container . add ( new UI . Text ( ) . setText ( 'Opacity' ) . setColor ( '#666' ) ) ;
30
- var materialOpacity = new UI . FloatNumber ( 'absolute' ) . setLeft ( '90px' ) . setFontSize ( '12px' ) . onChange ( update ) ;
30
+ var materialOpacity = new UI . FloatNumber ( 'absolute' ) . setLeft ( '90px' ) . setFontSize ( '12px' ) ;
31
+ materialOpacity . setMin ( 0 ) . setMax ( 1 ) ;
32
+ materialOpacity . onChange ( update ) ;
31
33
container . add ( materialOpacity ) ;
32
34
container . add ( new UI . HorizontalRule ( ) ) ;
33
35
You can’t perform that action at this time.
0 commit comments