waft-material 0.15.0

Material Design widgets for Waft
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
//! Flutter counterpart: material_ui's `range_slider_parts.dart`.
//!
//! The range slider's shapes are abstract classes users subclass, so traits, each held as an
//! `Rc` (`RangeSliderThumbShapeRef` and the others); the mixin [`BaseRangeSliderTrackShape`]
//! is a trait with a provided body that a track's [`RangeSliderTrackShape`] method calls. A
//! parameter Dart declares optional with no default in the abstract signature is an
//! `Option`, so an implementation applies its own default as Dart's override does. A shape's
//! `paint` takes the `App`, as `slider_parts.rs` says. `RangeSlider` itself is
//! `range_slider.rs`.

use std::any::Any;
use std::fmt::{self, Debug};
use std::rc::Rc;

use waft_animation::AnyAnimation;
use waft_embedder::{
    ClipOp, Color, FillRule, Offset, Paint, PaintStyle, Path, PathBuilder, RRect, Radius, Rect,
    Size, Stroke, TextDirection, rrect_radii_elliptical,
};
use waft_foundation::App;
use waft_painting::{BorderRadius, ClipContext, PaintingBinding, TextPainter, draw_rrect};
use waft_rendering::{AnyRenderBox, PaintingContext};
use waft_widgets::WidgetStates;

use crate::colors::Colors;
use crate::slider_parts::{evaluate_color_tween, evaluate_tween};
use crate::slider_theme::{SliderThemeData, Thumb};

/// Base class for `RangeSlider` thumb shapes.
///
/// Equality is [`eq_shape`](Self::eq_shape): identity, as Dart's default `==`, unless the
/// shape overrides it.
///
/// See also:
///
///  * [`RoundRangeSliderThumbShape`] for the default `RangeSlider`'s thumb shape
///    that paints a solid circle.
///  * [`RangeSliderTickMarkShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s tick marks.
///  * [`RangeSliderTrackShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s track.
///  * [`RangeSliderValueIndicatorShape`], which can be used to create custom
///    shapes for the `RangeSlider`'s value indicator.
///  * `SliderComponentShape`, which can be used to create custom shapes for
///    the `Slider`'s thumb, overlay, and value indicator and the
///    `RangeSlider`'s overlay.
pub trait RangeSliderThumbShape: Any + Debug {
    /// Returns the preferred size of the shape, based on the given conditions.
    ///
    /// The `is_discrete` argument is true if `RangeSlider::divisions` is non-null.
    /// When true, the slider will render tick marks on top of the track.
    ///
    /// The `is_enabled` argument is false when `RangeSlider::on_changed` is null and
    /// true otherwise. When true, the slider will respond to input.
    fn get_preferred_size(&self, is_enabled: bool, is_discrete: bool) -> Size;

    /// Paints the thumb shape based on the state passed to it.
    ///
    /// The `context` argument represents the `RangeSlider`'s render box.
    ///
    /// The `center` argument is the offset for where this shape's center should be
    /// painted. This offset is relative to the origin of the `context` canvas.
    ///
    /// The `activation_animation` argument is an animation triggered when the user
    /// begins to interact with the `RangeSlider`. It reverses when the user stops
    /// interacting with the slider.
    ///
    /// The `enable_animation` argument is an animation triggered when the
    /// `RangeSlider` is enabled, and it reverses when the slider is disabled. The
    /// `RangeSlider` is enabled when `RangeSlider::on_changed` is not null. Use
    /// this to paint intermediate frames for this shape when the slider changes
    /// enabled state.
    ///
    /// The `is_discrete` argument is true if `RangeSlider::divisions` is non-null.
    /// When true, the slider will render tick marks on top of the track.
    ///
    /// The `is_enabled` argument is false when `RangeSlider::on_changed` is null and
    /// true otherwise. When true, the slider will respond to input.
    ///
    /// If the `is_on_top` argument is true, this thumb is painted on top of the
    /// other slider thumb because this thumb is the one that was most recently
    /// selected.
    ///
    /// The `slider_theme` argument is the theme assigned to the `RangeSlider` that
    /// this shape belongs to.
    ///
    /// The `text_direction` argument can be used to determine how the orientation
    /// of either slider thumb should be changed, such as drawing different
    /// shapes for the left and right thumb.
    ///
    /// The `thumb` argument is the specifier for which of the two thumbs this
    /// method should paint (start or end).
    ///
    /// The `is_pressed` argument can be used to give the selected thumb
    /// additional selected or pressed state visual feedback, such as a larger
    /// shadow.
    ///
    /// `None` is Dart's argument left out.
    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        activation_animation: AnyAnimation<f64>,
        enable_animation: AnyAnimation<f64>,
        is_discrete: Option<bool>,
        is_enabled: Option<bool>,
        is_on_top: Option<bool>,
        text_direction: Option<TextDirection>,
        slider_theme: &SliderThemeData,
        thumb: Option<Thumb>,
        is_pressed: Option<bool>,
    );

    /// Downcast support for Dart's `is` checks.
    fn as_any(&self) -> &dyn Any;

    /// Dart's `==`: identity unless a shape overrides it.
    fn eq_shape(&self, other: &dyn RangeSliderThumbShape) -> bool {
        std::ptr::eq(self.as_any(), other.as_any())
    }
}

/// What a field or parameter Dart types as `RangeSliderThumbShape` becomes.
pub type RangeSliderThumbShapeRef = Rc<dyn RangeSliderThumbShape>;

impl PartialEq for dyn RangeSliderThumbShape {
    fn eq(&self, other: &dyn RangeSliderThumbShape) -> bool {
        self.eq_shape(other)
    }
}

/// Base class for `RangeSlider` value indicator shapes.
///
/// Equality is [`eq_shape`](Self::eq_shape): identity, as Dart's default `==`, unless the
/// shape overrides it.
///
/// See also:
///
///  * `PaddleRangeSliderValueIndicatorShape` for the default `RangeSlider`'s
///    value indicator shape that paints a custom path with text in it.
///  * [`RangeSliderTickMarkShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s tick marks.
///  * [`RangeSliderThumbShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s thumb.
///  * [`RangeSliderTrackShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s track.
///  * `SliderComponentShape`, which can be used to create custom shapes for
///    the `Slider`'s thumb, overlay, and value indicator and the
///    `RangeSlider`'s overlay.
pub trait RangeSliderValueIndicatorShape: Any + Debug {
    /// Returns the preferred size of the shape, based on the given conditions.
    ///
    /// The `is_enabled` argument is false when `RangeSlider::on_changed` is null and
    /// true otherwise. When true, the slider will respond to input.
    ///
    /// The `is_discrete` argument is true if `RangeSlider::divisions` is non-null.
    /// When true, the slider will render tick marks on top of the track.
    ///
    /// The `label_painter` argument helps determine the width of the shape. It is
    /// variable width because it is derived from a formatted string.
    ///
    /// The `text_scale_factor` argument can be used to determine whether the
    /// component should paint larger or smaller, depending on whether
    /// `text_scale_factor` is greater than 1 for larger, and between 0 and 1 for
    /// smaller. It's usually computed from `MediaQueryData::text_scaler`.
    fn get_preferred_size(
        &self,
        is_enabled: bool,
        is_discrete: bool,
        label_painter: &TextPainter,
        text_scale_factor: f64,
    ) -> Size;

    /// Determines the best offset to keep this shape on the screen.
    ///
    /// Override this method when the center of the value indicator should be
    /// shifted from the vertical center of the thumb.
    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn get_horizontal_shift(
        &self,
        app: &App,
        parent_box: Option<AnyRenderBox>,
        center: Option<Offset>,
        label_painter: Option<&TextPainter>,
        activation_animation: Option<AnyAnimation<f64>>,
        text_scale_factor: Option<f64>,
        size_with_overflow: Option<Size>,
    ) -> f64 {
        let _ = (
            app,
            parent_box,
            center,
            label_painter,
            activation_animation,
            text_scale_factor,
            size_with_overflow,
        );
        0.0
    }

    /// Paints the value indicator shape based on the state passed to it.
    ///
    /// The `context` argument represents the `RangeSlider`'s render box.
    ///
    /// The `center` argument is the offset for where this shape's center should be
    /// painted. This offset is relative to the origin of the `context` canvas.
    ///
    /// The `activation_animation` argument is an animation triggered when the user
    /// begins to interact with the `RangeSlider`. It reverses when the user stops
    /// interacting with the slider.
    ///
    /// The `enable_animation` argument is an animation triggered when the
    /// `RangeSlider` is enabled, and it reverses when the slider is disabled. The
    /// `RangeSlider` is enabled when `RangeSlider::on_changed` is not null. Use
    /// this to paint intermediate frames for this shape when the slider changes
    /// enabled state.
    ///
    /// The `is_discrete` argument is true if `RangeSlider::divisions` is non-null.
    /// When true, the slider will render tick marks on top of the track.
    ///
    /// The `is_on_top` argument is the top-most value indicator between the two value
    /// indicators, which is always the indicator for the most recently selected thumb. In
    /// the default case, this is used to paint a stroke around the top indicator
    /// for better visibility between the two indicators.
    ///
    /// The `text_scale_factor` argument can be used to determine whether the
    /// component should paint larger or smaller, depending on whether
    /// `text_scale_factor` is greater than 1 for larger, and between 0 and 1 for
    /// smaller. It's usually computed from `MediaQueryData::text_scaler`.
    ///
    /// The `size_with_overflow` argument can be used to determine the bounds the
    /// drawing of the components that are outside of the regular slider bounds.
    /// It's the size of the box, whose center is aligned with the slider's
    /// bounds, that the value indicators must be drawn within. Typically, it is
    /// bigger than the slider.
    ///
    /// The `parent_box` argument is the `RenderBox` of the `RangeSlider`. Its
    /// attributes, such as size, can be used to assist in painting this shape.
    ///
    /// The `slider_theme` argument is the theme assigned to the `RangeSlider` that
    /// this shape belongs to.
    ///
    /// The `text_direction` argument can be used to determine how any extra text
    /// or graphics, besides the text painted by the `label_painter` should be
    /// positioned. The `label_painter` argument already has the `text_direction`
    /// set.
    ///
    /// The `value` argument is the current parametric value (from 0.0 to 1.0) of
    /// the slider.
    ///
    /// The `thumb` argument is the specifier for which of the two thumbs this
    /// method should paint (start or end).
    ///
    /// `None` is Dart's argument left out.
    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        activation_animation: AnyAnimation<f64>,
        enable_animation: AnyAnimation<f64>,
        is_discrete: Option<bool>,
        is_on_top: Option<bool>,
        label_painter: &mut TextPainter,
        text_scale_factor: Option<f64>,
        size_with_overflow: Option<Size>,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        text_direction: Option<TextDirection>,
        value: Option<f64>,
        thumb: Option<Thumb>,
    );

    /// Downcast support for Dart's `is` checks.
    fn as_any(&self) -> &dyn Any;

    /// Dart's `==`: identity unless a shape overrides it.
    fn eq_shape(&self, other: &dyn RangeSliderValueIndicatorShape) -> bool {
        std::ptr::eq(self.as_any(), other.as_any())
    }
}

/// What a field or parameter Dart types as `RangeSliderValueIndicatorShape` becomes.
pub type RangeSliderValueIndicatorShapeRef = Rc<dyn RangeSliderValueIndicatorShape>;

impl PartialEq for dyn RangeSliderValueIndicatorShape {
    fn eq(&self, other: &dyn RangeSliderValueIndicatorShape) -> bool {
        self.eq_shape(other)
    }
}

/// Base class for `RangeSlider` tick mark shapes.
///
/// This is a simplified version of `SliderComponentShape` with a
/// [`SliderThemeData`] passed when getting the preferred size.
///
/// Equality is [`eq_shape`](Self::eq_shape): identity, as Dart's default `==`, unless the
/// shape overrides it.
///
/// See also:
///
///  * [`RoundRangeSliderTickMarkShape`] for the default `RangeSlider`'s tick mark
///    shape that paints a solid circle.
///  * [`RangeSliderThumbShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s thumb.
///  * [`RangeSliderTrackShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s track.
///  * [`RangeSliderValueIndicatorShape`], which can be used to create custom
///    shapes for the `RangeSlider`'s value indicator.
///  * `SliderComponentShape`, which can be used to create custom shapes for
///    the `Slider`'s thumb, overlay, and value indicator and the
///    `RangeSlider`'s overlay.
pub trait RangeSliderTickMarkShape: Any + Debug {
    /// Returns the preferred size of the shape.
    ///
    /// It is used to help position the tick marks within the slider.
    ///
    /// The `slider_theme` argument is the theme assigned to the `RangeSlider` that
    /// this shape belongs to.
    ///
    /// The `is_enabled` argument is false when `RangeSlider::on_changed` is null and
    /// true otherwise. When true, the slider will respond to input. `None` is Dart's
    /// argument left out.
    fn get_preferred_size(&self, slider_theme: &SliderThemeData, is_enabled: Option<bool>) -> Size;

    /// Paints the slider track.
    ///
    /// The `context` argument represents the `RangeSlider`'s render box.
    ///
    /// The `center` argument is the offset for where this shape's center should be
    /// painted. This offset is relative to the origin of the `context` canvas.
    ///
    /// The `parent_box` argument is the `RenderBox` of the `RangeSlider`. Its
    /// attributes, such as size, can be used to assist in painting this shape.
    ///
    /// The `slider_theme` argument is the theme assigned to the `RangeSlider` that
    /// this shape belongs to.
    ///
    /// The `enable_animation` argument is an animation triggered when the
    /// `RangeSlider` is enabled, and it reverses when the slider is disabled. The
    /// `RangeSlider` is enabled when `RangeSlider::on_changed` is not null. Use
    /// this to paint intermediate frames for this shape when the slider changes
    /// enabled state.
    ///
    /// The `is_enabled` argument is false when `RangeSlider::on_changed` is null and
    /// true otherwise. When true, the slider will respond to input. `None` is Dart's
    /// argument left out.
    ///
    /// The `text_direction` argument can be used to determine how the tick marks
    /// are painted depending on whether they are on an active track segment or not.
    ///
    /// The track segment between the two thumbs is the active track segment. The
    /// track segments between the thumb and each end of the slider are the inactive
    /// track segments. In `TextDirection::Ltr`, the start of the slider is on the
    /// left, and in `TextDirection::Rtl`, the start of the slider is on the right.
    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: Option<bool>,
        text_direction: TextDirection,
    );

    /// Downcast support for Dart's `is` checks.
    fn as_any(&self) -> &dyn Any;

    /// Dart's `==`: identity unless a shape overrides it.
    fn eq_shape(&self, other: &dyn RangeSliderTickMarkShape) -> bool {
        std::ptr::eq(self.as_any(), other.as_any())
    }
}

/// What a field or parameter Dart types as `RangeSliderTickMarkShape` becomes.
pub type RangeSliderTickMarkShapeRef = Rc<dyn RangeSliderTickMarkShape>;

impl PartialEq for dyn RangeSliderTickMarkShape {
    fn eq(&self, other: &dyn RangeSliderTickMarkShape) -> bool {
        self.eq_shape(other)
    }
}

/// Base class for `RangeSlider` track shapes.
///
/// The slider's thumbs move along the track. A discrete slider's tick marks
/// are drawn after the track, but before the thumb, and are aligned with the
/// track.
///
/// The [`get_preferred_rect`](Self::get_preferred_rect) helps position the slider thumbs and
/// tick marks relative to the track.
///
/// Equality is [`eq_shape`](Self::eq_shape): identity, as Dart's default `==`, unless the
/// shape overrides it.
///
/// See also:
///
///  * [`RoundedRectRangeSliderTrackShape`] for the default `RangeSlider`'s track
///    shape that paints a stadium-like track.
///  * [`RangeSliderTickMarkShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s tick marks.
///  * [`RangeSliderThumbShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s thumb.
///  * [`RangeSliderValueIndicatorShape`], which can be used to create custom
///    shapes for the `RangeSlider`'s value indicator.
///  * `SliderComponentShape`, which can be used to create custom shapes for
///    the `Slider`'s thumb, overlay, and value indicator and the
///    `RangeSlider`'s overlay.
pub trait RangeSliderTrackShape: Any + Debug {
    /// Returns the preferred bounds of the shape.
    ///
    /// It is used to provide horizontal boundaries for the position of the
    /// thumbs, and to help position the slider thumbs and tick marks relative to
    /// the track.
    ///
    /// The `parent_box` argument can be used to help determine the preferredRect
    /// relative to attributes of the render box of the slider itself, such as
    /// size.
    ///
    /// The `offset` argument is relative to the caller's bounding box. It can be
    /// used to convert gesture coordinates from global to slider-relative
    /// coordinates; Dart's default is `Offset.zero`.
    ///
    /// The `slider_theme` argument is the theme assigned to the `RangeSlider` that
    /// this shape belongs to.
    ///
    /// The `is_enabled` argument is false when `RangeSlider::on_changed` is null and
    /// true otherwise. When true, the slider will respond to input. `None` is Dart's
    /// argument left out.
    ///
    /// The `is_discrete` argument is true if `RangeSlider::divisions` is non-null.
    /// When true, the slider will render tick marks on top of the track. `None` is
    /// Dart's argument left out.
    fn get_preferred_rect(
        &self,
        app: &App,
        parent_box: AnyRenderBox,
        offset: Offset,
        slider_theme: &SliderThemeData,
        is_enabled: Option<bool>,
        is_discrete: Option<bool>,
    ) -> Rect;

    /// Paints the track shape based on the state passed to it.
    ///
    /// The `context` argument is the same as the one that includes the `Slider`'s
    /// render box.
    ///
    /// The `offset` argument is the offset of the origin of the `parent_box` to
    /// the origin of its `context` canvas. This shape must be painted relative
    /// to this offset. See `PaintingContextCallback`.
    ///
    /// The `parent_box` argument is the `RenderBox` of the `RangeSlider`. Its
    /// attributes, such as size, can be used to assist in painting this shape.
    ///
    /// The `slider_theme` argument is the theme assigned to the `RangeSlider` that
    /// this shape belongs to.
    ///
    /// The `enable_animation` argument is an animation triggered when the
    /// `RangeSlider` is enabled, and it reverses when the slider is disabled. The
    /// `RangeSlider` is enabled when `RangeSlider::on_changed` is not null. Use
    /// this to paint intermediate frames for this shape when the slider changes
    /// enabled state.
    ///
    /// The `start_thumb_center` argument is the offset of the center of the start
    /// thumb relative to the origin of the `PaintingContext::canvas`. It can be
    /// used as one point that divides the track between inactive and active.
    ///
    /// The `end_thumb_center` argument is the offset of the center of the end
    /// thumb relative to the origin of the `PaintingContext::canvas`. It can be
    /// used as one point that divides the track between inactive and active.
    ///
    /// The `is_enabled` argument is false when `RangeSlider::on_changed` is null and
    /// true otherwise. When true, the slider will respond to input; Dart's default is
    /// false.
    ///
    /// The `is_discrete` argument is true if `RangeSlider::divisions` is non-null.
    /// When true, the slider will render tick marks on top of the track; Dart's default
    /// is false.
    ///
    /// The `text_direction` argument can be used to determine how the track
    /// segments are painted depending on whether they are on an active track
    /// segment or not.
    ///
    /// The track segment between the two thumbs is the active track segment. The
    /// track segments between the thumb and each end of the slider are the inactive
    /// track segments. In `TextDirection::Ltr`, the start of the slider is on the
    /// left, and in `TextDirection::Rtl`, the start of the slider is on the right.
    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        offset: Offset,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: bool,
        is_discrete: bool,
        text_direction: TextDirection,
    );

    /// Whether the track shape is rounded. This is used to determine the correct
    /// position of the thumbs in relation to the track. Defaults to false.
    fn is_rounded(&self) -> bool {
        false
    }

    /// Downcast support for Dart's `is` checks.
    fn as_any(&self) -> &dyn Any;

    /// Dart's `==`: identity unless a shape overrides it.
    fn eq_shape(&self, other: &dyn RangeSliderTrackShape) -> bool {
        std::ptr::eq(self.as_any(), other.as_any())
    }
}

/// What a field or parameter Dart types as `RangeSliderTrackShape` becomes.
pub type RangeSliderTrackShapeRef = Rc<dyn RangeSliderTrackShape>;

impl PartialEq for dyn RangeSliderTrackShape {
    fn eq(&self, other: &dyn RangeSliderTrackShape) -> bool {
        self.eq_shape(other)
    }
}

/// Base range slider track shape that provides an implementation of
/// [`get_preferred_rect`](Self::get_preferred_rect) for default sizing.
///
/// The height is set from `SliderThemeData::track_height` and the width of the
/// parent box less the larger of the widths of `SliderThemeData::range_thumb_shape` and
/// `SliderThemeData::overlay_shape`.
///
/// A track that mixes it in calls this body from its [`RangeSliderTrackShape`] method.
///
/// See also:
///
///  * [`RectangularRangeSliderTrackShape`], which is a track shape with sharp
///    rectangular edges
pub trait BaseRangeSliderTrackShape {
    /// Returns a rect that represents the track bounds that fits within the
    /// `Slider`.
    ///
    /// The width is the width of the `RangeSlider`, but padded by the max
    /// of the overlay and thumb radius. The height is defined by the
    /// `SliderThemeData::track_height`.
    ///
    /// The [`Rect`] is centered both horizontally and vertically within the slider
    /// bounds.
    ///
    /// `None` for `is_enabled` or `is_discrete` is Dart's default, false.
    fn get_preferred_rect(
        &self,
        app: &App,
        parent_box: AnyRenderBox,
        offset: Offset,
        slider_theme: &SliderThemeData,
        is_enabled: Option<bool>,
        is_discrete: Option<bool>,
    ) -> Rect {
        let is_enabled = is_enabled.unwrap_or(false);
        let is_discrete = is_discrete.unwrap_or(false);
        debug_assert!(slider_theme.range_thumb_shape.is_some());
        debug_assert!(slider_theme.overlay_shape.is_some());
        debug_assert!(slider_theme.track_height.is_some());
        let thumb_size = slider_theme
            .range_thumb_shape
            .as_ref()
            .expect("the slider theme has a range thumb shape")
            .get_preferred_size(is_enabled, is_discrete);
        let overlay_width = slider_theme
            .overlay_shape
            .as_ref()
            .expect("the slider theme has an overlay shape")
            .get_preferred_size(is_enabled, is_discrete)
            .width();
        let mut track_height = slider_theme
            .track_height
            .expect("the slider theme has a track height");
        debug_assert!(overlay_width >= 0.0);
        debug_assert!(track_height >= 0.0);

        // If the track colors are transparent, then override only the track height
        // to maintain overall Slider width.
        if slider_theme.active_track_color == Some(Colors::TRANSPARENT)
            && slider_theme.inactive_track_color == Some(Colors::TRANSPARENT)
        {
            track_height = 0.0;
        }

        let track_left = offset.dx()
            + if slider_theme.padding.is_none() {
                (overlay_width / 2.0).max(thumb_size.width() / 2.0)
            } else {
                thumb_size.width() / 2.0
            };
        let track_top = offset.dy() + (parent_box.size(app).height() - track_height) / 2.0;
        let track_right = track_left + parent_box.size(app).width()
            - if slider_theme.padding.is_none() {
                thumb_size.width().max(overlay_width)
            } else {
                thumb_size.width()
            };
        let track_bottom = track_top + track_height;
        // If the parentBox's size less than slider's size the trackRight will be less than trackLeft, so switch them.
        Rect::from_ltrb(
            track_left.min(track_right),
            track_top,
            track_left.max(track_right),
            track_bottom,
        )
    }
}

/// A `RangeSlider` track that's a simple rectangle.
///
/// It paints a solid colored rectangle, vertically centered in the
/// `parent_box`. The track rectangle extends to the bounds of the `parent_box`,
/// but is padded by the `RoundSliderOverlayShape` radius. The height is
/// defined by the `SliderThemeData::track_height`. The color is determined by the
/// `Slider`'s enabled state and the track segment's active state which are
/// defined by:
///   `SliderThemeData::active_track_color`,
///   `SliderThemeData::inactive_track_color`,
///   `SliderThemeData::disabled_active_track_color`,
///   `SliderThemeData::disabled_inactive_track_color`.
///
/// The track segment between the two thumbs is the active track segment. The
/// track segments between the thumb and each end of the slider are the inactive
/// track segments. In `TextDirection::Ltr`, the start of the slider is on the
/// left, and in `TextDirection::Rtl`, the start of the slider is on the right.
///
/// See also:
///
///  * `RangeSlider`, for the component that is meant to display this shape.
///  * [`SliderThemeData`], where an instance of this class is set to inform the
///    slider of the visual details of the its track.
///  * [`RangeSliderTrackShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s track.
///  * [`RoundedRectRangeSliderTrackShape`], for a similar track with rounded
///    edges.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RectangularRangeSliderTrackShape;

impl RectangularRangeSliderTrackShape {
    /// Create a slider track with rectangular outer edges.
    ///
    /// The middle track segment is the selected range and is active, and the two
    /// outer track segments are inactive.
    pub const fn new() -> RectangularRangeSliderTrackShape {
        RectangularRangeSliderTrackShape
    }
}

impl BaseRangeSliderTrackShape for RectangularRangeSliderTrackShape {}

impl RangeSliderTrackShape for RectangularRangeSliderTrackShape {
    fn get_preferred_rect(
        &self,
        app: &App,
        parent_box: AnyRenderBox,
        offset: Offset,
        slider_theme: &SliderThemeData,
        is_enabled: Option<bool>,
        is_discrete: Option<bool>,
    ) -> Rect {
        BaseRangeSliderTrackShape::get_preferred_rect(
            self,
            app,
            parent_box,
            offset,
            slider_theme,
            is_enabled,
            is_discrete,
        )
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        offset: Offset,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: bool,
        is_discrete: bool,
        text_direction: TextDirection,
    ) {
        debug_assert!(slider_theme.disabled_active_track_color.is_some());
        debug_assert!(slider_theme.disabled_inactive_track_color.is_some());
        debug_assert!(slider_theme.active_track_color.is_some());
        debug_assert!(slider_theme.inactive_track_color.is_some());
        debug_assert!(slider_theme.range_thumb_shape.is_some());
        // Assign the track segment paints, which are left: active, right: inactive,
        // but reversed for right to left text.
        let active_paint = fill_paint(
            evaluate_color_tween(
                app,
                slider_theme.disabled_active_track_color,
                slider_theme.active_track_color,
                enable_animation,
            )
            .expect("the active track colors are set"),
        );
        let inactive_paint = fill_paint(
            evaluate_color_tween(
                app,
                slider_theme.disabled_inactive_track_color,
                slider_theme.inactive_track_color,
                enable_animation,
            )
            .expect("the inactive track colors are set"),
        );

        let (left_thumb_offset, right_thumb_offset) = match text_direction {
            TextDirection::Ltr => (start_thumb_center, end_thumb_center),
            TextDirection::Rtl => (end_thumb_center, start_thumb_center),
        };

        let track_rect = RangeSliderTrackShape::get_preferred_rect(
            self,
            app,
            parent_box,
            offset,
            slider_theme,
            Some(is_enabled),
            Some(is_discrete),
        );
        let canvas = context.canvas();
        let left_track_segment = Rect::from_ltrb(
            track_rect.left,
            track_rect.top,
            left_thumb_offset.dx(),
            track_rect.bottom,
        );
        if !left_track_segment.is_empty() {
            canvas.draw_rect(left_track_segment, &inactive_paint);
        }
        let middle_track_segment = Rect::from_ltrb(
            left_thumb_offset.dx(),
            track_rect.top,
            right_thumb_offset.dx(),
            track_rect.bottom,
        );
        if !middle_track_segment.is_empty() {
            canvas.draw_rect(middle_track_segment, &active_paint);
        }
        let right_track_segment = Rect::from_ltrb(
            right_thumb_offset.dx(),
            track_rect.top,
            track_rect.right,
            track_rect.bottom,
        );
        if !right_track_segment.is_empty() {
            canvas.draw_rect(right_track_segment, &inactive_paint);
        }
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderTrackShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// The default shape of a `RangeSlider`'s track.
///
/// It paints a solid colored rectangle with rounded edges, vertically centered
/// in the `parent_box`. The track rectangle extends to the bounds of the
/// `parent_box`, but is padded by the larger of `RoundSliderOverlayShape`'s
/// radius and [`RoundRangeSliderThumbShape`]'s radius. The height is defined by
/// the `SliderThemeData::track_height`. The color is determined by the
/// `RangeSlider`'s enabled state and the track segment's active state which are
/// defined by:
///   `SliderThemeData::active_track_color`,
///   `SliderThemeData::inactive_track_color`,
///   `SliderThemeData::disabled_active_track_color`,
///   `SliderThemeData::disabled_inactive_track_color`.
///
/// The track segment between the two thumbs is the active track segment. The
/// track segments between the thumb and each end of the slider are the inactive
/// track segments. In `TextDirection::Ltr`, the start of the slider is on the
/// left, and in `TextDirection::Rtl`, the start of the slider is on the right.
///
/// See also:
///
///  * `RangeSlider`, for the component that is meant to display this shape.
///  * [`SliderThemeData`], where an instance of this class is set to inform the
///    slider of the visual details of the its track.
///  * [`RangeSliderTrackShape`], which can be used to create custom shapes for
///    the `RangeSlider`'s track.
///  * [`RectangularRangeSliderTrackShape`], for a similar track with sharp edges.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RoundedRectRangeSliderTrackShape;

impl RoundedRectRangeSliderTrackShape {
    /// Create a slider track with rounded outer edges.
    ///
    /// The middle track segment is the selected range and is active, and the two
    /// outer track segments are inactive.
    pub const fn new() -> RoundedRectRangeSliderTrackShape {
        RoundedRectRangeSliderTrackShape
    }

    /// Dart's `paint` override with its extra `additionalActiveTrackHeight` (Dart's
    /// default 2), which a call through [`RangeSliderTrackShape`] cannot pass.
    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    pub fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        offset: Offset,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: bool,
        is_discrete: bool,
        text_direction: TextDirection,
        additional_active_track_height: f64,
    ) {
        debug_assert!(slider_theme.disabled_active_track_color.is_some());
        debug_assert!(slider_theme.disabled_inactive_track_color.is_some());
        debug_assert!(slider_theme.active_track_color.is_some());
        debug_assert!(slider_theme.inactive_track_color.is_some());
        debug_assert!(slider_theme.range_thumb_shape.is_some());

        let Some(track_height) = slider_theme.track_height.filter(|height| *height > 0.0) else {
            return;
        };

        // Assign the track segment paints, which are left: active, right: inactive,
        // but reversed for right to left text.
        let active_paint = fill_paint(
            evaluate_color_tween(
                app,
                slider_theme.disabled_active_track_color,
                slider_theme.active_track_color,
                enable_animation,
            )
            .expect("the active track colors are set"),
        );
        let inactive_paint = fill_paint(
            evaluate_color_tween(
                app,
                slider_theme.disabled_inactive_track_color,
                slider_theme.inactive_track_color,
                enable_animation,
            )
            .expect("the inactive track colors are set"),
        );

        let (left_thumb_offset, right_thumb_offset) = match text_direction {
            TextDirection::Ltr => (start_thumb_center, end_thumb_center),
            TextDirection::Rtl => (end_thumb_center, start_thumb_center),
        };
        let thumb_size = slider_theme
            .range_thumb_shape
            .as_ref()
            .expect("the slider theme has a range thumb shape")
            .get_preferred_size(is_enabled, is_discrete);
        let thumb_radius = thumb_size.width() / 2.0;
        debug_assert!(thumb_radius > 0.0);

        let track_rect = RangeSliderTrackShape::get_preferred_rect(
            self,
            app,
            parent_box,
            offset,
            slider_theme,
            Some(is_enabled),
            Some(is_discrete),
        );

        let track_radius = Radius::circular(track_rect.height() / 2.0);

        let canvas = context.canvas();
        draw_rrect(
            canvas,
            RRect::from_ltrb_and_corners(
                track_rect.left,
                track_rect.top,
                left_thumb_offset.dx(),
                track_rect.bottom,
                track_radius,
                Radius::ZERO,
                Radius::ZERO,
                track_radius,
            ),
            &inactive_paint,
        );
        draw_rrect(
            canvas,
            RRect::from_ltrb_and_corners(
                right_thumb_offset.dx(),
                track_rect.top,
                track_rect.right,
                track_rect.bottom,
                Radius::ZERO,
                track_radius,
                track_radius,
                Radius::ZERO,
            ),
            &inactive_paint,
        );
        draw_rrect(
            canvas,
            RRect::from_ltrbr(
                left_thumb_offset.dx() - (track_height / 2.0),
                track_rect.top - (additional_active_track_height / 2.0),
                right_thumb_offset.dx() + (track_height / 2.0),
                track_rect.bottom + (additional_active_track_height / 2.0),
                track_radius,
            ),
            &active_paint,
        );
    }
}

impl BaseRangeSliderTrackShape for RoundedRectRangeSliderTrackShape {}

impl RangeSliderTrackShape for RoundedRectRangeSliderTrackShape {
    fn get_preferred_rect(
        &self,
        app: &App,
        parent_box: AnyRenderBox,
        offset: Offset,
        slider_theme: &SliderThemeData,
        is_enabled: Option<bool>,
        is_discrete: Option<bool>,
    ) -> Rect {
        BaseRangeSliderTrackShape::get_preferred_rect(
            self,
            app,
            parent_box,
            offset,
            slider_theme,
            is_enabled,
            is_discrete,
        )
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        offset: Offset,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: bool,
        is_discrete: bool,
        text_direction: TextDirection,
    ) {
        RoundedRectRangeSliderTrackShape::paint(
            self,
            app,
            context,
            offset,
            parent_box,
            slider_theme,
            enable_animation,
            start_thumb_center,
            end_thumb_center,
            is_enabled,
            is_discrete,
            text_direction,
            2.0,
        );
    }

    fn is_rounded(&self) -> bool {
        true
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderTrackShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// The default shape of each `RangeSlider` tick mark.
///
/// Tick marks are only displayed if the slider is discrete, which can be done
/// by setting the `RangeSlider::divisions` to an integer value.
///
/// It paints a solid circle, centered on the track.
/// The color is determined by the `Slider`'s enabled state and track's active
/// states. These colors are defined in:
///   `SliderThemeData::active_track_color`,
///   `SliderThemeData::inactive_track_color`,
///   `SliderThemeData::disabled_active_track_color`,
///   `SliderThemeData::disabled_inactive_track_color`.
///
/// See also:
///
///  * `RangeSlider`, which includes tick marks defined by this shape.
///  * `SliderTheme`, which can be used to configure the tick mark shape of all
///    sliders in a widget subtree.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RoundRangeSliderTickMarkShape {
    /// The preferred radius of the round tick mark.
    ///
    /// If it is not provided, then 1/4 of the `SliderThemeData::track_height` is used.
    pub tick_mark_radius: Option<f64>,
}

impl RoundRangeSliderTickMarkShape {
    /// Create a range slider tick mark that draws a circle.
    pub const fn new() -> RoundRangeSliderTickMarkShape {
        RoundRangeSliderTickMarkShape {
            tick_mark_radius: None,
        }
    }

    /// Dart `RoundRangeSliderTickMarkShape(tickMarkRadius:)`.
    pub const fn tick_mark_radius(
        mut self,
        tick_mark_radius: f64,
    ) -> RoundRangeSliderTickMarkShape {
        self.tick_mark_radius = Some(tick_mark_radius);
        self
    }
}

impl RangeSliderTickMarkShape for RoundRangeSliderTickMarkShape {
    fn get_preferred_size(
        &self,
        slider_theme: &SliderThemeData,
        _is_enabled: Option<bool>,
    ) -> Size {
        debug_assert!(slider_theme.track_height.is_some());
        Size::from_radius(self.tick_mark_radius.unwrap_or_else(|| {
            slider_theme
                .track_height
                .expect("the slider theme has a track height")
                / 4.0
        }))
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        _parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: Option<bool>,
        text_direction: TextDirection,
    ) {
        let is_enabled = is_enabled.unwrap_or(false);
        debug_assert!(slider_theme.disabled_active_tick_mark_color.is_some());
        debug_assert!(slider_theme.disabled_inactive_tick_mark_color.is_some());
        debug_assert!(slider_theme.active_tick_mark_color.is_some());
        debug_assert!(slider_theme.inactive_tick_mark_color.is_some());

        let has_gap = slider_theme
            .track_gap
            .is_some_and(|track_gap| track_gap > 0.0);
        let under_thumb =
            start_thumb_center.dx() == center.dx() || end_thumb_center.dx() == center.dx();
        if has_gap && under_thumb {
            return;
        }
        let is_between_thumbs = match text_direction {
            TextDirection::Ltr => {
                start_thumb_center.dx() < center.dx() && center.dx() < end_thumb_center.dx()
            }
            TextDirection::Rtl => {
                end_thumb_center.dx() < center.dx() && center.dx() < start_thumb_center.dx()
            }
        };
        let begin = if is_between_thumbs {
            slider_theme.disabled_active_tick_mark_color
        } else {
            slider_theme.disabled_inactive_tick_mark_color
        };
        let end = if is_between_thumbs {
            slider_theme.active_tick_mark_color
        } else {
            slider_theme.inactive_tick_mark_color
        };
        let paint = fill_paint(
            evaluate_color_tween(app, begin, end, enable_animation)
                .expect("the tick mark colors are set"),
        );

        // The tick marks are tiny circles that are the same height as the track.
        let tick_mark_radius =
            RangeSliderTickMarkShape::get_preferred_size(self, slider_theme, Some(is_enabled))
                .width()
                / 2.0;
        if tick_mark_radius > 0.0 {
            context
                .canvas()
                .draw_circle(center, tick_mark_radius as f32, &paint);
        }
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderTickMarkShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// The default shape of a `RangeSlider`'s thumbs.
///
/// There is a shadow for the resting and pressed state.
///
/// See also:
///
///  * `RangeSlider`, which includes thumbs defined by this shape.
///  * `SliderTheme`, which can be used to configure the thumb shapes of all
///    range sliders in a widget subtree.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct RoundRangeSliderThumbShape {
    /// The preferred radius of the round thumb shape when the slider is enabled.
    ///
    /// If it is not provided, then the Material Design default of 10 is used.
    pub enabled_thumb_radius: f64,

    /// The preferred radius of the round thumb shape when the slider is disabled.
    ///
    /// If no disabledRadius is provided, then it is equal to the
    /// [`enabled_thumb_radius`](Self::enabled_thumb_radius).
    pub disabled_thumb_radius: Option<f64>,

    /// The resting elevation adds shadow to the unpressed thumb.
    ///
    /// The default is 1.
    pub elevation: f64,

    /// The pressed elevation adds shadow to the pressed thumb.
    ///
    /// The default is 6.
    pub pressed_elevation: f64,
}

impl RoundRangeSliderThumbShape {
    /// Create a slider thumb that draws a circle.
    pub const fn new() -> RoundRangeSliderThumbShape {
        RoundRangeSliderThumbShape {
            enabled_thumb_radius: 10.0,
            disabled_thumb_radius: None,
            elevation: 1.0,
            pressed_elevation: 6.0,
        }
    }

    /// Dart `RoundRangeSliderThumbShape(enabledThumbRadius:)`.
    pub const fn enabled_thumb_radius(
        mut self,
        enabled_thumb_radius: f64,
    ) -> RoundRangeSliderThumbShape {
        self.enabled_thumb_radius = enabled_thumb_radius;
        self
    }

    /// Dart `RoundRangeSliderThumbShape(disabledThumbRadius:)`.
    pub const fn disabled_thumb_radius(
        mut self,
        disabled_thumb_radius: f64,
    ) -> RoundRangeSliderThumbShape {
        self.disabled_thumb_radius = Some(disabled_thumb_radius);
        self
    }

    /// Dart `RoundRangeSliderThumbShape(elevation:)`.
    pub const fn elevation(mut self, elevation: f64) -> RoundRangeSliderThumbShape {
        self.elevation = elevation;
        self
    }

    /// Dart `RoundRangeSliderThumbShape(pressedElevation:)`.
    pub const fn pressed_elevation(mut self, pressed_elevation: f64) -> RoundRangeSliderThumbShape {
        self.pressed_elevation = pressed_elevation;
        self
    }

    /// Dart's `_disabledThumbRadius`.
    fn effective_disabled_thumb_radius(&self) -> f64 {
        self.disabled_thumb_radius
            .unwrap_or(self.enabled_thumb_radius)
    }
}

impl Default for RoundRangeSliderThumbShape {
    fn default() -> RoundRangeSliderThumbShape {
        RoundRangeSliderThumbShape::new()
    }
}

impl RangeSliderThumbShape for RoundRangeSliderThumbShape {
    fn get_preferred_size(&self, is_enabled: bool, _is_discrete: bool) -> Size {
        Size::from_radius(if is_enabled {
            self.enabled_thumb_radius
        } else {
            self.effective_disabled_thumb_radius()
        })
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        activation_animation: AnyAnimation<f64>,
        enable_animation: AnyAnimation<f64>,
        _is_discrete: Option<bool>,
        _is_enabled: Option<bool>,
        is_on_top: Option<bool>,
        _text_direction: Option<TextDirection>,
        slider_theme: &SliderThemeData,
        _thumb: Option<Thumb>,
        is_pressed: Option<bool>,
    ) {
        debug_assert!(slider_theme.show_value_indicator.is_some());
        debug_assert!(slider_theme.overlapping_shape_stroke_color.is_some());
        let radius = evaluate_tween(
            app,
            self.effective_disabled_thumb_radius(),
            self.enabled_thumb_radius,
            enable_animation,
        );

        // Add a stroke of 1dp around the circle if this thumb would overlap
        // the other thumb.
        if is_on_top.unwrap_or(false) {
            let stroke_paint = stroke_paint(
                slider_theme
                    .overlapping_shape_stroke_color
                    .expect("the slider theme has an overlapping shape stroke color"),
            );
            context
                .canvas()
                .draw_circle(center, radius as f32, &stroke_paint);
        }

        let color = evaluate_color_tween(
            app,
            slider_theme.disabled_thumb_color,
            slider_theme.thumb_color,
            enable_animation,
        )
        .expect("the thumb colors are set");

        let evaluated_elevation =
            if is_pressed.expect("the range slider says whether it is pressed") {
                evaluate_tween(
                    app,
                    self.elevation,
                    self.pressed_elevation,
                    activation_animation,
                )
            } else {
                self.elevation
            };
        let mut shadow_path = PathBuilder::new();
        shadow_path.arc(center, radius as f32, 0.0, std::f32::consts::TAU);
        let shadow_path = Path::new(shadow_path.build());

        let device_pixel_ratio = implicit_view_device_pixel_ratio(app);
        context.canvas().draw_shadow(
            shadow_path.as_valo(),
            shadow_path.fill_type,
            Colors::BLACK.into(),
            evaluated_elevation as f32,
            true,
            device_pixel_ratio as f32,
        );

        context
            .canvas()
            .draw_circle(center, radius as f32, &fill_paint(color));
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderThumbShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// The device pixel ratio the engine's `Canvas.drawShadow` reads from the implicit view:
/// the first view the platform reports, 1 when it reports none, as the engine's is without
/// metrics.
fn implicit_view_device_pixel_ratio(app: &App) -> f64 {
    app.platform()
        .views()
        .first()
        .map_or(1.0, |view| view.metrics().device_pixel_ratio)
}

/// Decides which thumbs (if any) should be selected.
///
/// The default finds the closest thumb, but if the thumbs are close to each
/// other, it waits for movement defined by `dx` to determine the selected
/// thumb.
///
/// Override `SliderThemeData::thumb_selector` for custom thumb selection.
///
/// Its arguments are Dart's `textDirection`, `values`, `tapValue`, `thumbSize`,
/// `trackSize` and `dx`, in that order; two selectors are equal only when they are one `Rc`.
pub type RangeThumbSelector =
    Rc<dyn Fn(TextDirection, RangeValues, f64, Size, Size, f64) -> Option<Thumb>>;

/// Object for representing range slider thumb values.
///
/// This object is passed into `RangeSlider::values` to set its values, and it
/// is emitted in `RangeSlider::on_changed`, `RangeSlider::on_change_start`, and
/// `RangeSlider::on_change_end` when the values change.
#[derive(Clone, Copy, PartialEq)]
pub struct RangeValues {
    /// The value of the start thumb.
    ///
    /// For LTR text direction, the start is the left thumb, and for RTL text
    /// direction, the start is the right thumb.
    pub start: f64,

    /// The value of the end thumb.
    ///
    /// For LTR text direction, the end is the right thumb, and for RTL text
    /// direction, the end is the left thumb.
    pub end: f64,
}

impl RangeValues {
    /// Creates pair of start and end values.
    pub const fn new(start: f64, end: f64) -> RangeValues {
        RangeValues { start, end }
    }
}

impl Debug for RangeValues {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "RangeValues({:?}, {:?})", self.start, self.end)
    }
}

/// Object for setting range slider label values that appear in the value
/// indicator for each thumb.
///
/// Used in combination with `SliderThemeData::show_value_indicator` to display
/// labels above the thumbs.
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct RangeLabels {
    /// The label of the start thumb.
    ///
    /// For LTR text direction, the start is the left thumb, and for RTL text
    /// direction, the start is the right thumb.
    pub start: String,

    /// The label of the end thumb.
    ///
    /// For LTR text direction, the end is the right thumb, and for RTL text
    /// direction, the end is the left thumb.
    pub end: String,
}

impl RangeLabels {
    /// Creates pair of start and end labels.
    pub fn new(start: impl Into<String>, end: impl Into<String>) -> RangeLabels {
        RangeLabels {
            start: start.into(),
            end: end.into(),
        }
    }
}

impl Debug for RangeLabels {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "RangeLabels({}, {})", self.start, self.end)
    }
}

/// Dart's `Paint()..color = color`.
fn fill_paint(color: Color) -> Paint {
    Paint {
        color: color.into(),
        ..Paint::default()
    }
}

/// Dart's `Paint()..color = color..strokeWidth = 1.0..style = PaintingStyle.stroke`.
fn stroke_paint(color: Color) -> Paint {
    Paint {
        color: color.into(),
        style: PaintStyle::Stroke(Stroke::new(1.0)),
        ..Paint::default()
    }
}

/// The gapped shape of a `RangeSlider`'s track.
///
/// The [`GappedRangeSliderTrackShape`] consists of active and inactive
/// tracks. The active track uses the `SliderThemeData::active_track_color` and the
/// inactive tracks uses the `SliderThemeData::inactive_track_color`.
///
/// The track shape uses circular corner radius for the edge corners and a corner radius
/// of 2 pixels for the inside corners.
///
/// Between the active and inactive tracks there are gaps of size
/// `SliderThemeData::track_gap`. If the `SliderThemeData::thumb_shape` is
/// [`HandleRangeSliderThumbShape`] and the thumb is pressed, the thumb's width is reduced;
/// as a result, the track gaps size in [`GappedRangeSliderTrackShape`] is also reduced.
///
/// If `SliderThemeData::track_gap` is null, then the track gaps size defaults to 6 pixels.
///
/// If `ThemeData::use_material3` is true and `RangeSlider::year2023` is false, then the
/// `RangeSlider` will use [`GappedRangeSliderTrackShape`] as the default track shape.
///
/// See also:
///
///  * `RangeSlider`, which includes a track defined by this shape.
///  * `SliderTheme`, which can be used to configure the track shape of all
///    range sliders in a widget subtree.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct GappedRangeSliderTrackShape;

impl GappedRangeSliderTrackShape {
    /// Create a range slider track that draws 3 rounded rectangles with rounded outer edges.
    pub const fn new() -> GappedRangeSliderTrackShape {
        GappedRangeSliderTrackShape
    }

    /// Dart's `paint` override with its extra `additionalActiveTrackHeight` (Dart's
    /// default 2), which a call through [`RangeSliderTrackShape`] cannot pass.
    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    pub fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        offset: Offset,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: bool,
        is_discrete: bool,
        text_direction: TextDirection,
        additional_active_track_height: f64,
    ) {
        let _ = additional_active_track_height;
        debug_assert!(slider_theme.disabled_active_track_color.is_some());
        debug_assert!(slider_theme.disabled_inactive_track_color.is_some());
        debug_assert!(slider_theme.active_track_color.is_some());
        debug_assert!(slider_theme.inactive_track_color.is_some());
        debug_assert!(slider_theme.range_thumb_shape.is_some());

        let Some(track_height) = slider_theme.track_height.filter(|height| *height > 0.0) else {
            return;
        };

        let active_paint = fill_paint(
            evaluate_color_tween(
                app,
                slider_theme.disabled_active_track_color,
                slider_theme.active_track_color,
                enable_animation,
            )
            .expect("the active track colors are set"),
        );
        let inactive_paint = fill_paint(
            evaluate_color_tween(
                app,
                slider_theme.disabled_inactive_track_color,
                slider_theme.inactive_track_color,
                enable_animation,
            )
            .expect("the inactive track colors are set"),
        );

        let track_rect = RangeSliderTrackShape::get_preferred_rect(
            self,
            app,
            parent_box,
            offset,
            slider_theme,
            Some(is_enabled),
            Some(is_discrete),
        );

        let track_corner_radius = Radius::circular(track_rect.shortest_side() / 2.0);
        const TRACK_INSIDE_CORNER_RADIUS: Radius = Radius::circular(2.0);

        let (left_thumb_offset, right_thumb_offset) = match text_direction {
            TextDirection::Ltr => (start_thumb_center, end_thumb_center),
            TextDirection::Rtl => (end_thumb_center, start_thumb_center),
        };

        let thumb_size = slider_theme
            .range_thumb_shape
            .as_ref()
            .expect("the slider theme has a range thumb shape")
            .get_preferred_size(is_enabled, is_discrete);
        let thumb_radius = thumb_size.width() / 2.0;
        debug_assert!(thumb_radius > 0.0);
        let track_gap = slider_theme
            .track_gap
            .expect("the slider theme has a track gap");

        let track_rrect = RRect::from_rect_and_corners(
            track_rect,
            track_corner_radius,
            track_corner_radius,
            track_corner_radius,
            track_corner_radius,
        );

        let left_rrect = RRect::from_ltrb_and_corners(
            track_rect.left,
            track_rect.top,
            left_thumb_offset.dx() - track_gap,
            track_rect.bottom,
            track_corner_radius,
            TRACK_INSIDE_CORNER_RADIUS,
            TRACK_INSIDE_CORNER_RADIUS,
            track_corner_radius,
        );

        let right_rrect = RRect::from_ltrb_and_corners(
            right_thumb_offset.dx() + track_gap,
            track_rect.top,
            track_rect.right,
            track_rect.bottom,
            TRACK_INSIDE_CORNER_RADIUS,
            track_corner_radius,
            track_corner_radius,
            TRACK_INSIDE_CORNER_RADIUS,
        );

        let canvas = context.canvas();
        canvas.save();
        canvas.clip_rrect_radii_elliptical(
            track_rrect.outer_rect(),
            rrect_radii_elliptical(track_rrect),
            ClipOp::Intersect,
            true,
        );
        let draw_left_track = start_thumb_center.dx() > (left_rrect.left + (track_height / 2.0));
        let draw_right_track = end_thumb_center.dx() < (right_rrect.right - (track_height / 2.0));

        if draw_left_track {
            draw_rrect(canvas, left_rrect, &inactive_paint);
        }
        if draw_right_track {
            draw_rrect(canvas, right_rrect, &inactive_paint);
        }

        if left_thumb_offset.dx() + track_gap < right_thumb_offset.dx() - track_gap {
            draw_rrect(
                canvas,
                RRect::from_ltrbr(
                    left_thumb_offset.dx() + track_gap,
                    track_rect.top,
                    right_thumb_offset.dx() - track_gap,
                    track_rect.bottom,
                    TRACK_INSIDE_CORNER_RADIUS,
                ),
                &active_paint,
            );
        }

        canvas.restore();

        const STOP_INDICATOR_RADIUS: f64 = 2.0;
        let stop_indicator_trailing_space = track_height / 2.0;
        let start_stop_indicator_offset = Offset::new(
            track_rect.center_left().dx() + stop_indicator_trailing_space,
            track_rect.center().dy(),
        );
        let end_stop_indicator_offset = Offset::new(
            track_rect.center_right().dx() - stop_indicator_trailing_space,
            track_rect.center().dy(),
        );

        let show_start_stop_indicator = start_thumb_center.dx() > start_stop_indicator_offset.dx();
        if show_start_stop_indicator && !is_discrete {
            let stop_indicator_rect =
                Rect::from_circle(start_stop_indicator_offset, STOP_INDICATOR_RADIUS);
            canvas.draw_circle(
                stop_indicator_rect.center(),
                STOP_INDICATOR_RADIUS as f32,
                &active_paint,
            );
        }

        let show_end_stop_indicator = end_thumb_center.dx() < end_stop_indicator_offset.dx();
        if show_end_stop_indicator && !is_discrete {
            let stop_indicator_rect =
                Rect::from_circle(end_stop_indicator_offset, STOP_INDICATOR_RADIUS);
            canvas.draw_circle(
                stop_indicator_rect.center(),
                STOP_INDICATOR_RADIUS as f32,
                &active_paint,
            );
        }
    }
}

impl BaseRangeSliderTrackShape for GappedRangeSliderTrackShape {}

impl RangeSliderTrackShape for GappedRangeSliderTrackShape {
    fn get_preferred_rect(
        &self,
        app: &App,
        parent_box: AnyRenderBox,
        offset: Offset,
        slider_theme: &SliderThemeData,
        is_enabled: Option<bool>,
        is_discrete: Option<bool>,
    ) -> Rect {
        BaseRangeSliderTrackShape::get_preferred_rect(
            self,
            app,
            parent_box,
            offset,
            slider_theme,
            is_enabled,
            is_discrete,
        )
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        offset: Offset,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        enable_animation: AnyAnimation<f64>,
        start_thumb_center: Offset,
        end_thumb_center: Offset,
        is_enabled: bool,
        is_discrete: bool,
        text_direction: TextDirection,
    ) {
        GappedRangeSliderTrackShape::paint(
            self,
            app,
            context,
            offset,
            parent_box,
            slider_theme,
            enable_animation,
            start_thumb_center,
            end_thumb_center,
            is_enabled,
            is_discrete,
            text_direction,
            2.0,
        );
    }

    fn is_rounded(&self) -> bool {
        true
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderTrackShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// The bar shape of `RangeSlider`'s thumbs.
///
/// When the range slider is enabled, the `ColorScheme::primary` color is used for the
/// thumb. When the slider is disabled, the `ColorScheme::on_surface` color with an
/// opacity of 0.38 is used for the thumb.
///
/// The thumb bar shape width is reduced when the thumb is pressed.
///
/// If `SliderThemeData::thumb_size` is null, then the thumb size is 4 pixels for the width
/// and 44 pixels for the height.
///
/// If `ThemeData::use_material3` is true and `RangeSlider::year2023` is false, then the
/// `RangeSlider` will use [`HandleRangeSliderThumbShape`] as the default track shape.
///
/// See also:
///
///  * `RangeSlider`, which includes thumbs defined by this shape.
///  * `SliderTheme`, which can be used to configure the thumbs shape of all
///    range sliders in a widget subtree.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct HandleRangeSliderThumbShape;

impl HandleRangeSliderThumbShape {
    /// Create a range slider thumb that draws a bar.
    pub const fn new() -> HandleRangeSliderThumbShape {
        HandleRangeSliderThumbShape
    }
}

impl RangeSliderThumbShape for HandleRangeSliderThumbShape {
    fn get_preferred_size(&self, _is_enabled: bool, _is_discrete: bool) -> Size {
        Size::new(4.0, 44.0)
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        _activation_animation: AnyAnimation<f64>,
        enable_animation: AnyAnimation<f64>,
        _is_discrete: Option<bool>,
        _is_enabled: Option<bool>,
        _is_on_top: Option<bool>,
        _text_direction: Option<TextDirection>,
        slider_theme: &SliderThemeData,
        _thumb: Option<Thumb>,
        _is_pressed: Option<bool>,
    ) {
        debug_assert!(slider_theme.show_value_indicator.is_some());
        debug_assert!(slider_theme.overlapping_shape_stroke_color.is_some());
        debug_assert!(slider_theme.disabled_thumb_color.is_some());
        debug_assert!(slider_theme.thumb_color.is_some());
        debug_assert!(slider_theme.thumb_size.is_some());

        let color = evaluate_color_tween(
            app,
            slider_theme.disabled_thumb_color,
            slider_theme.thumb_color,
            enable_animation,
        )
        .expect("the thumb colors are set");

        let thumb_size = slider_theme
            .thumb_size
            .as_ref()
            .expect("the slider theme has a thumb size")
            .resolve(&WidgetStates::new())
            .expect("the thumb size resolves for no state"); // This is resolved in the paint method.
        let rrect = RRect::from_rect_and_radius(
            Rect::from_center(center, thumb_size.width(), thumb_size.height()),
            Radius::circular(thumb_size.shortest_side() / 2.0),
        );

        draw_rrect(context.canvas(), rrect, &fill_paint(color));
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderThumbShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// The rounded rectangle shape of a `RangeSlider`'s value indicators.
///
/// If the `SliderThemeData::value_indicator_color` is null, then the shape uses the
/// `ColorScheme::inverse_surface` color to draw the value indicator.
///
/// If the `SliderThemeData::value_indicator_text_style` is null, then the indicator label
/// text style defaults to `TextTheme::label_medium` with the color set to
/// `ColorScheme::on_inverse_surface`. If the `ThemeData::use_material3` is set to false, then
/// the indicator label text style defaults to `TextTheme::body_large` with the color set to
/// `ColorScheme::on_inverse_surface`.
///
/// If the `SliderThemeData::value_indicator_stroke_color` is provided, then the value
/// indicator is drawn with a stroke border with the color provided.
///
/// If `ThemeData::use_material3` is true and `RangeSlider::year2023` is false, then the
/// `RangeSlider` will use [`RoundedRectRangeSliderValueIndicatorShape`] as the default value
/// indicators shape.
///
/// See also:
///
///  * `RangeSlider`, which includes value indicators defined by this shape.
///  * `SliderTheme`, which can be used to configure the range slider value indicators
///    of all range sliders in a widget subtree.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RoundedRectRangeSliderValueIndicatorShape;

impl RoundedRectRangeSliderValueIndicatorShape {
    const PATH_PAINTER: RoundedRectSliderValueIndicatorPathPainter =
        RoundedRectSliderValueIndicatorPathPainter;

    /// Create range slider value indicators that resembles a rounded rectangle.
    pub const fn new() -> RoundedRectRangeSliderValueIndicatorShape {
        RoundedRectRangeSliderValueIndicatorShape
    }
}

impl RangeSliderValueIndicatorShape for RoundedRectRangeSliderValueIndicatorShape {
    fn get_preferred_size(
        &self,
        _is_enabled: bool,
        _is_discrete: bool,
        label_painter: &TextPainter,
        text_scale_factor: f64,
    ) -> Size {
        debug_assert!(text_scale_factor >= 0.0);
        Self::PATH_PAINTER.get_preferred_size(label_painter, text_scale_factor)
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        activation_animation: AnyAnimation<f64>,
        _enable_animation: AnyAnimation<f64>,
        _is_discrete: Option<bool>,
        is_on_top: Option<bool>,
        label_painter: &mut TextPainter,
        text_scale_factor: Option<f64>,
        size_with_overflow: Option<Size>,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        _text_direction: Option<TextDirection>,
        _value: Option<f64>,
        _thumb: Option<Thumb>,
    ) {
        debug_assert!(text_scale_factor.is_some());
        debug_assert!(size_with_overflow.is_some());
        debug_assert!(slider_theme.value_indicator_color.is_some());

        let scale = activation_animation.value(app);
        Self::PATH_PAINTER.paint(
            app,
            context,
            parent_box,
            center,
            scale,
            label_painter,
            text_scale_factor.expect("the range slider passes its text scale factor"),
            size_with_overflow.expect("the range slider passes its size with overflow"),
            slider_theme
                .value_indicator_color
                .expect("the slider theme has a value indicator color"),
            if is_on_top.expect("the range slider says which indicator is on top") {
                slider_theme.overlapping_shape_stroke_color
            } else {
                slider_theme.value_indicator_stroke_color
            },
        );
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderValueIndicatorShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// The shape of a Material 3 `RangeSlider`'s value indicators.
///
/// If the `SliderThemeData::value_indicator_color` is null, then the shape uses the
/// `ColorScheme::primary` color to draw the value indicator.
///
/// If the `SliderThemeData::value_indicator_text_style` is null, then the indicator label
/// text style defaults to `TextTheme::label_medium` with the color set to
/// `ColorScheme::on_primary`. If the `ThemeData::use_material3` is set to false, then the
/// indicator label text style defaults to `TextTheme::body_large` with the color set to
/// `ColorScheme::on_inverse_surface`.
///
/// If the `SliderThemeData::value_indicator_stroke_color` is provided, then the value
/// indicator is drawn with a stroke border with the color provided.
///
/// See also:
///
///  * `RangeSlider`, which includes value indicators defined by this shape.
///  * `SliderTheme`, which can be used to configure the range slider value indicators
///    of all range sliders in a widget subtree.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct DropRangeSliderValueIndicatorShape;

impl DropRangeSliderValueIndicatorShape {
    const PATH_PAINTER: DropSliderValueIndicatorPathPainter = DropSliderValueIndicatorPathPainter;

    /// Create a range slider value indicator that resembles a drop shape.
    pub const fn new() -> DropRangeSliderValueIndicatorShape {
        DropRangeSliderValueIndicatorShape
    }
}

impl RangeSliderValueIndicatorShape for DropRangeSliderValueIndicatorShape {
    fn get_preferred_size(
        &self,
        _is_enabled: bool,
        _is_discrete: bool,
        label_painter: &TextPainter,
        text_scale_factor: f64,
    ) -> Size {
        debug_assert!(text_scale_factor >= 0.0);
        Self::PATH_PAINTER.get_preferred_size(label_painter, text_scale_factor)
    }

    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        center: Offset,
        activation_animation: AnyAnimation<f64>,
        _enable_animation: AnyAnimation<f64>,
        _is_discrete: Option<bool>,
        is_on_top: Option<bool>,
        label_painter: &mut TextPainter,
        text_scale_factor: Option<f64>,
        size_with_overflow: Option<Size>,
        parent_box: AnyRenderBox,
        slider_theme: &SliderThemeData,
        _text_direction: Option<TextDirection>,
        _value: Option<f64>,
        _thumb: Option<Thumb>,
    ) {
        let scale = activation_animation.value(app);
        Self::PATH_PAINTER.paint(
            app,
            context,
            parent_box,
            center,
            scale,
            label_painter,
            text_scale_factor.expect("the range slider passes its text scale factor"),
            size_with_overflow.expect("the range slider passes its size with overflow"),
            slider_theme
                .value_indicator_color
                .expect("the slider theme has a value indicator color"),
            if is_on_top.expect("the range slider says which indicator is on top") {
                slider_theme.overlapping_shape_stroke_color
            } else {
                slider_theme.value_indicator_stroke_color
            },
        );
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    /// Value equality, as Dart's canonicalized `const` instances are identical.
    fn eq_shape(&self, other: &dyn RangeSliderValueIndicatorShape) -> bool {
        other.as_any().downcast_ref::<Self>() == Some(self)
    }
}

/// Dart's private `_RoundedRectSliderValueIndicatorPathPainter`, which this file repeats
/// from `slider_parts.dart`.
struct RoundedRectSliderValueIndicatorPathPainter;

impl RoundedRectSliderValueIndicatorPathPainter {
    const LABEL_PADDING: f64 = 10.0;
    const PREFERRED_HEIGHT: f64 = 32.0;
    const MIN_LABEL_WIDTH: f64 = 16.0;
    const RECT_Y_OFFSET: f64 = 10.0;
    const BOTTOM_TIP_Y_OFFSET: f64 = 16.0;
    const PREFERRED_HALF_HEIGHT: f64 = Self::PREFERRED_HEIGHT / 2.0;

    fn get_preferred_size(&self, label_painter: &TextPainter, text_scale_factor: f64) -> Size {
        let width = Self::MIN_LABEL_WIDTH.max(label_painter.width())
            + (Self::LABEL_PADDING * 2.0) * text_scale_factor;
        Size::new(width, Self::PREFERRED_HEIGHT * text_scale_factor)
    }

    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn get_horizontal_shift(
        &self,
        app: &App,
        parent_box: AnyRenderBox,
        center: Offset,
        label_painter: &TextPainter,
        text_scale_factor: f64,
        size_with_overflow: Size,
        scale: f64,
    ) -> f64 {
        debug_assert!(!size_with_overflow.is_empty());

        const EDGE_PADDING: f64 = 8.0;
        let rectangle_width = self.upper_rectangle_width(label_painter, scale);

        // Value indicator draws on the Overlay and by using the global Offset
        // we are making sure we use the bounds of the Overlay instead of the Slider.
        let global_center = parent_box.local_to_global(app, center, None);

        // The rectangle must be shifted towards the center so that it minimizes the
        // chance of it rendering outside the bounds of the render box. If the shift
        // is negative, then the lobe is shifted from right to left, and if it is
        // positive, then the lobe is shifted from left to right.
        let overflow_left = (rectangle_width / 2.0 - global_center.dx() + EDGE_PADDING).max(0.0);
        let overflow_right = (rectangle_width / 2.0
            - (size_with_overflow.width() - global_center.dx() - EDGE_PADDING))
            .max(0.0);

        if rectangle_width < size_with_overflow.width() {
            overflow_left - overflow_right
        } else if overflow_left - overflow_right > 0.0 {
            overflow_left - (EDGE_PADDING * text_scale_factor)
        } else {
            -overflow_right + (EDGE_PADDING * text_scale_factor)
        }
    }

    fn upper_rectangle_width(&self, label_painter: &TextPainter, scale: f64) -> f64 {
        let unscaled_width =
            Self::MIN_LABEL_WIDTH.max(label_painter.width()) + (Self::LABEL_PADDING * 2.0);
        unscaled_width * scale
    }

    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        parent_box: AnyRenderBox,
        center: Offset,
        scale: f64,
        label_painter: &mut TextPainter,
        text_scale_factor: f64,
        size_with_overflow: Size,
        background_paint_color: Color,
        stroke_paint_color: Option<Color>,
    ) {
        if scale == 0.0 {
            // Zero scale essentially means "do not draw anything", so it's safe to just return.
            return;
        }
        debug_assert!(!size_with_overflow.is_empty());

        let rectangle_width = self.upper_rectangle_width(label_painter, scale);
        let horizontal_shift = self.get_horizontal_shift(
            app,
            parent_box,
            center,
            label_painter,
            text_scale_factor,
            size_with_overflow,
            scale,
        );

        let upper_rect = Rect::from_ltwh(
            -rectangle_width / 2.0 + horizontal_shift,
            -Self::RECT_Y_OFFSET - Self::PREFERRED_HEIGHT,
            rectangle_width,
            Self::PREFERRED_HEIGHT,
        );

        let fill_paint = fill_paint(background_paint_color);

        let fonts = PaintingBinding::instance(app).fonts(app);
        let canvas = context.canvas();
        canvas.save();
        // Prepare the canvas for the base of the tooltip, which is relative to the
        // center of the thumb.
        canvas.translate(
            center.dx() as f32,
            (center.dy() - Self::BOTTOM_TIP_Y_OFFSET) as f32,
        );
        canvas.scale(scale as f32, scale as f32);

        let rrect =
            RRect::from_rect_and_radius(upper_rect, Radius::circular(upper_rect.height() / 2.0));
        if let Some(stroke_paint_color) = stroke_paint_color {
            draw_rrect(canvas, rrect, &stroke_paint(stroke_paint_color));
        }

        draw_rrect(canvas, rrect, &fill_paint);

        // The label text is centered within the value indicator.
        let bottom_tip_to_upper_rect_translate_y =
            -Self::PREFERRED_HALF_HEIGHT / 2.0 - upper_rect.height();
        canvas.translate(0.0, bottom_tip_to_upper_rect_translate_y as f32);
        let box_center = Offset::new(horizontal_shift, upper_rect.height() / 2.3);
        let half_label_painter_offset =
            Offset::new(label_painter.width() / 2.0, label_painter.height() / 2.0);
        let label_offset = box_center - half_label_painter_offset;
        label_painter.paint(app.get_mut(fonts), canvas, label_offset);
        canvas.restore();
    }
}

/// Dart's private `_DropSliderValueIndicatorPathPainter`, which this file repeats from
/// `slider_parts.dart`.
struct DropSliderValueIndicatorPathPainter;

impl DropSliderValueIndicatorPathPainter {
    const TRIANGLE_HEIGHT: f64 = 10.0;
    const LABEL_PADDING: f64 = 8.0;
    const PREFERRED_HEIGHT: f64 = 32.0;
    const MIN_LABEL_WIDTH: f64 = 20.0;
    const MIN_RECT_HEIGHT: f64 = 28.0;
    const RECT_Y_OFFSET: f64 = 6.0;
    const BOTTOM_TIP_Y_OFFSET: f64 = 16.0;
    const PREFERRED_HALF_HEIGHT: f64 = Self::PREFERRED_HEIGHT / 2.0;
    const UPPER_RECT_RADIUS: f64 = 4.0;

    fn get_preferred_size(&self, label_painter: &TextPainter, text_scale_factor: f64) -> Size {
        let width = Self::MIN_LABEL_WIDTH.max(label_painter.width())
            + Self::LABEL_PADDING * 2.0 * text_scale_factor;
        Size::new(width, Self::PREFERRED_HEIGHT * text_scale_factor)
    }

    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn get_horizontal_shift(
        &self,
        app: &App,
        parent_box: AnyRenderBox,
        center: Offset,
        label_painter: &TextPainter,
        text_scale_factor: f64,
        size_with_overflow: Size,
        scale: f64,
    ) -> f64 {
        debug_assert!(!size_with_overflow.is_empty());

        const EDGE_PADDING: f64 = 8.0;
        let rectangle_width = self.upper_rectangle_width(label_painter, scale);

        // Value indicator draws on the Overlay and by using the global Offset
        // we are making sure we use the bounds of the Overlay instead of the Slider.
        let global_center = parent_box.local_to_global(app, center, None);

        // The rectangle must be shifted towards the center so that it minimizes the
        // chance of it rendering outside the bounds of the render box. If the shift
        // is negative, then the lobe is shifted from right to left, and if it is
        // positive, then the lobe is shifted from left to right.
        let overflow_left = (rectangle_width / 2.0 - global_center.dx() + EDGE_PADDING).max(0.0);
        let overflow_right = (rectangle_width / 2.0
            - (size_with_overflow.width() - global_center.dx() - EDGE_PADDING))
            .max(0.0);

        if rectangle_width < size_with_overflow.width() {
            overflow_left - overflow_right
        } else if overflow_left - overflow_right > 0.0 {
            overflow_left - (EDGE_PADDING * text_scale_factor)
        } else {
            -overflow_right + (EDGE_PADDING * text_scale_factor)
        }
    }

    fn upper_rectangle_width(&self, label_painter: &TextPainter, scale: f64) -> f64 {
        let unscaled_width = Self::MIN_LABEL_WIDTH.max(label_painter.width()) + Self::LABEL_PADDING;
        unscaled_width * scale
    }

    fn adjust_border_radius(&self, rect: Rect) -> BorderRadius {
        const RECTNESS: f64 = 0.0;
        BorderRadius::lerp(
            Some(BorderRadius::all(Radius::circular(Self::UPPER_RECT_RADIUS))),
            Some(BorderRadius::all(Radius::circular(
                rect.shortest_side() / 2.0,
            ))),
            1.0 - RECTNESS,
        )
        .expect("both radii are given")
    }

    #[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
    fn paint(
        &self,
        app: &mut App,
        context: &mut PaintingContext,
        parent_box: AnyRenderBox,
        center: Offset,
        scale: f64,
        label_painter: &mut TextPainter,
        text_scale_factor: f64,
        size_with_overflow: Size,
        background_paint_color: Color,
        stroke_paint_color: Option<Color>,
    ) {
        if scale == 0.0 {
            // Zero scale essentially means "do not draw anything", so it's safe to just return.
            return;
        }
        debug_assert!(!size_with_overflow.is_empty());
        let rectangle_width = self.upper_rectangle_width(label_painter, scale);
        let horizontal_shift = self.get_horizontal_shift(
            app,
            parent_box,
            center,
            label_painter,
            text_scale_factor,
            size_with_overflow,
            scale,
        );
        let upper_rect = Rect::from_ltwh(
            -rectangle_width / 2.0 + horizontal_shift,
            -Self::RECT_Y_OFFSET - Self::MIN_RECT_HEIGHT,
            rectangle_width,
            Self::MIN_RECT_HEIGHT,
        );

        let fill_paint = fill_paint(background_paint_color);

        let fonts = PaintingBinding::instance(app).fonts(app);
        let canvas = context.canvas();
        canvas.save();
        canvas.translate(
            center.dx() as f32,
            (center.dy() - Self::BOTTOM_TIP_Y_OFFSET) as f32,
        );
        canvas.scale(scale as f32, scale as f32);

        let adjusted_border_radius = self.adjust_border_radius(upper_rect);
        let border_rect = adjusted_border_radius
            .resolve(label_painter.text_direction())
            .to_rrect(upper_rect);
        let mut triangle_path = PathBuilder::new();
        // Dart's `Path()..lineTo` starts at the origin; valo's `line_to` on an empty path would
        // start at its point.
        triangle_path.move_to((0.0, 0.0));
        triangle_path
            .line_to((-Self::TRIANGLE_HEIGHT as f32, -Self::TRIANGLE_HEIGHT as f32))
            .line_to((Self::TRIANGLE_HEIGHT as f32, -Self::TRIANGLE_HEIGHT as f32))
            .close();
        triangle_path.rrect_radii_elliptical(
            border_rect.outer_rect(),
            rrect_radii_elliptical(border_rect),
        );
        let triangle_path = triangle_path.build();

        if let Some(stroke_paint_color) = stroke_paint_color {
            canvas.draw_path(
                &triangle_path,
                FillRule::NonZero,
                &stroke_paint(stroke_paint_color),
            );
        }

        canvas.draw_path(&triangle_path, FillRule::NonZero, &fill_paint);

        // The label text is centered within the value indicator.
        let bottom_tip_to_upper_rect_translate_y =
            -Self::PREFERRED_HALF_HEIGHT / 2.0 - upper_rect.height();
        canvas.translate(0.0, bottom_tip_to_upper_rect_translate_y as f32);
        let box_center = Offset::new(horizontal_shift, upper_rect.height() / 1.75);
        let half_label_painter_offset =
            Offset::new(label_painter.width() / 2.0, label_painter.height() / 2.0);
        let label_offset = box_center - half_label_painter_offset;
        label_painter.paint(app.get_mut(fonts), canvas, label_offset);
        canvas.restore();
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn range_values_compare_by_their_start_and_end() {
        assert_eq!(RangeValues::new(0.25, 0.75), RangeValues::new(0.25, 0.75));
        assert_ne!(RangeValues::new(0.25, 0.75), RangeValues::new(0.25, 0.5));
        assert_ne!(RangeValues::new(0.25, 0.75), RangeValues::new(0.5, 0.75));
    }

    #[test]
    fn range_values_print_as_dart_to_string_does() {
        assert_eq!(
            format!("{:?}", RangeValues::new(0.0, 1.5)),
            "RangeValues(0.0, 1.5)"
        );
    }

    #[test]
    fn range_labels_compare_by_their_start_and_end() {
        assert_eq!(RangeLabels::new("a", "b"), RangeLabels::new("a", "b"));
        assert_ne!(RangeLabels::new("a", "b"), RangeLabels::new("a", "c"));
        assert_ne!(RangeLabels::new("a", "b"), RangeLabels::new("c", "b"));
    }

    #[test]
    fn range_labels_print_as_dart_to_string_does() {
        assert_eq!(
            format!("{:?}", RangeLabels::new("start", "end")),
            "RangeLabels(start, end)"
        );
    }

    /// slider_theme_test 'Track shape isRounded defaults', for the range tracks.
    #[test]
    fn track_shape_is_rounded_defaults() {
        assert!(!RangeSliderTrackShape::is_rounded(
            &RectangularRangeSliderTrackShape::new()
        ));
        assert!(RangeSliderTrackShape::is_rounded(
            &RoundedRectRangeSliderTrackShape::new()
        ));
        assert!(RangeSliderTrackShape::is_rounded(
            &GappedRangeSliderTrackShape::new()
        ));
    }

    #[test]
    fn the_round_thumb_is_sized_by_its_radius_for_its_enabled_state() {
        let shape = RoundRangeSliderThumbShape::new();
        assert_eq!(shape.get_preferred_size(true, false), Size::new(20.0, 20.0));
        assert_eq!(
            shape.get_preferred_size(false, false),
            Size::new(20.0, 20.0)
        );
        let shape = shape.enabled_thumb_radius(12.0).disabled_thumb_radius(6.0);
        assert_eq!(shape.get_preferred_size(true, true), Size::new(24.0, 24.0));
        assert_eq!(shape.get_preferred_size(false, true), Size::new(12.0, 12.0));
    }

    #[test]
    fn the_handle_thumb_is_four_by_forty_four() {
        assert_eq!(
            HandleRangeSliderThumbShape::new().get_preferred_size(true, false),
            Size::new(4.0, 44.0)
        );
    }

    #[test]
    fn the_round_tick_mark_defaults_to_a_quarter_of_the_track_height() {
        let theme = SliderThemeData::new().track_height(8.0);
        assert_eq!(
            RoundRangeSliderTickMarkShape::new().get_preferred_size(&theme, None),
            Size::new(4.0, 4.0)
        );
        assert_eq!(
            RoundRangeSliderTickMarkShape::new()
                .tick_mark_radius(5.0)
                .get_preferred_size(&theme, Some(true)),
            Size::new(10.0, 10.0)
        );
    }

    #[test]
    fn built_in_shapes_compare_by_value() {
        let a: RangeSliderThumbShapeRef = Rc::new(RoundRangeSliderThumbShape::new());
        let b: RangeSliderThumbShapeRef = Rc::new(RoundRangeSliderThumbShape::new());
        let c: RangeSliderThumbShapeRef = Rc::new(RoundRangeSliderThumbShape::new().elevation(2.0));
        assert!(*a == *b);
        assert!(*a != *c);
        let handle: RangeSliderThumbShapeRef = Rc::new(HandleRangeSliderThumbShape::new());
        assert!(*a != *handle);
    }
}