SVGHMI: more straightforward implementation of dragging position computation in Scrollbar + some little fix about boundaries. svghmi
authorEdouard Tisserant
Mon, 15 Feb 2021 15:46:47 +0100
branchsvghmi
changeset 3143 8388e6d4aa61
parent 3142 2637bb6a6bb0
child 3144 2af6afaccaf2
child 3145 80ebb88cf7b7
SVGHMI: more straightforward implementation of dragging position computation in Scrollbar + some little fix about boundaries.
svghmi/widget_scrollbar.ysl2
--- a/svghmi/widget_scrollbar.ysl2	Sun Feb 14 19:15:20 2021 +0100
+++ b/svghmi/widget_scrollbar.ysl2	Mon Feb 15 15:46:47 2021 +0100
@@ -12,11 +12,10 @@
         dispatch(value,oldval, index) {
             switch(index) {
                 case 0:
-                    if (Math.round(this.position) != value)
-                        this.position = value;
+                    this.position = value;
                     break;
                 case 1:
-                    this.range = value;
+                    this.range = Math.max(1,value);
                     break;
                 case 2:
                     this.size = value;
@@ -55,8 +54,8 @@
         }
 
         apply_position(position){
-            this.position = Math.max(Math.min(position, this.range), 0);
-            this.apply_hmi_value(0, Math.round(this.position));
+            this.position = Math.round(Math.max(Math.min(position, this.range), 0));
+            this.apply_hmi_value(0, this.position);
         }
 
         on_page_click(is_up){
@@ -74,6 +73,7 @@
             this.invctm = ctm.inverse();
             svg_root.addEventListener("pointerup", this.bound_drop, true);
             svg_root.addEventListener("pointermove", this.bound_drag, true);
+            this.dragpos = this.position;
         }
 
         drop(e) {
@@ -86,7 +86,8 @@
             if(pixels == 0) return;
             let point = new DOMPoint(e.movementX, e.movementY);
             let movement = point.matrixTransform(this.invctm).y;
-            this.apply_position(this.position + movement * units / pixels);
+            this.dragpos += movement * units / pixels;
+            this.apply_position(this.dragpos);
         }
     }
     ||