Skip to content

Commit 27621da

Browse files
6heogoffart
authored andcommitted
In ScrollView use a single property to save reference values on mousepress.
This change was suggested in PR 9696
1 parent ad4eec2 commit 27621da

File tree

4 files changed

+27
-51
lines changed

4 files changed

+27
-51
lines changed

internal/compiler/widgets/cosmic/scrollview.slint

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,13 @@ export component ScrollBar {
4848
}
4949

5050
touch-area := TouchArea {
51-
property <length> pressed-value;
52-
property <length> saved-maximum;
53-
property <length> saved-x;
54-
property <length> saved-y;
51+
property <{pressed-value: length, maximum: length, x:length, y: length}> saved-values;
5552

5653
width: parent.width;
5754
height: parent.height;
5855

5956
function update-saved-values() {
60-
self.pressed-value = -root.value;
61-
self.saved-maximum = root.maximum;
62-
self.saved-y = self.mouse-y;
63-
self.saved-x = self.mouse-x;
57+
self.saved-values = { pressed-value: -root.value, maximum: root.maximum, x: self.mouse-x, y: self.mouse-y };
6458
}
6559

6660
pointer-event(event) => {
@@ -73,15 +67,15 @@ export component ScrollBar {
7367
if (self.enabled && self.pressed) {
7468
// Update reference points when the size of the viewport changes to
7569
// avoid 'jumping' during scrolling.
76-
// This happens when height estimate of a ListView changes, after
70+
// This happens when height estimate of a ListView changes after
7771
// new items are loaded.
78-
if (self.saved-maximum != root.maximum) {
72+
if (self.saved-values.maximum != root.maximum) {
7973
self.update-saved-values();
8074
}
8175

82-
root.value = -max(0px, min(root.maximum, self.pressed-value + (
83-
root.horizontal ? (touch-area.mouse-x - touch-area.saved-x) * (root.maximum / (root.track-size - thumb.width))
84-
: (touch-area.mouse-y - touch-area.saved-y) * (root.maximum / (root.track-size - thumb.height))
76+
root.value = -max(0px, min(root.maximum, self.saved-values.pressed-value + (
77+
root.horizontal ? (self.mouse-x - self.saved-values.x) * (root.maximum / (root.track-size - thumb.width))
78+
: (self.mouse-y - self.saved-values.y) * (root.maximum / (root.track-size - thumb.height))
8579
)));
8680
root.scrolled();
8781
}

internal/compiler/widgets/cupertino/scrollview.slint

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,13 @@ export component ScrollBar inherits Rectangle {
5656
}
5757

5858
touch-area := TouchArea {
59-
property <length> pressed-value;
60-
property <length> saved-maximum;
61-
property <length> saved-x;
62-
property <length> saved-y;
59+
property <{pressed-value: length, maximum: length, x:length, y: length}> saved-values;
6360

6461
width: parent.width;
6562
height: parent.height;
6663

6764
function update-saved-values() {
68-
self.pressed-value = -root.value;
69-
self.saved-maximum = root.maximum;
70-
self.saved-y = self.mouse-y;
71-
self.saved-x = self.mouse-x;
65+
self.saved-values = { pressed-value: -root.value, maximum: root.maximum, x: self.mouse-x, y: self.mouse-y };
7266
}
7367

7468
pointer-event(event) => {
@@ -81,15 +75,15 @@ export component ScrollBar inherits Rectangle {
8175
if (self.enabled && self.pressed) {
8276
// Update reference points when the size of the viewport changes to
8377
// avoid 'jumping' during scrolling.
84-
// This happens when height estimate of a ListView changes, after
78+
// This happens when height estimate of a ListView changes after
8579
// new items are loaded.
86-
if (self.saved-maximum != root.maximum) {
80+
if (self.saved-values.maximum != root.maximum) {
8781
self.update-saved-values();
8882
}
8983

90-
root.value = -max(0px, min(root.maximum, self.pressed-value + (
91-
root.horizontal ? (touch-area.mouse-x - touch-area.saved-x) * (root.maximum / (root.track-size - thumb.width))
92-
: (touch-area.mouse-y - touch-area.saved-y) * (root.maximum / (root.track-size - thumb.height))
84+
root.value = -max(0px, min(root.maximum, self.saved-values.pressed-value + (
85+
root.horizontal ? (self.mouse-x - self.saved-values.x) * (root.maximum / (root.track-size - thumb.width))
86+
: (self.mouse-y - self.saved-values.y) * (root.maximum / (root.track-size - thumb.height))
9387
)));
9488
root.scrolled();
9589
}

internal/compiler/widgets/fluent/scrollview.slint

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,13 @@ component ScrollBar inherits Rectangle {
7777
}
7878

7979
touch-area := TouchArea {
80-
property <length> pressed-value;
81-
property <length> saved-maximum;
82-
property <length> saved-x;
83-
property <length> saved-y;
80+
property <{pressed-value: length, maximum: length, x:length, y: length}> saved-values;
8481

8582
width: parent.width;
8683
height: parent.height;
8784

8885
function update-saved-values() {
89-
self.pressed-value = -root.value;
90-
self.saved-maximum = root.maximum;
91-
self.saved-y = self.mouse-y;
92-
self.saved-x = self.mouse-x;
86+
self.saved-values = { pressed-value: -root.value, maximum: root.maximum, x: self.mouse-x, y: self.mouse-y };
9387
}
9488

9589
pointer-event(event) => {
@@ -102,15 +96,15 @@ component ScrollBar inherits Rectangle {
10296
if (self.enabled && self.pressed) {
10397
// Update reference points when the size of the viewport changes to
10498
// avoid 'jumping' during scrolling.
105-
// This happens when height estimate of a ListView changes, after
99+
// This happens when height estimate of a ListView changes after
106100
// new items are loaded.
107-
if (self.saved-maximum != root.maximum) {
101+
if (self.saved-values.maximum != root.maximum) {
108102
self.update-saved-values();
109103
}
110104

111-
root.value = -max(0px, min(root.maximum, self.pressed-value + (
112-
root.horizontal ? (touch-area.mouse-x - touch-area.saved-x) * (root.maximum / (root.track-size - thumb.width))
113-
: (touch-area.mouse-y - touch-area.saved-y) * (root.maximum / (root.track-size - thumb.height))
105+
root.value = -max(0px, min(root.maximum, self.saved-values.pressed-value + (
106+
root.horizontal ? (self.mouse-x - self.saved-values.x) * (root.maximum / (root.track-size - thumb.width))
107+
: (self.mouse-y - self.saved-values.y) * (root.maximum / (root.track-size - thumb.height))
114108
)));
115109
root.scrolled();
116110
}

internal/compiler/widgets/material/scrollview.slint

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,13 @@ component ScrollBar inherits Rectangle {
5858
}
5959

6060
touch-area := TouchArea {
61-
property <length> pressed-value;
62-
property <length> saved-maximum;
63-
property <length> saved-x;
64-
property <length> saved-y;
61+
property <{pressed-value: length, maximum: length, x:length, y: length}> saved-values;
6562

6663
width: parent.width;
6764
height: parent.height;
6865

6966
function update-saved-values() {
70-
self.pressed-value = -root.value;
71-
self.saved-maximum = root.maximum;
72-
self.saved-y = self.mouse-y;
73-
self.saved-x = self.mouse-x;
67+
self.saved-values = { pressed-value: -root.value, maximum: root.maximum, x: self.mouse-x, y: self.mouse-y };
7468
}
7569

7670
pointer-event(event) => {
@@ -85,13 +79,13 @@ component ScrollBar inherits Rectangle {
8579
// avoid 'jumping' during scrolling.
8680
// This happens when height estimate of a ListView changes after
8781
// new items are loaded.
88-
if (self.saved-maximum != root.maximum) {
82+
if (self.saved-values.maximum != root.maximum) {
8983
self.update-saved-values();
9084
}
9185

92-
root.value = -max(0px, min(root.maximum, self.pressed-value + (
93-
root.horizontal ? (touch-area.mouse-x - touch-area.saved-x) * (root.maximum / (root.width - handle.width))
94-
: (touch-area.mouse-y - touch-area.saved-y) * (root.maximum / (root.height - handle.height))
86+
root.value = -max(0px, min(root.maximum, self.saved-values.pressed-value + (
87+
root.horizontal ? (self.mouse-x - self.saved-values.x) * (root.maximum / (root.width - handle.width))
88+
: (self.mouse-y - self.saved-values.y) * (root.maximum / (root.height - handle.height))
9589
)));
9690
root.scrolled();
9791
}

0 commit comments

Comments
 (0)