Skip to content

Commit 17600ba

Browse files
authored
Slider: correct rail/track geometry to account for thumb size (#9449)
- Shift rail by half-thumb and shrink by thumb size (H/V) - Size track using thumb center (width = thumb.x, height = thumb.y) - Clamp thumb position against parent size instead of root - Visual fill now matches interaction range - Apply consistently to Cosmic, Cupertino, Fluent, Material - Note: Qt backend not updated; still misaligned
1 parent cc538ba commit 17600ba

File tree

4 files changed

+38
-32
lines changed

4 files changed

+38
-32
lines changed

internal/compiler/widgets/cosmic/slider.slint

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,26 @@ export component Slider {
3636
]
3737

3838
rail := Rectangle {
39-
width: base.vertical ? 4px : parent.width;
40-
height: base.vertical ? parent.height : 4px;
39+
x: base.vertical ? (parent.width - self.width) / 2 : thumb.width / 2;
40+
y: base.vertical ? thumb.height / 2 : (parent.height - self.height) / 2;
41+
width: base.vertical ? 4px : parent.width - thumb.width;
42+
height: base.vertical ? parent.height - thumb.height : 4px;
4143
background: CosmicPalette.neutral-6-background;
4244
border-radius: 2px;
4345
}
4446

4547
track := Rectangle {
46-
x: base.vertical ? (parent.width - self.width) / 2 : 0;
47-
y: base.vertical ? 0 : (parent.height - self.height) / 2;
48-
width: base.vertical ? rail.width : thumb.x + (thumb.width / 2);
49-
height: base.vertical ? thumb.y + (thumb.height / 2) : rail.height;
48+
x: base.vertical ? (parent.width - self.width) / 2 : thumb.width / 2;
49+
y: base.vertical ? thumb.height / 2 : (parent.height - self.height) / 2;
50+
width: base.vertical ? rail.width : thumb.x;
51+
height: base.vertical ? thumb.y : rail.height;
5052
background: CosmicPalette.secondary-accent-background;
5153
border-radius: rail.border-radius;
5254
}
5355

5456
thumb := Rectangle {
55-
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.width - self.width);
56-
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.height - self.height) : (parent.height - self.height) / 2;
57+
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.width - self.width);
58+
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.height - self.height) : (parent.height - self.height) / 2;
5759
width: 20px;
5860
height: self.width;
5961
border-radius: 10px;

internal/compiler/widgets/cupertino/slider.slint

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export component Slider {
3838
]
3939

4040
rail := Rectangle {
41-
width: base.vertical ? 4px : parent.width;
42-
height: base.vertical ? parent.height : 4px;
41+
x: base.vertical ? (parent.width - self.width) / 2 : thumb.width / 2;
42+
y: base.vertical ? thumb.height / 2 : (parent.height - self.height) / 2;
43+
width: base.vertical ? 4px : parent.width - thumb.width;
44+
height: base.vertical ? parent.height - thumb.height : 4px;
4345
background: CupertinoPalette.alternate-control-background;
4446
border-radius: 2px;
4547

@@ -51,17 +53,17 @@ export component Slider {
5153
}
5254

5355
track := Rectangle {
54-
x: base.vertical ? (parent.width - self.width) / 2 : 0;
55-
y: base.vertical ? 0 : (parent.height - self.height) / 2;
56-
width: base.vertical ? rail.width : thumb.x + (thumb.width / 2);
57-
height: base.vertical ? thumb.y + (thumb.height / 2) : rail.height;
56+
x: base.vertical ? (parent.width - self.width) / 2 : thumb.width / 2;
57+
y: base.vertical ? thumb.height / 2 : (parent.height - self.height) / 2;
58+
width: base.vertical ? rail.width : thumb.x;
59+
height: base.vertical ? thumb.y : rail.height;
5860
background: CupertinoPalette.accent-background;
5961
border-radius: rail.border-radius;
6062
}
6163

6264
thumb := Rectangle {
63-
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.width - self.width);
64-
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.height - self.height) : (parent.height - self.height) / 2;
65+
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.width - self.width);
66+
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.height - self.height) : (parent.height - self.height) / 2;
6567
width: 20px;
6668
height: self.width;
6769
border-radius: 10px;

internal/compiler/widgets/fluent/slider.slint

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,26 @@ export component Slider {
4646
]
4747

4848
rail := Rectangle {
49-
width: base.vertical ? 4px : parent.width;
50-
height: base.vertical ? parent.height : 4px;
49+
x: base.vertical ? (parent.width - self.width) / 2 : thumb.width / 2;
50+
y: base.vertical ? thumb.height / 2 : (parent.height - self.height) / 2;
51+
width: base.vertical ? 4px : parent.width - thumb.width;
52+
height: base.vertical ? parent.height - thumb.height : 4px;
5153
background: FluentPalette.border;
5254
border-radius: 2px;
5355
}
5456

5557
track := Rectangle {
56-
x: base.vertical ? (parent.width - self.width) / 2 : 0;
57-
y: base.vertical ? 0 : (parent.height - self.height) / 2;
58-
width: base.vertical ? rail.width : thumb.x + (thumb.width / 2);
59-
height: base.vertical ? thumb.y + (thumb.height / 2) : rail.height;
58+
x: base.vertical ? (parent.width - self.width) / 2 : thumb.width / 2;
59+
y: base.vertical ? thumb.height / 2 : (parent.height - self.height) / 2;
60+
width: base.vertical ? rail.width : thumb.x;
61+
height: base.vertical ? thumb.y : rail.height;
6062
background: FluentPalette.accent-background;
6163
border-radius: rail.border-radius;
6264
}
6365

6466
thumb := Rectangle {
65-
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.width - self.width);
66-
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.height - self.height) : (parent.height - self.height) / 2;
67+
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.width - self.width);
68+
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.height - self.height) : (parent.height - self.height) / 2;
6769
width: 20px;
6870
height: self.width;
6971
border-radius: 10px;

internal/compiler/widgets/material/slider.slint

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ export component Slider {
4949
background := Rectangle {
5050
background: MaterialPalette.control-background-variant;
5151
opacity: 0.38;
52-
x: (parent.width - self.width) / 2;
53-
y: (parent.height - self.height) / 2;
54-
width: base.vertical ? 4px : parent.width;
55-
height: base.vertical ? parent.height : 4px;
52+
x: base.vertical ? (parent.width - self.width) / 2 : handle.width / 2;
53+
y: base.vertical ? handle.height / 2 : (parent.height - self.height) / 2;
54+
width: base.vertical ? 4px : parent.width - handle.width;
55+
height: base.vertical ? parent.height - handle.height : 4px;
5656
border-radius: 2px;
5757
}
5858

5959
track := Rectangle {
6060
background: MaterialPalette.accent-background;
6161
x: base.vertical ? (parent.width - self.width) / 2 : background.x;
6262
y: base.vertical ? background.y : (parent.height - self.height) / 2;
63-
width: base.vertical? background.width : handle.x + (handle.width / 2);
64-
height: base.vertical? handle.y + (handle.height / 2) : background.height;
63+
width: base.vertical? background.width : handle.x;
64+
height: base.vertical? handle.y : background.height;
6565
border-radius: background.border-radius;
6666
}
6767

@@ -78,8 +78,8 @@ export component Slider {
7878
}
7979

8080
handle := Rectangle {
81-
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.width - self.width);
82-
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, root.height - self.height) : (parent.height - self.height) / 2;
81+
x: base.vertical ? (parent.width - self.width) / 2 : clamp((parent.width - self.width) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.width - self.width);
82+
y: base.vertical ? clamp((parent.height - self.height) * (root.value - root.minimum) / (root.maximum - root.minimum), 0, parent.height - self.height) : (parent.height - self.height) / 2;
8383
background: MaterialPalette.accent-background;
8484
width: base.vertical ? root.width : root.height;
8585
height: base.vertical ? root.width : root.height;

0 commit comments

Comments
 (0)