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
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
// cSpell: ignore langtype typeregister borderless commonmark Strikethroughs
//! The builtin elements of the language and the runtime items they lower to.
//!
//! `item!` declares a runtime item, one per item struct, with the properties, callbacks and
//! functions the item implements. An item that has every property of another one names it
//! after a colon, so the compiler can lower to the smaller item when the larger one isn't needed:
//!
//! ```text
//! item! { SimpleText: Empty {
//! /// Documentation of the member.
//! in property <string> text;
//! in property <length> font-size: 12px;
//! @deprecated in property <angle> rotation-angle <=> transform-rotation; // deprecated alias
//! //! ### Section heading // free-form documentation kept in source order
//! callback edited(text: string) -> bool;
//! function close() { } // implemented by a compiler pass
//! function start() { BuiltinFunction.StartTimer } // implemented by a BuiltinFunction
//! out property <FontMetrics> font-metrics { BuiltinFunction.ItemFontMetrics } // computed per element
//! } }
//! ```
//!
//! `element!` declares an element `.slint` code can use. An element names the native item it
//! lowers to; the compiler picks the smallest item in that item's parent chain that has every
//! property the element uses, so a `Rectangle { }` becomes an `Empty`. Members declared on the
//! element itself only exist in the compiler. Accepted child elements are listed with
//! `children:`.
//!
//! ```text
//! element! {
//! /// Documentation of the element.
//! @implicit_size
//! Text: ComplexText
//! }
//!
//! element! { Window: WindowItem { children: MenuBar; } }
//!
//! element! {
//! @is_non_item_type
//! Timer {
//! in property <duration> interval;
//! function start() { BuiltinFunction.StartTimer }
//! }
//! }
//! ```
//!
//! The `@flags` of an element are the boolean fields of `BuiltinElement` (`is_internal`,
//! `is_global`, ...) plus `expands_to_parent_geometry` or `implicit_size` for the default size,
//! `builtin_struct(Name)`, `sc` for an element of the Slint SC subset and `skip_inherited` to
//! leave the docs of the native items out of the element's.
//! Member modifiers `@shadowable`, `@deprecated` (aliases only) and `@pure` keep their Slint
//! meaning; `@constexpr` marks a property whose value is known at compile time, `@fake` one
//! that exists only at compile time and `@sc` one of the Slint SC subset. A default value is a
//! literal (`true`, `4`, `8px`, `500ms`, `"text"`, `#00f`) or an enum value
//! (`ImageFit.contain`); the compiler sets it as the property's binding.
//!
//! Elements that are accepted children of another element are only reachable through it.
//! A native item or an element must be declared before the items and elements using it, so each
//! item sits right before the element that lowers to it. The macros expand to calls on a
//! [`Builder`] that fill a [`NativeClass`] and a [`BuiltinElement`]; [`load`] runs them.
use crate::expression_tree::{BuiltinFunction, Unit};
use crate::langtype::{
BuiltinElement, BuiltinPropertyDefault, BuiltinPropertyInfo, BuiltinStruct, ConstantExpression,
DefaultSizeBinding, ElementDocEntry, ElementType, Function, NativeClass, Type,
};
use crate::object_tree::{Component, Element, PropertyVisibility};
use crate::typeregister::TypeRegister;
use smol_str::SmolStr;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Arc;
/// `stringify!` output of a hyphenated name, without the spaces it puts around `-`.
fn kebab(spelled: &str) -> SmolStr {
debug_assert!(!spelled.contains('_'), "`{spelled}` must be spelled with dashes");
spelled.split(' ').collect()
}
/// Joins doc lines like the parser did for `///` comments: one space after the marker is
/// dropped, lines are separated by `\n`.
fn join_docs(lines: &[&str]) -> Option<String> {
(!lines.is_empty()).then(|| {
lines.iter().map(|l| l.strip_prefix(' ').unwrap_or(l)).collect::<Vec<_>>().join("\n")
})
}
/// The default value as written after the property: a literal (`true`, `4`, `8px`, `"text"`,
/// `#00f`) or an enum value (`ImageFit.contain`). A number on an `int` property is cast, as the
/// compiler does for a binding.
fn default(ty: &Type, text: &str) -> Option<ConstantExpression> {
if text.is_empty() {
return None;
}
if text.starts_with('"') {
return Some(ConstantExpression::StringLiteral(
crate::literals::unescape_string(text).unwrap(),
));
}
let text = text.replace(' ', "");
Some(match text.as_str() {
"true" => ConstantExpression::BoolLiteral(true),
"false" => ConstantExpression::BoolLiteral(false),
color if color.starts_with('#') => {
let argb = i_slint_common::color_parsing::parse_color_literal(color).unwrap();
ConstantExpression::Cast {
from: Box::new(ConstantExpression::NumberLiteral(argb as f64, Unit::None)),
to: Type::Color,
}
}
value if value.starts_with(|c: char| c.is_ascii_alphabetic()) => {
let (qualifier, value) = value.split_once('.').unwrap();
let Type::Enumeration(enumeration) = ty else {
panic!("enum default `{qualifier}.{value}` on a property of type {ty}")
};
assert_eq!(qualifier, enumeration.name, "wrong enum in `{qualifier}.{value}`");
let value = enumeration.clone().try_value_from_string(&kebab(value)).unwrap();
ConstantExpression::EnumerationValue(value)
}
number => {
let (value, unit) =
crate::literals::parse_number_literal(SmolStr::new(number)).unwrap();
let (value, unit) = unit.normalize(value);
let number = ConstantExpression::NumberLiteral(value, unit);
match ty {
Type::Int32 => ConstantExpression::Cast { from: Box::new(number), to: Type::Int32 },
_ => number,
}
}
})
}
#[cfg(feature = "builtin-docs")]
macro_rules! docs {
($($l:literal)*) => { &[$($l),*] };
}
/// Without the feature the doc strings stay out of the binary.
#[cfg(not(feature = "builtin-docs"))]
macro_rules! docs {
($($l:literal)*) => {
&[]
};
}
#[rustfmt::skip]
macro_rules! visibility {
(in) => { PropertyVisibility::Input };
(out) => { PropertyVisibility::Output };
(in - out) => { PropertyVisibility::InOut };
(private) => { PropertyVisibility::Private };
}
/// An `@flag` of an element; a bare flag names a `BuiltinElement` field.
macro_rules! flag {
($e:ident sc) => { $e.element.slint_sc = true };
($e:ident skip_inherited) => { $e.element.docs.truncate(1) };
($e:ident expands_to_parent_geometry) => { $e.element.default_size_binding = DefaultSizeBinding::ExpandsToParentGeometry };
($e:ident implicit_size) => { $e.element.default_size_binding = DefaultSizeBinding::ImplicitSize };
($e:ident builtin_struct($s:ident)) => { $e.class.builtin_struct = Some(BuiltinStruct::$s) };
($e:ident $flag:ident) => { $e.element.$flag = true };
}
/// The members of a native item or builtin element, as calls on the builder `$e`.
macro_rules! members {
($l:ident $e:ident $(#![doc = $s:literal])*) => { $e.section(docs!($($s)*)); };
// property
($l:ident $e:ident $(#![doc = $s:literal])* $(#[doc = $d:literal])* $(@$mod:ident)*
$vis:ident $(- $vis2:ident)? property < $($ty:tt)-+ > $($name:tt)-+ $(: $default:tt $(. $($dv:tt)-+)? $($hex:literal)?)? $(<=> $($alias:tt)-+)? ;
$($rest:tt)*) => {
$e.section(docs!($($s)*));
{
let ty = $l.ty(stringify!($($ty)-+));
let default = default(&ty, stringify!($($default $(. $($dv)-+)? $($hex)?)?));
$e.property(stringify!($($name)-+), ty, visibility!($vis $(- $vis2)?), default,
None $(.or(Some(stringify!($($alias)-+))))?, &[$(stringify!($mod)),*], docs!($($d)*));
}
members!($l $e $($rest)*);
};
// property computed by a BuiltinFunction, per element or per process
($l:ident $e:ident $(#![doc = $s:literal])* $(#[doc = $d:literal])* $(@$mod:ident)*
$vis:ident property < $($ty:tt)-+ > $($name:tt)-+ { BuiltinFunction . $bf:ident } $($rest:tt)*) => {
$e.section(docs!($($s)*));
{
let mut info = BuiltinPropertyInfo::new($l.ty(stringify!($($ty)-+)));
info.property_visibility = visibility!($vis);
info.default_value = computed_default(BuiltinFunction::$bf);
$e.add(stringify!($($name)-+), info, &[$(stringify!($mod)),*], docs!($($d)*));
}
members!($l $e $($rest)*);
};
// callback
($l:ident $e:ident $(#![doc = $s:literal])* $(#[doc = $d:literal])* $(@$mod:ident)*
callback $($name:tt)-+ $(( $($n:tt : $($t:tt)-+),* ))? $(-> $($ret:tt)-+)? ; $($rest:tt)*) => {
$e.section(docs!($($s)*));
$e.function(stringify!($($name)-+), Type::Callback,
$l.function(&[$($((stringify!($n), stringify!($($t)-+))),*)?], stringify!($($($ret)-+)?)),
None, &[$(stringify!($mod)),*], docs!($($d)*));
members!($l $e $($rest)*);
};
// function, implemented by a compiler pass or by the BuiltinFunction named in its body
($l:ident $e:ident $(#![doc = $s:literal])* $(#[doc = $d:literal])* $(@$mod:ident)*
function $($name:tt)-+ ( $($n:tt : $($t:tt)-+),* ) $(-> $($ret:tt)-+)? { $(BuiltinFunction . $bf:ident)? } $($rest:tt)*) => {
$e.section(docs!($($s)*));
$e.function(stringify!($($name)-+), Type::Function,
$l.function(&[$((stringify!($n), stringify!($($t)-+))),*], stringify!($($($ret)-+)?)),
None $(.or(Some(BuiltinFunction::$bf)))?, &[$(stringify!($mod)),*], docs!($($d)*));
members!($l $e $($rest)*);
};
// accepted child elements
($l:ident $e:ident $(#![doc = $s:literal])* children : $($child:ident),+ ; $($rest:tt)*) => {
$e.section(docs!($($s)*));
$l.children(&mut $e, &[$(stringify!($child)),+]);
members!($l $e $($rest)*);
};
}
/// The default of a property a `BuiltinFunction` computes.
/// A function that takes the element computes a value per element, one that takes nothing
/// answers for the whole process.
fn computed_default(function: BuiltinFunction) -> BuiltinPropertyDefault {
if function.ty().args.is_empty() {
BuiltinPropertyDefault::RuntimeValue(function)
} else {
BuiltinPropertyDefault::ElementFunction(function)
}
}
/// A native item or builtin element being built.
struct Builder {
class: NativeClass,
element: BuiltinElement,
}
impl Builder {
/// `//!` lines, kept in the docs in source order.
fn section(&mut self, lines: &[&str]) {
if let Some(text) = join_docs(lines) {
self.element.docs.push(ElementDocEntry::Text(text));
}
}
fn add(&mut self, name: &str, mut info: BuiltinPropertyInfo, mods: &[&str], docs: &[&str]) {
info.shadowable = mods.contains(&"shadowable");
info.slint_sc = mods.contains(&"sc");
info.docs = join_docs(docs);
let name = kebab(name);
self.member_doc(name.clone());
// A property computed per element isn't a property of the native item.
match info.default_value {
BuiltinPropertyDefault::ElementFunction(_) => {
self.element.properties.insert(name, info)
}
_ => self.class.properties.insert(name, info),
};
}
/// The docs are only assembled when they reach the binary.
fn member_doc(&mut self, name: SmolStr) {
if cfg!(feature = "builtin-docs") {
self.element.docs.push(ElementDocEntry::Member(name));
}
}
#[inline(never)]
fn property(
&mut self,
name: &str,
ty: Type,
vis: PropertyVisibility,
default: Option<ConstantExpression>,
alias: Option<&str>,
mods: &[&str],
docs: &[&str],
) {
debug_assert_eq!(
mods.contains(&"deprecated"),
alias.is_some(),
"`@deprecated` on {}::{name} is only for two-way-binding aliases, and every alias must have it",
self.class.class_name
);
if let Some(target) = alias {
let name = kebab(name);
self.class.deprecated_aliases.insert(name.clone(), kebab(target));
self.member_doc(name);
return;
}
let mut info = BuiltinPropertyInfo::new(ty);
info.property_visibility = if mods.contains(&"constexpr") {
PropertyVisibility::Constexpr
} else if mods.contains(&"fake") {
PropertyVisibility::Fake
} else {
vis
};
if let Some(default) = default {
assert!(
!mods.contains(&"shadowable"),
"shadowable property {}::{name} can't have a default value as it would end up on the shadowing declaration",
self.class.class_name
);
debug_assert_eq!(
default.to_expression().ty(),
info.ty,
"the default value of {}::{name} has the wrong type",
self.class.class_name
);
info.default_value = BuiltinPropertyDefault::Expr(default);
}
self.add(name, info, mods, docs);
}
/// A callback or a function; `ty` is the `Type` constructor. A function is implemented by
/// a compiler pass, or by `builtin`.
#[inline(never)]
fn function(
&mut self,
name: &str,
ty: fn(Arc<Function>) -> Type,
function: Function,
builtin: Option<BuiltinFunction>,
mods: &[&str],
docs: &[&str],
) {
let declared_pure = mods.contains(&"pure");
let info = match builtin {
Some(builtin) => {
// The BuiltinFunction type prepends implicit ElementReference arguments.
let builtin_ty = builtin.ty();
let implicit = builtin_ty.args.len().saturating_sub(function.args.len());
debug_assert!(
builtin_ty.args.ends_with(&function.args)
&& builtin_ty.args[..implicit]
.iter()
.all(|t| matches!(t, Type::ElementReference))
&& builtin_ty.return_type == function.return_type,
"the declared signature of {}::{name} doesn't match {builtin:?}: {builtin_ty:?}",
self.class.class_name
);
let mut merged = (*builtin_ty).clone();
merged.arg_names = std::iter::repeat_n(SmolStr::default(), implicit)
.chain(function.arg_names)
.collect();
debug_assert_eq!(
declared_pure,
builtin.is_pure(),
"the 'pure' qualifier of {}::{name} doesn't match {builtin:?}",
self.class.class_name
);
// `pure` comes from the BuiltinFunction, see BuiltinPropertyInfo::pure.
let mut info = BuiltinPropertyInfo::from(builtin);
info.ty = ty(Arc::new(merged));
info
}
None => {
let mut info = BuiltinPropertyInfo::new(ty(Arc::new(function)));
info.pure = declared_pure;
info
}
};
self.add(name, info, mods, docs);
}
}
struct Loader<'a> {
register: &'a mut TypeRegister,
/// The native items by name, each with the properties and docs of its whole parent chain.
items: HashMap<SmolStr, (Arc<NativeClass>, BuiltinElement)>,
/// The builtin elements by name.
elements: HashMap<SmolStr, Rc<BuiltinElement>>,
}
impl Loader<'_> {
/// A type as written: `length`, `[MenuEntry]`, or nothing for `void`.
fn ty(&self, text: &str) -> Type {
if text.is_empty() {
return Type::Void;
}
if let Some(inner) = text.strip_prefix('[').and_then(|t| t.strip_suffix(']')) {
return Type::Array(Arc::new(self.ty(inner)));
}
let ty = self.register.lookup(&kebab(text));
assert!(ty != Type::Invalid, "unknown type `{text}` in a builtin element");
ty
}
/// The signature of a callback or function from its `(name: type, ..)` and return type.
fn function(&self, args: &[(&str, &str)], ret: &str) -> Function {
Function {
return_type: self.ty(ret),
args: args.iter().map(|(_, t)| self.ty(t)).collect(),
arg_names: args.iter().map(|(n, _)| kebab(n)).collect(),
}
}
fn item_chain(&self, name: &str) -> &(Arc<NativeClass>, BuiltinElement) {
self.items
.get(name)
.unwrap_or_else(|| panic!("native item `{name}` must be declared before its use"))
}
#[inline(never)]
fn item(&self, name: &str, parent: Option<&str>) -> Builder {
let mut class = NativeClass::new(name);
let mut element = BuiltinElement::default();
if let Some(parent) = parent {
let (parent_class, chain) = self.item_chain(parent);
class.parent = Some(parent_class.clone());
element.properties = chain.properties.clone();
element.docs = chain.docs.clone();
}
Builder { class, element }
}
fn finish_item(&mut self, mut e: Builder) {
e.element.properties.extend(e.class.properties.clone());
self.items.insert(e.class.class_name.clone(), (Arc::new(e.class), e.element));
}
#[inline(never)]
fn element(&self, name: &str, docs: &[&str]) -> Builder {
let mut e = self.item(name, None);
if cfg!(feature = "builtin-docs") {
e.element.docs.push(ElementDocEntry::Text(join_docs(docs).unwrap_or_default()));
}
e
}
/// The native item the element lowers to. The element gets the properties and docs of the
/// item and of its parents.
fn base(&self, e: &mut Builder, item: &str) {
let (class, chain) = self.item_chain(item);
e.element.properties.extend(chain.properties.clone());
e.element.docs.extend(chain.docs.iter().cloned());
e.class.parent = Some(class.clone());
}
/// The accepted child elements, which can only be used within this one.
fn children(&mut self, e: &mut Builder, names: &[&str]) {
let parent = e.class.class_name.clone();
for name in names {
let name = SmolStr::new(name);
if name == parent {
e.element.additional_accept_self = true;
} else {
let child = self.elements.get(&name).unwrap_or_else(|| {
panic!(
"`{name}` must be declared before the builtin elements using it as a child"
)
});
e.element.additional_accepted_child_types.insert(name.clone(), child.clone());
}
self.register.context_restricted_types.entry(name).or_default().insert(parent.clone());
}
}
fn finish_element(&mut self, e: Builder) {
let mut builtin = e.element;
builtin.name = e.class.class_name.clone();
builtin.properties.extend(e.class.properties.clone());
// An element without members of its own is the native item it lowers to.
let own_members = !e.class.properties.is_empty()
|| !e.class.deprecated_aliases.is_empty()
|| e.class.builtin_struct.is_some();
builtin.native_class = match e.class.parent.clone() {
Some(item) if !own_members => item,
_ => Arc::new(e.class),
};
let builtin = Rc::new(builtin);
if builtin.is_global {
let global = Rc::new(Component {
id: builtin.name.clone(),
root_element: Rc::new(RefCell::new(Element {
base_type: ElementType::Builtin(builtin.clone()),
..Default::default()
})),
..Default::default()
});
global.root_element.borrow_mut().enclosing_component = Rc::downgrade(&global);
self.register.add(global);
}
self.elements.insert(builtin.name.clone(), builtin);
}
}
/// The declarations. `item!` declares a runtime item, `element!` an element of the language.
fn build(l: &mut Loader) {
macro_rules! item {
($Name:ident $(: $Parent:ident)? { $($body:tt)* }) => {{
let mut e = l.item(stringify!($Name), None $(.or(Some(stringify!($Parent))))?);
members!(l e $($body)*);
l.finish_item(e);
}};
}
macro_rules! element {
($(#[doc = $d:literal])* $(@$flag:ident $(($arg:ident))?)* $Name:ident $(: $Item:ident)? $({ $($body:tt)* })?) => {{
let mut e = l.element(stringify!($Name), docs!($($d)*));
$( l.base(&mut e, stringify!($Item)); )?
$( flag!(e $flag $(($arg))?); )*
members!(l e $($($body)*)?);
l.finish_element(e);
}};
}
item! { Empty { } }
element! {
@is_internal
Empty: Empty
}
item! { Rectangle: Empty {
/// The background brush of this `Rectangle`, filling its geometry. \{#sls.ref.rectangle.background}
///
/// Without a `background` and without a border, the `Rectangle` paints nothing. \{#sls.ref.rectangle.empty}
///
/// A translucent background lets the content underneath show through. \{#sls.ref.rectangle.translucent}
///
/// ```slint imageAlt="rectangle background" width="200" height="400"
/// property <brush> rainbow-gradient: @linear-gradient(40deg, rgba(255, 0, 0, 1) 0%, rgba(255, 154, 0, 1) 10%, rgba(208, 222, 33, 1) 20%,rgba(79, 220, 74, 1) 30%, rgba(63, 218, 216, 1) 40%, rgba(47, 201, 226, 1) 50%, rgba(28, 127, 238, 1) 60%, rgba(95, 21, 242, 1) 70%, rgba(186, 12, 248, 1) 80%, rgba(251, 7, 217, 1) 90%, rgba(255, 0, 0, 1) 100%);
///
/// Rectangle {
/// x: 10px;
/// y: 10px;
/// width: 180px;
/// height: 180px;
/// background: #315afd;
/// }
///
///
/// Rectangle {
/// x: 10px;
/// y: 210px;
/// width: 180px;
/// height: 180px;
/// background: rainbow-gradient;
/// }
/// ```
/// \default transparent
@sc in property <brush> background;
@deprecated in property <brush> color <=> background;
} }
item! { BasicBorderRectangle: Rectangle {
/// ```slint imageAlt="rectangle border-color" width="200" height="200"
/// Rectangle {
/// width: 200px;
/// height: 200px;
/// border-width: 10px;
/// border-color: lightslategray;
/// }
/// ```
/// The color of the border.
/// :::caution[Caution]
/// The default `border-width` is `0px`, so the border is invisible. After setting a color also ensure that the `border-width` is set to a non-zero value.
/// :::
/// \default transparent
in property <brush> border-color;
/// ```slint imageAlt="rectangle border-width" width="200" height="200"
/// Rectangle {
/// width: 200px;
/// height: 200px;
/// border-width: 30px;
/// border-color: lightslategray;
/// }
/// ```
/// The width of the border.
/// \default 0
in property <length> border-width;
//! ### clip
//! <SlintProperty propName="clip" typeName="bool" defaultValue="false">
//! ```slint imageAlt="rectangle clip" width="200" height="400"
//! // clip: false; the default
//! Rectangle {
//! x: 50px; y: 50px;
//! width: 150px;
//! height: 150px;
//! background: darkslategray;
//! # Text {
//! # text: "clip: false";
//! # font-size: 20pt;
//! # color: white;
//! # }
//! Rectangle {
//! x: -40px; y: -40px;
//! width: 100px;
//! height: 100px;
//! background: lightslategray;
//! }
//! }
//!
//! // clip: true; Clips the children of this Rectangle
//! Rectangle {
//! x: 50px; y: 250px;
//! width: 150px;
//! height: 150px;
//! background: darkslategray;
//! clip: true;
//! # Text {
//! # text: "clip: true";
//! # font-size: 20pt;
//! # color: white;
//! # }
//! Rectangle {
//! x: -40px; y: -40px;
//! width: 100px;
//! height: 100px;
//! background: lightslategray;
//! }
//! }
//!
//! ```
//! By default, when child elements are outside the bounds of a parent,
//! they are still shown. When this property is set to `true`, the children
//! of this `Rectangle` are clipped and only the contents inside the elements bounds are shown.
//! </SlintProperty>
//!
//!
//! ## Border Radius Properties
/// The size of the radius. This single value is applied to all four corners.
/// \default 0
in property <length> border-radius;
} }
item! { BorderRectangle: BasicBorderRectangle {
//! To target specific corners with different values use the following properties:
///
in property <length> border-top-left-radius;
///
in property <length> border-top-right-radius;
///
in property <length> border-bottom-left-radius;
///
in property <length> border-bottom-right-radius;
//! ## Drop Shadows
//!
//! To achieve the graphical effect of a visually elevated shape that shows a shadow effect underneath the frame of
//! an element, it's possible to set the following `drop-shadow` properties:
//!
//! The CSS equivalent is `box-shadow`: `box-shadow: 2px 2px 4px 1px black` translates to
//! `drop-shadow-offset-x: 2px; drop-shadow-offset-y: 2px; drop-shadow-blur: 4px;
//! drop-shadow-spread: 1px; drop-shadow-color: black;`.
//!
//! ### drop-shadow-blur
//! <SlintProperty propName="drop-shadow-blur" typeName="length"/>
//! The radius of the shadow that also describes the level of blur applied to the shadow. Negative values are ignored and zero means no blur.
//!
//! ### drop-shadow-color
//! <SlintProperty propName="drop-shadow-color" typeName="color"/>
//! The base color of the shadow to use. Typically that color is the starting color of a gradient that fades into transparency.
//!
//! ### drop-shadow-offset-x
//! <SlintProperty propName="drop-shadow-offset-x" typeName="length"/>
//! The horizontal distance of the shadow from the element's frame.
//!
//!
//! ### drop-shadow-offset-y
//! <SlintProperty propName="drop-shadow-offset-y" typeName="length"/>
//! The vertical distance of the shadow from the element's frame.
//!
//! ### drop-shadow-spread
//! <SlintProperty propName="drop-shadow-spread" typeName="length"/>
//! Grows (positive) or shrinks (negative) the shadow shape on all sides before the blur is applied.
//! Equivalent to the spread radius in CSS `box-shadow`. Currently only supported by the Skia renderer.
//!
//! ## Inner Shadows
//!
//! Inner shadows are rendered inside the element's geometry (inverted from drop shadows), giving
//! the appearance of an inwards-cast shadow. They follow the same parameters as drop shadows.
//! Currently only supported by the Skia renderer.
//!
//! The CSS equivalent is `box-shadow` with the `inset` keyword: `box-shadow: inset 2px 2px 4px 1px black`
//! translates to `inner-shadow-offset-x: 2px; inner-shadow-offset-y: 2px; inner-shadow-blur: 4px;
//! inner-shadow-spread: 1px; inner-shadow-color: black;`.
//!
//! ### inner-shadow-blur
//! <SlintProperty propName="inner-shadow-blur" typeName="length"/>
//! The blur radius of the inner shadow.
//!
//! ### inner-shadow-color
//! <SlintProperty propName="inner-shadow-color" typeName="color"/>
//! The base color of the inner shadow.
//!
//! ### inner-shadow-offset-x
//! <SlintProperty propName="inner-shadow-offset-x" typeName="length"/>
//! Horizontal offset of the inner shadow inside the element.
//!
//! ### inner-shadow-offset-y
//! <SlintProperty propName="inner-shadow-offset-y" typeName="length"/>
//! Vertical offset of the inner shadow inside the element.
//!
//! ### inner-shadow-spread
//! <SlintProperty propName="inner-shadow-spread" typeName="length"/>
//! Positive spread thickens the shadow band along the element's interior boundary; negative spread
//! thins it.
} }
element! {
/// By default, a `Rectangle` is just an empty item that shows nothing. By setting a color or configuring a border,
/// it's then possible to draw a rectangle on the screen. \{#sls.meta.rectangle.purpose}
///
/// <NotInSC>
/// When not part of a layout, its width and height default to 100% of the parent element.
/// </NotInSC>
///
/// ```slint playground imageAlt="rectangle example"
/// export component ExampleRectangle inherits Window {
/// width: 200px; height: 800px; background: transparent;
///
/// Rectangle {
/// x: 10px; y: 10px;
/// width: 180px;
/// height: 180px;
/// background: #315afd;
/// }
///
/// // Rectangle with a border
/// Rectangle {
/// x: 10px; y: 210px;
/// width: 180px;
/// height: 180px;
/// background: green;
/// border-width: 2px;
/// border-color: red;
/// }
///
/// // Transparent Rectangle with a border and a radius
/// Rectangle {
/// x: 10px; y: 410px;
/// width: 180px;
/// height: 180px;
/// border-width: 4px;
/// border-color: black;
/// border-radius: 30px;
/// }
///
/// // A radius of width/2 makes it a circle
/// Rectangle {
/// x: 10px; y: 610px;
/// width: 180px;
/// height: 180px;
/// background: yellow;
/// border-width: 2px;
/// border-color: blue;
/// border-radius: self.width/2;
/// }
/// }
/// ```
/// \group:elements
@sc @expands_to_parent_geometry
Rectangle: BorderRectangle
}
item! { ImageItem: Empty {
in property <length> width;
in property <length> height;
/// When set, the image is used as an alpha mask and is drawn in the given color (or with the gradient).
/// ```slint imageAlt="image example" width="300" height="200"
/// Image {
/// source: @image-url("slint-logo-simple-dark.png");
/// colorize: darkorange;
/// }
/// ```
in property <brush> colorize;
/// The [image](/reference/property-types/images/) to draw, created with
/// [`@image-url()`](/reference/language/expressions/#sls.expr.image.form)
/// or set by the application: by default no image, drawing
/// nothing. \{#sls.ref.image.source}
///
/// Access an `image`'s source dimension using its `source.width` and
/// `source.height` properties. \{#sls.ref.image.source.dimensions}
///
/// ```slint
/// export component Example inherits Window {
/// in property <image> some_image: @image-url("images/logo.png");
///
/// out property <int> image-width: some_image.width;
/// out property <int> image-height: some_image.height;
/// }
/// ```
@sc in property <image> source;
/// ```slint imageAlt="image fill example" width="300" height="200"
/// Image {
/// width: 200px; height: 50px;
/// source: @image-url("mini-banner.png");
/// image-fit: fill;
/// }
/// ```
///
/// ```slint imageAlt="image contain example" width="300" height="200"
/// Image {
/// width: 250px; height: 40px;
/// source: @image-url("mini-banner.png");
/// image-fit: contain;
/// }
/// ```
///
/// ```slint imageAlt="image cover example" width="300" height="200"
/// Image {
/// width: 250px; height: 250px;
/// source: @image-url("mini-banner.png");
/// image-fit: cover;
/// }
/// ```
///
/// ```slint imageAlt="image preserve example" width="400" height="400"
/// Image {
/// width: 400px; height: 400px;
/// source: @image-url("mini-banner.png");
/// image-fit: preserve;
/// }
/// ```
/// \default `contain` when the `Image` element is part of a layout, `fill` otherwise
in property <ImageFit> image-fit;
/// ```slint imageAlt="image smooth example" width="300" height="300"
/// Image {
/// width: 800px;
/// source: @image-url("mini-banner.png");
/// image-rendering: smooth;
/// }
/// ```
///
/// ```slint imageAlt="image pixelated example" width="300" height="300"
/// Image {
/// width: 800px;
/// source: @image-url("mini-banner.png");
/// image-rendering: pixelated;
/// }
/// ```
/// \default smooth
in property <ImageRendering> image-rendering;
@deprecated in property <angle> rotation-angle <=> transform-rotation;
} }
item! { ClippedImage: ImageItem {
/// The horizontal alignment of the image within the element.
/// \default center
in property <ImageHorizontalAlignment> horizontal-alignment;
/// The vertical alignment of the image within the element.
/// \default center
in property <ImageVerticalAlignment> vertical-alignment;
//! ## Image Tiling
/// How the image is tiled horizontally.
/// \default none
in property <ImageTiling> horizontal-tiling;
/// ```slint imageAlt="image horizontal tiling repeat example" width="400" height="400"
/// Image {
/// width: 400px;
/// height: 400px;
/// source: @image-url("slint-logo.png");
/// horizontal-tiling: repeat;
/// }
/// ```
///
/// ```slint imageAlt="image horizontal tiling round example" width="400" height="400"
/// Image {
/// width: 400px;
/// height: 400px;
/// source: @image-url("slint-logo.png");
/// horizontal-tiling: round;
/// }
/// ```
/// ```slint imageAlt="image vertical tiling repeat example" width="400" height="400"
/// Image {
/// width: 400px;
/// height: 400px;
/// source: @image-url("slint-logo.png");
/// vertical-tiling: repeat;
/// }
/// ```
///
/// ```slint imageAlt="image vertical tiling round example" width="400" height="400"
/// Image {
/// width: 400px;
/// height: 400px;
/// source: @image-url("slint-logo.png");
/// vertical-tiling: round;
/// }
/// ```
///
/// ```slint imageAlt="image vertical and horizontal tiling round example" width="400" height="400"
/// Image {
/// width: 400px;
/// height: 400px;
/// source: @image-url("slint-logo.png");
/// vertical-tiling: round;
/// horizontal-tiling: round;
/// }
/// ```
/// \default none
in property <ImageTiling> vertical-tiling;
// TODO: sets both horizontal-tiling and vertical-tiling at the same time.
// in property <ImageTiling> tiling;
//! ## Source Clip
///
in property <int> source-clip-x;
///
in property <int> source-clip-y;
/// \default source.width - source.clip-x
in property <int> source-clip-width;
/// \default source.height - source.clip-y
in property <int> source-clip-height;
//! Properties in source image coordinates that define the region of the source image that is rendered.
//! By default the entire source image is visible:
} }
element! {
/// ```slint imageAlt="image example" width="300" height="200"
/// Image {
/// source: @image-url("mini-banner.png");
/// }
/// ```
///
/// Use the `Image` element to display an
/// [image](/reference/property-types/images/). \{#sls.meta.image.purpose}
///
/// <OnlyInSC>
/// The element draws the image of its `source` property pixel for pixel:
/// the image's top-left pixel is at the element's position, and one image
/// pixel covers one frame-buffer pixel, without scaling. \{#sls.ref.image.draw}
///
/// The element is always the size of its source image: `width` and `height`
/// hold the dimensions of that image, and setting them is an
/// error. \{#sls.ref.image.size}
/// </OnlyInSC>
///
/// \footer
/// <NotInSC>
/// ## Accessibility
///
/// ### Alternative text
///
/// Consider giving an alternative text description of your image by setting the `accessible-label` property:
///
/// ```slint
/// Image {
/// width: 100px;
/// height: 100px;
/// source: @image-url("slint-logo.png");
/// accessible-label: "Slint logo";
/// }
/// ```
///
/// ### Filtering out images for users of assistive technologies
///
/// By default, images have the `accessible-role` property set to `image`.
/// If your image is purely decorative and doesn't convey any information,
/// consider removing it from the accessibility tree:
///
/// ```slint
/// Image {
/// source: @image-url("mini-banner.png");
/// accessible-role: none;
/// }
/// ```
/// </NotInSC>
/// \group:elements
@sc @implicit_size
Image: ClippedImage
}
item! { ComponentContainer: Empty {
in property <component-factory> component-factory;
out property <bool> has-component;
in-out property <length> width;
in-out property <length> height;
} }
element! {
@accepts_focus
ComponentContainer: ComponentContainer
}
item! { Transform: Empty {
in property <angle> transform-rotation;
in property <percent> transform-scale-x;
in property <percent> transform-scale-y;
in property <Point> transform-origin;
} }
element! {
@is_internal @expands_to_parent_geometry
Transform: Transform
}
item! { SimpleText: Empty {
in property <length> width;
in property <length> height;
/// The color of the text.
///
/// ```slint "color: #3586f4;" imageAlt="text color" width="200" height="200" needsBackground
/// Text {
/// text: "Hello";
/// color: #3586f4;
/// font-size: 40pt;
/// }
/// ```
/// \default <depends on theme>
in property <brush> color; // StyleMetrics.default-text-color set in apply_default_properties_from_style
/// The font size of the text.
///
/// ```slint "font-size: 70pt;" imageAlt="text font-size" width="200" height="200" needsBackground
/// Text {
/// text: "Big";
/// color: black;
/// font-size: 70pt;
/// }
/// ```
in property <length> font-size;
/// The weight of the font. The values range from 100 (lightest) to 900 (thickest). 400 is the normal weight. Use the <Link type="FontWeight" /> namespace for predefined constants.
///
/// ```slint 'font-weight: FontWeight.extra-bold;' imageAlt="text font-weight" width="200" height="200" needsBackground
/// Text {
/// text: "BOLD";
/// color: black;
/// font-size: 30pt;
/// font-weight: FontWeight.extra-bold;
/// }
/// ```
in property <int> font-weight;
/// ```slint "horizontal-alignment: left;" imageAlt="text-horizontal-alignment" width="200" height="200" needsBackground
/// Text {
/// x: 0;
/// text: "Hello";
/// color: black;
/// font-size: 40pt;
/// horizontal-alignment: left;
/// }
/// ```
in property <TextHorizontalAlignment> horizontal-alignment;
/// The maximum number of lines to display. Wrapped lines count towards the limit, and
/// with `overflow` set to `elide`, the ellipsis is placed on the last visible line.
/// Values less than or equal to zero don't limit the number of lines.
/// \default 0
in property <int> max-lines;
/// The text rendered.
/// \default ""
in property <string> text;
/// The vertical alignment of the text.
in property <TextVerticalAlignment> vertical-alignment;
@deprecated in property <angle> rotation-angle <=> transform-rotation;
} }
item! { ComplexText: SimpleText {
/// The name of the font family selected for rendering the text.
///
/// ```slint 'font-family: "Comic Sans MS";' imageAlt="text font-family" width="200" height="200" needsBackground
/// Text {
/// text: "CoMiC!";
/// color: black;
/// font-size: 40pt;
/// font-family: "Comic Sans MS";
/// }
/// ```
///
/// :::note[Note]
/// Make sure the font is loaded before using it in a `Text` element.
/// See <Link type="FontHandling" /> for more.
/// :::
in property <string> font-family;
/// Whether or not the font face should be drawn italicized or not.
///
/// ```slint "font-italic: true;" imageAlt="text font-family" width="200" height="200" needsBackground
/// Text {
/// text: "Italic";
/// color: black;
/// font-italic: true;
/// font-size: 40pt;
/// }
/// ```
/// \default false
in property <bool> font-italic;
/// How the text should behave when it exceeds the available space.
in property <TextOverflow> overflow;
/// ```slint "wrap: word-wrap;" imageAlt="wrap" width="200" height="200" needsBackground
/// Text {
/// text: "This paragraph breaks into multiple lines of text";
/// font-size: 20pt;
/// wrap: word-wrap;
/// width: 180px;
/// }
/// ```
in property <TextWrap> wrap;
/// The letter spacing allows changing the spacing between the glyphs. A positive value increases the spacing and a negative value decreases the distance.
/// ```slint "letter-spacing: 4px;" imageAlt="text-horizontal-alignment" width="200" height="200" needsBackground
/// Text {
/// text: "Spaced!";
/// color: black;
/// font-size: 30pt;
/// letter-spacing: 4px;
/// }
/// ```
in property <length> letter-spacing;
/// The line height as a unitless factor (or a percentage: `150%` equals `1.5`) applied to
/// the font's natural line height (ascent + descent + line gap). The default of `1` keeps
/// the natural line height; larger values spread the lines apart, smaller values pull them
/// together, and `0` collapses them onto each other. Negative or non-numeric values behave
/// like `1`. Unlike CSS `line-height`, the factor is relative to the natural line height,
/// not the font size, and keyword or length values aren't supported.
///
/// ```slint "line-height-factor: 1.5;" imageAlt="text with increased line height" width="200" height="200" needsBackground
/// Text {
/// text: "Two lines\nof text";
/// color: black;
/// font-size: 30pt;
/// line-height-factor: 1.5;
/// }
/// ```
/// \default 1
in property <float> line-height-factor: 1;
/// The brush used for the text outline.
/// ```slint "stroke: darkblue;" imageAlt="text stroke" width="300" height="200" needsBackground
/// Text {
/// text: "Stroke";
/// stroke-width: 2px;
/// stroke: darkblue;
/// stroke-style: center;
/// font-size: 80px;
/// color: lightblue;
/// }
/// ```
in property <brush> stroke;
/// The width of the text outline. If the width is zero, then a hairline stroke (1 physical pixel) will be rendered.
in property <length> stroke-width;
/// ```slint "stroke-style: center;" imageAlt="stroke-style" width="200" height="200" needsBackground
/// Text {
/// text: "Style";
/// stroke-width: 2px;
/// stroke: #3586f4;
/// stroke-style: center;
/// font-size: 60px;
/// color: white;
/// }
/// ```
in property <TextStrokeStyle> stroke-style;
/// The design metrics of the font scaled to the font pixel size used by the element.
out property <FontMetrics> font-metrics { BuiltinFunction.ItemFontMetrics }
} }
element! {
/// ```slint playground
/// // text-example.slint
/// export component TextExample inherits Window {
/// // Text colored red.
/// Text {
/// x:0; y:0;
/// text: "Hello World";
/// color: red;
/// }
///
/// // This paragraph breaks into multiple lines of text.
/// Text {
/// x:0; y: 30px;
/// text: "This paragraph breaks into multiple lines of text";
/// wrap: word-wrap;
/// width: 150px;
/// height: 100%;
/// }
/// }
/// ```
///
/// A `Text` element for displaying text.
///
/// By default, the `min-width`, `min-height`, `preferred-width`, and `preferred-height`
/// of a `Text` element are set to fit the full text as if it were displayed on a single line
/// (unless the text contains explicit line breaks).
/// However, if the `wrap` property is set to `word-wrap`, and/or if the `overflow` property is set to `elide`,
/// the `min-width` is reduced to zero, allowing the text to wrap or be elided,
/// while the `preferred-width` and `preferred-height` remain unchanged.
///
/// \footer
/// ## Accessibility
///
/// By default, `Text` elements have the following accessibility properties set:
///
/// - `accessible-role: text;`
/// - `accessible-label: text;`
/// \group:elements
@implicit_size
Text: ComplexText
}
item! { StyledTextItem: Empty {
in property <length> width;
in property <length> height;
/// The default color of the text, used when no color is specified via markup.
/// \default <depends on theme>
in property <brush> default-color;
/// The default font family used to render the text, when no font is specified via markup. If left empty, the value falls back to the enclosing `Window`'s `default-font-family`.
in property <string> default-font-family;
/// The default font size used to render the text, when no size is specified via markup. If unset (or zero), the value falls back to the enclosing `Window`'s `default-font-size`.
in property <length> default-font-size;
/// The horizontal alignment of the text.
in property <TextHorizontalAlignment> horizontal-alignment;
/// The color used for rendering links in the text.
in property <color> link-color: #00f;
/// The maximum number of lines to display. Wrapped lines count towards the limit.
/// Values less than or equal to zero don't limit the number of lines.
/// \default 0
in property <int> max-lines;
/// The styled text rendered, using CommonMark markup with additional HTML tags for styling.
/// \default ""
in property <styled-text> text;
/// The vertical alignment of the text.
in property <TextVerticalAlignment> vertical-alignment;
/// A callback that's invoked when a link in the text is clicked. The parameter contains the clicked link as a string.
callback link-clicked(link: string);
} }
element! {
/// The `StyledText` element renders text with various styling and interactive properties, such as bolded, underlined and colored sections as well as HTTP links. It is based on a subset of the [commonmark](https://commonmark.org/) spec.
///
/// ```slint imageAlt="Styled Text Example" width="200" height="200" scale="3"
/// export component Example inherits Window {
/// in property <string> value: 55;
/// width: 200px;
/// height: 200px;
/// StyledText {
/// text: @markdown("This is a piece of <u>Styled Text</u>\n"
/// "with a red value inserted:"
/// "<font color=\"red\">\{value}</font>");
/// }
/// }
/// ```
///
///
/// ## Features
///
/// Styled Text supports the following features:
///
/// Feature | Method
/// ---------------|-------
/// Italics | Builtin
/// Strikethroughs | Builtin
/// Inline code | Builtin
/// Links | Builtin
/// Ordered and unordered lists | Builtin
/// Underlines | `<u>` HTML tag
/// Text Colors |`<font color="...">` HTML tags
///
/// ### Currently Unsupported
///
/// Feature |
/// -----------------|
/// Headings |
/// Images |
/// Tables |
/// Block Quotes |
/// Subscripts |
/// Superscripts |
/// Horizontal Rules |
/// Footnotes |
/// Math expressions |
/// Other HTML tags |
/// \group:elements
@implicit_size
StyledText: StyledTextItem
}
item! { TouchArea {
/// When disabled, the `TouchArea` doesn't recognize any touch or mouse events and they are
/// passed through to elements underneath.
///
/// ```slint playground imageAlt="Basic syntax" width="200" height="100" scale="2"
/// import { Button, CheckBox } from "std-widgets.slint";
///
/// export component Example inherits Window {
/// width: 200px; height: 100px;
///
/// VerticalLayout {
/// Rectangle {
/// Button {
/// text: "Try to press me";
/// }
/// TouchArea {
/// enabled: event-blocker.checked;
/// }
/// }
/// event-blocker := CheckBox {
/// text: "Block Access";
/// }
/// }
/// }
/// ```
///
/// :::note{Note}
/// When `enabled` is set to false while the `TouchArea` is pressed, `pointer-event` will be
/// invoked with `PointerEventKind.Cancel`, and the `pressed` and `has-hover` properties will
/// be reset to `false`.
/// :::
in property <bool> enabled: true;
/// Set to true when the mouse is over the `TouchArea` area.
out property <bool> has-hover;
/// The mouse cursor when the mouse is hovering the `TouchArea`.
in property <MouseCursor> mouse-cursor;
/// Set by the `TouchArea` to the position of the mouse within it.
out property <length> mouse-x;
/// Set by the `TouchArea` to the position of the mouse within it.
out property <length> mouse-y;
/// Set by the `TouchArea` to the position of the mouse at the moment it was last pressed.
out property <length> pressed-x;
/// Set by the `TouchArea` to the position of the mouse at the moment it was last pressed.
out property <length> pressed-y;
/// Set to `true` by the `TouchArea` when the mouse is pressed over it.
out property <bool> pressed;
/// Invoked when clicked: A finger or the left mouse button is pressed, then released on this element. \{#sls.ref.toucharea.clicked}
///
/// <OnlyInSC>
/// The Touch Input chapter specifies when a press and a release count as a click. \{#sls.ref.toucharea.clicked.input}
/// </OnlyInSC>
@sc callback clicked;
/// Invoked when double-clicked. The left mouse button is pressed and released twice on this element in a short
/// period of time, or the same is done with a finger. The `clicked()` callbacks will be triggered before the `double-clicked()` callback is triggered.
callback double-clicked;
/// The mouse or finger has been moved. This will only be called if the mouse is also pressed or the finger continues to touch
/// the display. See also **pointer-event(PointerEvent)**.
callback moved;
/// <PointerEvent />
callback pointer-event(event: PointerEvent);
/// Invoked when the mouse wheel was rotated or another scroll gesture was made.
/// The `PointerScrollEvent` argument contains information about how much to scroll in what direction.
/// <PointerScrollEvent />
/// The returned `EventResult`indicates whether to accept or ignore the event. Ignored events are
/// forwarded to the parent element.
/// <EventResult />
callback scroll-event(event: PointerScrollEvent) -> EventResult;
} }
element! {
/// Use `TouchArea` to control what happens when the region it covers is touched or interacted with
/// using the mouse. \{#sls.meta.toucharea.purpose}
///
/// When not part of a layout, its width or height default to 100% of the parent element. \{#sls.ref.toucharea.size}
///
/// <OnlyInSC>
/// Of the members of `TouchArea`, only `clicked` and the geometry properties are part of Slint SC. \{#sls.ref.toucharea.members}
/// </OnlyInSC>
///
/// <NotInSC>
/// ```slint playground
/// export component Example inherits Window {
/// width: 200px;
/// height: 100px;
/// area := TouchArea {
/// width: parent.width;
/// height: parent.height;
/// clicked => {
/// rect2.background = #ff0;
/// }
/// }
/// Rectangle {
/// x:0;
/// width: parent.width / 2;
/// height: parent.height;
/// background: area.pressed ? blue: red;
/// }
/// rect2 := Rectangle {
/// x: parent.width / 2;
/// width: parent.width / 2;
/// height: parent.height;
/// }
/// }
/// ```
/// </NotInSC>
/// \group:gestures
@sc @expands_to_parent_geometry
TouchArea: TouchArea
}
item! { KeyBinding {
/// The <Link type="keys" label="keys" /> to match against incoming key events.
in property <keys> keys;
/// Whether this KeyBinding is currently enabled. Disabled KeyBinding elements don't consume key events and never invoke their `activated()` callback.
in property <bool> enabled: true;
/// Invoked when the parent `FocusScope` receives a key event that matches the `keys` of this `KeyBinding`.
callback activated;
} }
element! {
/// Place `KeyBinding` elements inside a `FocusScope` to declare keyboard shortcuts.
/// KeyBindings use **logical keys**, based on the character a key produces, not physical key positions.
///
/// See <Link type="KeyBindingOverview" label="Key Bindings"/> for details.
@is_non_item_type
KeyBinding: KeyBinding
}
item! { FocusScope {
/// Is `true` when the element has keyboard focus.
out property <bool> has-focus;
/// When false, the FocusScope will not accept focus, neither via click nor via tab focus traversal, not even programmatically.
///
/// A parent `FocusScope` will still receive key events from child `FocusScope`s that were rejected, even if `enabled` is set to false.
in property <bool> enabled: true;
/// When true, the `FocusScope` will make itself the focused element when clicked.
///
/// This property has no effect if the `enabled` property is set to false.
in property <bool> focus-on-click: true;
/// When true, the `FocusScope` will accept focus as part of the tab focus traversal.
///
/// This property has no effect if the `enabled` property is set to false.
in property <bool> focus-on-tab-navigation: true;
//! ## Functions
//!
//! ### focus()
//! Call this function to transfer keyboard focus to this `FocusScope`, to receive future <Link type="KeyEvent" />s.
//!
//! ### clear-focus()
//! Call this function to remove keyboard focus from this `FocusScope` if it currently has the focus. See also <Link type="FocusHandling" />.
/// This function is called during key event handling, *before* `key-pressed` is called. Use this to intercept key press events. The returned <Link type="EventResult" />
/// indicates whether to accept or reject the event. Rejected events are forwarded to the parent element.
callback capture-key-pressed(event: KeyEvent) -> EventResult;
/// This function is called during key event handling, *before* `key-released` is called. Use this to intercept key release events. The returned <Link type="EventResult" />
/// indicates whether to accept or reject the event. Rejected events are forwarded to the parent element.
callback capture-key-released(event: KeyEvent) -> EventResult;
/// Invoked when a key is pressed, the argument is a <Link type="KeyEvent" /> struct. The returned <Link type="EventResult" />
/// indicates whether to accept or reject the event. Rejected events are forwarded to the parent element.
callback key-pressed(event: KeyEvent) -> EventResult;
/// Invoked when a key is released, the argument is a <Link type="KeyEvent" /> struct. The returned <Link type="EventResult" />
/// indicates whether to accept or reject the event. Rejected events are forwarded to the parent element.
callback key-released(event: KeyEvent) -> EventResult;
/// Invoked when the focus on the `FocusScope` has changed. The argument is a a <Link type="FocusReason" /> enum containing the reason for focus change.
callback focus-changed-event(reason: FocusReason);
/// Invoked when the `FocusScope` gains focus. The argument is a a <Link type="FocusReason" /> enum containing the reason for focus gain.
callback focus-gained(reason: FocusReason);
/// Invoked when the `FocusScope` loses focus. The argument is a a <Link type="FocusReason" /> enum containing the reason for focus loss.
callback focus-lost(reason: FocusReason);
} }
element! {
/// ```slint playground
/// export component Example inherits Window {
/// width: 100px;
/// height: 100px;
/// forward-focus: my-key-handler;
/// my-key-handler := FocusScope {
/// key-pressed(event) => {
/// debug(event.text);
/// if (event.modifiers.control) {
/// debug("control was pressed during this event");
/// }
/// if (event.text == Key.Escape) {
/// debug("Esc key was pressed")
/// }
/// accept
/// }
///
/// KeyBinding {
/// keys: @keys(Control + X);
/// activated => {
/// debug("Control + X pressed")
/// }
/// }
/// }
/// }
/// ```
///
/// The `FocusScope` can react to <Link type="KeyBindingOverview" label="keyboard shortcuts"/> using the <Link type="KeyBinding" label="KeyBinding element"/>, and exposes callbacks to handle key events manually.
/// Note that `FocusScope` will only handle key events when it either `has-focus`, or when it surrounds another FocusScope that `has-focus` (see [Key Event Delivery](#key-event-delivery))
///
/// The <Link type="KeyEvent" /> has a text property, which is a character of the key entered.
/// When a non-printable key is pressed, the character will be either a control character,
/// or it will be mapped to a private unicode character. The mapping of these non-printable, special characters is available in the <Link type="KeyEvent"/> namespace
///
/// ## Key Event Delivery
///
/// Key events are delivered to the element that `has-focus`.
///
/// Before attempting to deliver the `KeyEvent`, it is checked whether some other element wants to intercept the `KeyEvent`.
/// Visiting all the elements starting at the Window, going down toward the focused element, `capture_key_pressed` or `capture_key_released` is called.
/// If any of these returns `EventResult::accept`, then key event processing stops at this point. If `EventResult::reject` is returned,
/// then event delivery continues.
///
/// If no element captures the `KeyEvent`, then the `KeyEvent` is delivered to the focused element by calling `key-pressed` or `key-released`.
/// If these callbacks return `EventResult::accept`, then event delivery is finished and the event has been handled. Otherwise, (recursively) try
/// to deliver the key event to the parent element.
/// \group:keyboard-input
@accepts_focus @expands_to_parent_geometry
FocusScope: FocusScope {
children: KeyBinding;
}
}
item! { Flickable: Empty {
/// ```slint imageAlt="flickable interactive" width="200" height="200"
/// Flickable {
/// interactive: false;
/// }
/// ```
/// When false, the content can't be panned by the user, neither by dragging with the mouse
/// nor with touch.
in property <bool> interactive: true;
/// When true, the content can be scrolled by clicking on it and dragging it with the cursor.
/// Panning with a touch screen is only affected by `interactive`.
in property <bool> mouse-drag-pan-enabled: true;
/// The total width of the scrollable content.
@shadowable in property <length> content-width;
/// The total height of the scrollable content.
@shadowable in property <length> content-height;
/// The position of the scrollable content relative to the `Flickable`. This is usually a negative value.
@shadowable in-out property <length> content-x;
/// The position of the scrollable content relative to the `Flickable`. This is usually a negative value.
@shadowable in-out property <length> content-y;
@deprecated in property <length> viewport-width <=> content-width;
@deprecated in property <length> viewport-height <=> content-height;
@deprecated in-out property <length> viewport-x <=> content-x;
@deprecated in-out property <length> viewport-y <=> content-y;
/// Invoked when `content-x` or `content-y` is changed by a user action (dragging, scrolling).
callback flicked;
} }
element! {
/// ```slint playground
/// export component Example inherits Window {
/// width: 270px;
/// height: 100px;
///
/// Flickable {
/// content-height: 300px;
/// Text {
/// x:0;
/// y: 150px;
/// text: "This is some text that you have to scroll to see";
/// }
/// }
/// }
/// ```
///
/// The `Flickable` is a low-level element that is the base for scrollable
/// widgets, such as the <Link type="ScrollView"/> or <Link type="ListView"/>.
/// When the `content-width` or the `content-height` is greater than the parent's `width` or `height`
/// respectively, the element becomes scrollable.
///
/// When unset, the `content-width` and `content-height` are
/// calculated automatically based on the `Flickable`'s children. This isn't the
/// case when using a `for` loop to populate the elements. This is a bug tracked in
/// issue [#407](https://github.com/slint-ui/slint/issues/407).
/// The maximum and preferred size of the `Flickable` are based on the content size.
///
/// Note that the `Flickable` doesn't create a scrollbar.
/// You can use a <Link type="ScrollView"/> instead or add your own scroll bars.
///
/// When not part of a layout, its width or height defaults to 100% of the parent
/// element when not specified.
///
/// ## Pointer Event Interaction
///
/// If the `Flickable`'s area contains elements that use `TouchArea` to act on clicking, such as `Button`
/// widgets, then the following algorithm is used to distinguish between the user's intent of scrolling or
/// interacting with `TouchArea` elements:
///
/// 1. If the `Flickable`'s `interactive` property is `false`, all events are forwarded to elements underneath.
/// If `mouse-drag-pan-enabled` is `false`, only mouse events are forwarded this way, while touch events keep panning.
/// 2. If a press event is received where the event's coordinates interact with a `TouchArea`, the event is stored
/// and any subsequent move and release events are handled as follows:
/// 1. If 100ms elapse without any events, the stored press event is delivered to the `TouchArea`.
/// 2. If a release event is received before 100ms have elapsed, the stored press event as well as the
/// release event are immediately delivered to the `TouchArea` and the algorithm resets.
/// 3. Any move events received will start a flicking operation on the `Flickable` if all of the following
/// conditions are met:
/// 1. The event is received before 500ms have elapsed since receiving the press event.
/// 2. The distance to the press event exceeds 8 logical pixels in an orientation in which we are allowed to move.
/// If `Flickable` decides to flick, any press event sent previously to a `TouchArea`, is followed up
/// by an exit event. During the phase of receiving move events, the flickable follows the coordinates.
/// 3. If the interaction of press, move, and release events begins at coordinates that do not intersect with
/// a `TouchArea`, then `Flickable` will flick immediately on pointer move events when the euclidean distance
/// to the coordinates of the press event exceeds 8 logical pixels.
///
/// If no element underneath claims a press, the `Flickable` itself only intercepts it when it can actually pan in some direction,
/// i.e. when its `content-width`/`content-height` exceed its own size, or its content is currently scrolled away from the origin.
/// Otherwise the event is forwarded to elements underneath it,
/// the same way wheel/scroll events already are (see below).
///
/// ## Wheel/Scroll Event Interaction
///
/// The `Flickable` also supports scrolling with the mouse wheel and touchpad scroll gestures.
/// It will scroll regardless of the `interactive` and `mouse-drag-pan-enabled` properties.
/// If the `Flickable` can scroll in the event's direction, the event will be intercepted.
/// If the Flickable can't scroll in the direction of the event, the event will be forwarded to the parent.
/// \group:gestures
@expands_to_parent_geometry
Flickable: Flickable
}
item! { SwipeGestureHandler {
/// When disabled, the `SwipeGestureHandler` doesn't recognize any gestures.
in property <bool> enabled: true;
/// The position of the pointer when the swipe started.
out property <Point> pressed-position;
/// The current pointer position.
out property <Point> current-position;
/// `true` while the gesture is recognized, false otherwise.
out property <bool> swiping;
//! ### Handle swipe directions properties
/// \default false
in property <bool> handle-swipe-left;
/// \default false
in property <bool> handle-swipe-right;
/// \default false
in property <bool> handle-swipe-up;
/// \default false
in property <bool> handle-swipe-down;
// For the future
//in property <length> swipe-distance-threshold: 8px;
//in property <duration> swipe-duration-threshold: 500ms;
// in property <bool> delays-propagation;
//in property <duration> propagation-delay: 100ms;
// in property <int> required-touch-points: 1;
//callback swipe-recognized();
/// Invoked when the pointer is moved.
callback moved;
/// Invoked after the swipe gesture was recognized and the pointer was released.
callback swiped;
/// Invoked when the swipe is cancelled programmatically or if the window loses focus.
callback cancelled;
/// Cancel any on-going swipe gesture recognition.
function cancel() { }
} }
element! {
/// Use the `SwipeGestureHandler` to handle swipe gesture in some particular direction.
/// Recognition is limited to the element's geometry.
///
/// The `SwipeGestureHandler` recognizes touchscreen swipes and mouse drags.
///
/// ```slint playground
/// export component Example inherits Window {
/// width: 270px;
/// height: 100px;
///
/// property <int> current-page: 0;
///
/// sgr := SwipeGestureHandler {
/// handle-swipe-right: current-page > 0;
/// handle-swipe-left: current-page < 5;
/// swiped => {
/// if self.current-position.x > self.pressed-position.x + self.width / 4 {
/// current-page -= 1;
/// } else if self.current-position.x < self.pressed-position.x - self.width / 4 {
/// current-page += 1;
/// }
/// }
///
/// HorizontalLayout {
/// property <length> position: - current-page * root.width;
/// animate position { duration: 200ms; easing: ease-in-out; }
/// property <length> swipe-offset;
/// x: position + swipe-offset;
/// states [
/// swiping when sgr.swiping : {
/// swipe-offset: sgr.current-position.x - sgr.pressed-position.x;
/// out { animate swipe-offset { duration: 200ms; easing: ease-in-out; } }
/// }
/// ]
///
/// Rectangle { width: root.width; background: green; }
/// Rectangle { width: root.width; background: limegreen; }
/// Rectangle { width: root.width; background: yellow; }
/// Rectangle { width: root.width; background: orange; }
/// Rectangle { width: root.width; background: red; }
/// Rectangle { width: root.width; background: violet; }
/// }
/// }
/// }
/// ```
///
/// Specify the different swipe directions you'd like to handle by setting the `handle-swipe-left/right/up/down` properties and react to the gesture in the `swiped` callback.
///
/// Pointer press events on the recognizer's area are forwarded to the children with a small delay.
/// If the pointer moves by more than 8 logical pixels in one of the enabled swipe directions, the gesture is recognized, and events are no longer forwarded to the children.
///
/// To keep the gesture-recognition area large enough to feel responsive, wrap the `SwipeGestureHandler` around the controls it should
/// handle swipes for, rather than placing it as a sibling before them.
///
/// :::note{Known issue}
/// [#6781](https://github.com/slint-ui/slint/issues/6781): `SwipeGestureHandler` can interfere with other controls that also recognize swipe gestures, such as `Slider`.
/// Work around it by disabling the relevant `handle-swipe-*` properties while the child is being interacted with, for example in a
/// `Slider`'s `changed` and `released` callbacks.
/// :::
/// \group:gestures
@expands_to_parent_geometry
SwipeGestureHandler: SwipeGestureHandler
}
item! { ScaleRotateGestureHandler {
/// When disabled, the `ScaleRotateGestureHandler` doesn't recognize any gestures and any on-going gesture is cancelled.
in property <bool> enabled: true;
/// `true` while a gesture is being recognized, `false` otherwise.
out property <bool> active;
/// The cumulative scale factor of the gesture. Always starts at `1.0` when the gesture begins.
/// A value greater than `1.0` means zooming in, less than `1.0` means zooming out.
/// When the gesture is not active, the value is `1.0`.
out property <float> scale;
/// The cumulative rotation angle of the gesture. Always starts at `0deg` when the gesture begins.
/// Positive values indicate clockwise rotation, negative values indicate counter-clockwise rotation.
/// When the gesture is not active, the value is `0deg`.
out property <angle> rotation;
/// The center point of the gesture, in the coordinate system of the `ScaleRotateGestureHandler`.
/// For two-finger touch input, this is the midpoint between the two fingers.
/// For trackpad gestures, this is the mouse cursor position.
out property <Point> center;
/// Invoked when a gesture begins. Use this to capture the initial state you want to transform.
callback started;
/// Invoked whenever the `scale`, `rotation`, or `center` changes during the gesture.
callback updated;
/// Invoked when the gesture completes normally (fingers lifted).
callback ended;
/// Invoked when the gesture is cancelled, for example when the handler is disabled during an active gesture or the window loses focus.
callback cancelled;
} }
element! {
/// Use the `ScaleRotateGestureHandler` to handle pinch and rotation gestures.
/// Recognition is limited to the element's geometry.
///
/// The `ScaleRoteGestureHandler` supports touchscreens on all platforms, and additionally supports trackpad gestures on macOS and iOS.
///
/// ```slint playground
/// export component Example inherits Window {
/// width: 400px;
/// height: 400px;
///
/// property <float> start-scale;
/// property <angle> start-rotation;
///
/// gesture := ScaleRotateGestureHandler {
/// started => {
/// start-scale = rect.current-scale;
/// start-rotation = rect.current-rotation;
/// }
/// updated => {
/// rect.current-scale = start-scale * self.scale;
/// rect.current-rotation = start-rotation + self.rotation;
/// }
///
/// rect := Rectangle {
/// background: @radial-gradient(circle, #4488ff, #224488);
/// border-radius: 8px;
///
/// property <float> current-scale: 1.0;
/// property <angle> current-rotation: 0deg;
/// width: 200px * self.current-scale;
/// height: 200px * self.current-scale;
/// x: (parent.width - self.width) / 2;
/// y: (parent.height - self.height) / 2;
///
/// Text {
/// text: "Pinch & rotate";
/// color: white;
/// }
/// }
/// }
/// }
/// ```
///
/// The `scale` property provides a cumulative scale factor relative to the start of the gesture (starting at `1.0`).
/// The `rotation` property provides a cumulative rotation angle (starting at `0deg`).
/// Use the `started` callback to capture your initial state, then multiply by `scale` and add `rotation` in the `updated` callback to apply the gesture.
/// \group:gestures
@expands_to_parent_geometry
ScaleRotateGestureHandler: ScaleRotateGestureHandler
}
item! { DragArea {
/// Set to `false` to stop the `DragArea` from starting drags.
/// Events still reach the child elements.
in property <bool> enabled: true;
/// The payload that's transferred to a <Link type="DropArea" /> when a drop happens.
in property <data-transfer> data;
/// Bitmap drawn under the cursor while a drag is in flight.
/// When unset (the default empty image), no overlay is drawn.
in property <image> drag-image;
/// Horizontal hot spot within `drag-image` that aligns with the cursor, in image pixel coordinates.
/// `0` puts the image's left edge at the cursor; following HTML5's `setDragImage(image, x, y)` convention.
in property <int> drag-image-offset-x;
/// Vertical hot spot within `drag-image` that aligns with the cursor, in image pixel coordinates.
/// `0` puts the image's top edge at the cursor.
in property <int> drag-image-offset-y;
/// Whether the source allows the drop to copy the data. The source retains the data.
in property <bool> allow-copy;
/// Whether the source allows the drop to move the data. The source should remove the
/// original from its model in the `drag-finished` callback when the action is `move`.
in property <bool> allow-move;
/// Whether the source allows the drop to link to the data. Neither side gives up ownership.
in property <bool> allow-link;
/// `true` once the press has crossed the drag threshold and a drag is in flight,
/// `false` once the drop completes or the drag is cancelled.
out property <bool> dragging;
/// Fires when the drag ends: with the chosen action on a successful drop, or with
/// `DragAction.none` if the drag was cancelled.
callback drag-finished(action: DragAction);
} }
element! {
/// Use `DragArea` to make any part of the UI draggable.
/// A drag starts when the user presses the mouse inside the area and moves past a small threshold,
/// and the value bound to `data` becomes the drag payload delivered to a <Link type="DropArea" />.
/// A click doesn't start a drag, so child elements like <Link type="TouchArea" /> stay interactive.
///
/// The payload is a `data-transfer` value, which abstracts over the file-type transfer mechanisms supported by each platform.
/// `data-transfer` values are opaque in Slint code:
/// construct and read them via callbacks implemented in the host language.
///
/// The source declares which actions it permits via `allow-copy`, `allow-move`, and `allow-link`.
/// At least one must be set to true; a `DragArea` that permits no action never starts a drag.
/// When no modifier key is pressed, the proposed action is the first allowed of move, copy, link;
/// modifier keys request a specific action (Ctrl -> copy, Shift -> move, Ctrl+Shift -> link).
/// The target picks the final action from this set in its `can-drop` callback. Once a drop completes
/// (or the drag is cancelled), `drag-finished(action)` fires so a "move" source can remove the original data.
///
/// See <Link type="DragAndDrop" /> for a usage guide and a complete example.
/// \group:drag-and-drop
@expands_to_parent_geometry
DragArea: DragArea
}
item! { DropArea {
/// Set to `false` to stop the `DropArea` from accepting any drops.
in property <bool> enabled: true;
/// Return the action this target wants to perform with the drag, or `DragAction.none` to reject.
/// The runtime clamps the returned value to the source's allowed set: anything the source did not
/// allow is treated as `none`.
/// The argument is a <Link type="DropEvent" /> describing the drag.
callback can-drop(event: DropEvent) -> DragAction;
/// Invoked when the user releases the mouse over the area after `can-drop` returned a non-`none`
/// action. Use this callback to read `event.data` and apply the drop. The returned
/// `DragAction` is reported to the source via `drag-finished`; return `event.proposed-action`
/// to mirror what was negotiated during hover, or a different action to refine the choice at
/// drop time. The runtime clamps the return value against the source's allowed set.
callback dropped(event: DropEvent) -> DragAction;
/// `true` while an accepted drag hovers over the area, `false` otherwise.
/// Bind it to a visual property to give the user feedback, for example a background color.
out property <bool> has-drag;
/// The action the runtime is currently negotiating with the source: `none` when no drag is hovering,
/// or `copy`/`move`/`link` once a concrete action is settled.
out property <DragAction> current-action;
} }
element! {
/// Use `DropArea` to accept drops coming from a <Link type="DragArea" />, or from another application on platforms that support it.
/// The `can-drop` callback runs while the cursor moves over the area to decide whether to accept the drag,
/// and which action (copy/move/link) to perform.
/// The `dropped` callback runs when the user releases the mouse inside the area after `can-drop` returned
/// a non-`none` action.
///
/// See <Link type="DragAndDrop" /> for a usage guide and a complete example.
/// \group:drag-and-drop
@expands_to_parent_geometry
DropArea: DropArea
}
item! { MenuItem {
/// The title shown for this menu item.
/// \default ""
in property <string> title;
/// Invoked when the menu entry is activated.
callback activated;
/// When disabled, the `MenuItem` can be selected but not activated.
in property <bool> enabled: true;
/// When true, the `MenuItem` can be checked. The value of the `checked` property is toggled when the user activates the menu item.
/// \default false
in property <bool> checkable: false;
/// The keyboard shortcut for this `MenuItem`.
///
/// This property can only be set in a `MenuItem` that is part of a <Link type="MenuBar"/>.
in property <keys> shortcut;
/// When true, a checkmark will be shown next to the title of the `MenuItem`.
/// \default false
in-out property <bool> checked: false;
/// The icon shown next to the title.
in property <image> icon;
} }
element! {
/// A `MenuItem` represents a single menu entry. It must be a child of a `Menu` element.
@is_non_item_type @disallow_global_types_as_child_elements
MenuItem: MenuItem
}
element! {
/// A `MenuSeparator` represents a separator in a menu.
/// It cannot have children, and doesn't have properties or callbacks.
/// MenuSeparator at the beginning or end of a menu will not be visible.
/// Consecutive `MenuSeparator`s will be merged into one.
@is_non_item_type @disallow_global_types_as_child_elements
MenuSeparator
}
element! {
/// Place the `Menu` element in a <Link type="MenuBar" />, a `ContextMenuArea`, or within another `Menu`.
/// Use `MenuItem` children of individual menu items, `Menu` children to create sub-menus, and `MenuSeparator` to create separators.
@is_non_item_type @disallow_global_types_as_child_elements
Menu {
/// This is the label of the menu as written in the menu bar or in the parent menu.
/// \default ""
in property <string> title;
/// When disabled, the `Menu` can be selected but not activated.
in property <bool> enabled: true;
/// The icon shown next to the title when in a parent menu.
in property <image> icon;
children: MenuItem, MenuSeparator, Menu;
}
}
element! {
/// Use the `MenuBar` element in a <Link type="Window" /> to declare the structure of a menu bar, including the actual
/// menus and sub-menus.
///
/// :::note{Note}
/// There can only be one `MenuBar` element in a `Window` and it must not be in a `for` or a `if`.
/// :::
///
/// The `MenuBar` doesn't have properties, but it must contain <Link type="Menu" /> as children that represent top level entries in the menu bar.
///
/// Depending on the platform, the menu bar might be native or rendered by Slint.
/// This means that for example, on macOS, the menu bar will be at the top of the screen.
/// The `width` and `height` property of the <Link type="Window" /> define the client area, excluding the menu bar.
/// The `x` and `y` properties of `Window` children are also relative to the client area.
///
/// ### Example
///
/// ```slint
/// export component Example inherits Window {
/// MenuBar {
/// Menu {
/// title: @tr("File");
/// MenuItem {
/// title: @tr("New");
/// activated => { file-new(); }
/// shortcut: @keys(Control + N);
/// }
/// MenuItem {
/// title: @tr("Open");
/// activated => { file-open(); }
/// shortcut: @keys(Control + O);
/// }
/// }
/// Menu {
/// title: @tr("Edit");
/// MenuItem {
/// title: @tr("Copy");
/// }
/// MenuItem {
/// title: @tr("Paste");
/// }
/// MenuSeparator {}
/// Menu {
/// title: @tr("Find");
/// MenuItem {
/// title: @tr("Find in document...");
/// }
/// MenuItem {
/// title: @tr("Find Next");
/// }
/// MenuItem {
/// title: @tr("Find Previous");
/// }
/// }
/// }
/// }
///
/// callback file-new();
/// callback file-open();
///
/// // ... actual window content goes here
/// }
/// ```
/// \skip_children
@is_non_item_type @disallow_global_types_as_child_elements
MenuBar {
/// Whether this menu bar should be visible. If the menu bar is not visible, the menu bar will not take up any space but shortcuts will still function.
/// \default true
in property <bool> visible: true;
children: Menu;
}
}
item! { ContextMenu: Empty {
callback activated(entry: MenuEntry);
callback sub-menu(entry: MenuEntry) -> [MenuEntry];
callback show(position: Point);
function close() { }
@pure function is-open() -> bool { }
in property <bool> enabled: true;
} }
element! {
// The NativeItem, exported as ContextMenuInternal for the style
@is_internal @expands_to_parent_geometry
ContextMenuInternal: ContextMenu {
in property <[MenuEntry]> entries;
}
}
element! {
// Lowered in lower_menus pass.
/// Use the non-visual `ContextMenuArea` element to declare an area where the user can show a context menu.
///
/// The context menu is shown if the user right-clicks on the area covered by the `ContextMenuArea` element,
/// or if the user presses the "Menu" key on their keyboard while a `FocusScope` within the `ContextMenuArea` has focus.
/// On Android, the menu is shown with a long press.
/// Call the `show()` function on the `ContextMenuArea` element to programmatically show the context menu.
///
/// One of the children of the `ContextMenuArea` must be a `Menu` element, which defines the menu to be shown.
/// There can be at most one `Menu` child, all other children must be of a different type and will be shown as regular visual children.
/// Define the structure of the menu by placing `MenuItem` or `Menu` elements inside that `Menu`.
///
/// \footer
/// ## Example
///
/// ```slint
/// export component Example {
/// ContextMenuArea {
/// Menu {
/// MenuItem {
/// title: @tr("Cut");
/// activated => { debug("Cut"); }
/// }
/// MenuItem {
/// title: @tr("Copy");
/// activated => { debug("Copy"); }
/// }
/// MenuItem {
/// title: @tr("Paste");
/// activated => { debug("Paste"); }
/// }
/// MenuSeparator {}
/// Menu {
/// title: @tr("Find");
/// MenuItem {
/// title: @tr("Find Next");
/// }
/// MenuItem {
/// title: @tr("Find Previous");
/// }
/// }
/// }
/// }
/// }
/// ```
/// \group:window
@expands_to_parent_geometry
ContextMenuArea: Empty {
//! ## Function
//!
//! ### show(Point)
//!
//! Call this function to programmatically show the context menu at the given position relative to the `ContextMenuArea` element.
//!
//! ## close()
//!
//! Close the context menu if it's currently open.
// This is actually function as part of out interface, but a callback as much is the runtime concerned
callback show(position: Point);
function close() { }
//! ### enabled
//!
//! <SlintProperty propName="enabled" typeName="bool" defaultValue="true">
//! When disabled, the `Menu` is not showing.
//! </SlintProperty>
in property <bool> enabled: true;
children: Menu;
}
}
item! { WindowItem {
/// The width of the window. \{#sls.ref.window.width}
///
/// <OnlyInSC>
/// The application gives the window its size when it creates the component, so this is a value the file reads,
/// and binding it is an error. \{#sls.ref.window.width-out}
/// </OnlyInSC>
@sc in-out property <length> width;
/// The height of the window. \{#sls.ref.window.height}
///
/// <OnlyInSC>
/// The application gives the window its size when it creates the component, so this is a value the file reads,
/// and binding it is an error. \{#sls.ref.window.height-out}
/// </OnlyInSC>
@sc in-out property <length> height;
/// Whether the window should be placed above all other windows on window managers supporting it.
/// \default false
in property <bool> always-on-top;
/// Whether to display the Window in full-screen mode. In full-screen mode the Window will occupy the entire screen, it will not be resizable, and it will not display the title bar.
/// \default true if 'SLINT_FULLSCREEN' environment variable is set, otherwise false
in-out property <bool> full-screen;
/// Whether the window is minimized. Setting this to true minimizes the window.
@shadowable in-out property <bool> minimized;
/// Whether the window is maximized. Setting this to true maximizes the window.
@shadowable in-out property <bool> maximized;
/// The background brush of the `Window`. It is painted first, covering the whole window. \{#sls.ref.window.background}
///
/// <OnlyInSC>
/// This background must be an opaque color literal.
/// Rendering writes every pixel of the frame buffer, and there's nothing
/// underneath the window for a translucent background to blend with. \{#sls.ref.window.opaque}
/// </OnlyInSC>
/// \default depends on the style
@sc in property <brush> background; // StyleMetrics.background set in apply_default_properties_from_style
@deprecated in property <brush> color <=> background;
/// The font family to use as default in text elements inside this window, that don't have their `font-family` property set.
in property <string> default-font-family;
/// The font size to use as default in text elements inside this window, that don't have their `font-size` property set. The value of this property also forms the basis for relative font sizes.
/// \default 0
in property <length> default-font-size;
/// The font weight to use as default in text elements inside this window, that don't have their `font-weight` property set. The values range from 100 (lightest) to 900 (thickest). 400 is the normal weight. Use the <Link type="FontWeight" /> namespace for predefined constants.
in property <int> default-font-weight;
/// The window icon shown in the title bar or the task bar on window managers supporting it.
in property <image> icon;
/// Whether the window should be borderless/frameless or not.
/// \default false
in property <bool> no-frame;
/// :::caution[Caution]
/// This property is `winit` only for now.
/// :::
/// Size of the resize border in borderless/frameless windows.
/// \default 0
in property <length> resize-border-width;
/// The window title that is shown in the title bar.
/// \default the name of the running program
in property <string> title { BuiltinFunction.DefaultWindowTitle }
/// Some devices, such as mobile phones, allow programs to overlap the system UI. A few examples for this are the notch on iPhones, the window buttons on macOS on windows that extend their content over the titlebar and the system bar on Android. This property exposes the amount of space at the edges of the window that can be drawn to but where no interactive elements should be placed. On most devices, this is 0 for all sides.
out property <Edges> safe-area-insets;
/// On mobile devices, virtual keyboards (aka software keyboards or onscreen keyboards) are displayed on top of the application. When such a keyboard is shown, this property denotes the position of the top left boundary of the rectangle covered by it in window coordinates.
out property <Point> virtual-keyboard-position;
/// On mobile devices, virtual keyboards (aka software keyboards or onscreen keyboards) are displayed on top of the application. When such a keyboard is shown, this property denotes the width and height of the rectangle covered by it in window coordinates.
out property <Size> virtual-keyboard-size;
/// Request that the window be closed.
/// This triggers the `close-requested` callback, giving the application a chance to cancel the close.
/// Returns `true` if the application accepted the close request; false otherwise.
/// Returns `false` if called on a child `Window` element, which can't be closed independently.
@shadowable function close() -> bool { }
/// Hide this window. This also drops the strong reference on the window, so if this was
/// the last reference, the event loop will quit.
@shadowable function hide() { }
} }
element! {
/// `Window` is the root of the tree of elements that are visible on the screen. \{#sls.meta.window.purpose}
///
/// <NotInSC>
/// The `Window` geometry will be restricted by its layout constraints: Setting the `width` will result in a fixed width,
/// and the window manager will respect the `min-width` and `max-width` so the window can't be resized bigger
/// or smaller. The initial width can be controlled with the `preferred-width` property. The same applies to the `Window`s height.
/// </NotInSC>
///
/// <NotInSC>
/// Use the <Link type="MenuBar" /> element to declare a menu bar for the window.
/// </NotInSC>
/// \group:window
@sc
Window: WindowItem {
children: MenuBar;
}
}
item! { WindowMoveArea {
/// Set to `false` to stop the `WindowMoveArea` from initiating window moves.
/// Events still reach the child elements.
in property <bool> enabled: true;
} }
element! {
/// Use `WindowMoveArea` to let the user move the window by dragging a region of your UI,
/// such as a custom title bar in a window without native decorations (`no-frame: true`).
///
/// The move starts when the user presses the left mouse button inside the area and drags past a small threshold.
/// A plain click doesn't move the window, so child elements like <Link type="TouchArea" /> stay interactive.
///
/// The windowing system performs the move.
/// It requires a backend and platform with support for it (winit on Windows, macOS, X11, and Wayland; Qt).
/// On platforms without support, the element does nothing.
///
/// When not part of a layout, its width and height default to 100% of the parent element.
///
/// ```slint playground
/// export component Example inherits Window {
/// no-frame: true;
/// preferred-width: 400px;
/// preferred-height: 300px;
/// VerticalLayout {
/// Rectangle {
/// height: 32px;
/// background: #444444;
/// WindowMoveArea {
/// HorizontalLayout {
/// Text {
/// text: "My Application";
/// color: white;
/// vertical-alignment: center;
/// horizontal-alignment: center;
/// }
/// }
/// }
/// }
/// Rectangle {
/// background: white;
/// }
/// }
/// }
/// ```
/// \group:window
@expands_to_parent_geometry
WindowMoveArea: WindowMoveArea
}
item! { BoxShadow: Empty {
in property <length> border-top-left-radius;
in property <length> border-top-right-radius;
in property <length> border-bottom-left-radius;
in property <length> border-bottom-right-radius;
in property <length> offset-x;
in property <length> offset-y;
in property <color> color;
in property <length> blur;
in property <length> spread;
in property <bool> inset;
} }
element! {
@is_internal @expands_to_parent_geometry
BoxShadow: BoxShadow
}
item! { TextInput {
/// The text rendered and editable by the user.
/// \default ""
in-out property <string> text;
/// The name of the font family selected for rendering the text.
in property <string> font-family;
/// The font size of the text.
in property <length> font-size;
/// Whether or not the font face should be drawn italicized or not.
/// \default false
in property <bool> font-italic;
/// The weight of the font. The values range from 100 (lightest) to 900 (thickest). 400 is the normal weight.
in property <int> font-weight;
/// The color of the text.
/// \default depends on the style
in property <brush> color; // StyleMetrics.default-text-color set in apply_default_properties_from_style
/// The foreground color of the selection.
in property <color> selection-foreground-color; // StyleMetrics.selection-foreground set in apply_default_properties_from_style
/// The background color of the selection.
in property <color> selection-background-color; // StyleMetrics.selection-background set in apply_default_properties_from_style
/// The horizontal alignment of the text.
in property <TextHorizontalAlignment> horizontal-alignment;
/// The vertical alignment of the text.
in property <TextVerticalAlignment> vertical-alignment;
/// The way the text input wraps. Only makes sense when `single-line` is false.
/// \default no-wrap
in property <TextWrap> wrap;
/// The letter spacing allows changing the spacing between the glyphs. A positive value increases the spacing and a negative value decreases the distance.
/// \default 0
in property <length> letter-spacing;
/// The line height as a unitless factor (or a percentage: `150%` equals `1.5`) applied to
/// the font's natural line height (ascent + descent + line gap). The default of `1` keeps
/// the natural line height; larger values spread the lines apart, smaller values pull them
/// together, and `0` collapses them onto each other. Negative or non-numeric values behave
/// like `1`. Unlike CSS `line-height`, the factor is relative to the natural line height,
/// not the font size, and keyword or length values aren't supported.
/// \default 1
in property <float> line-height-factor: 1;
in property <length> width;
in property <length> height;
/// The height of the page used to compute how much to scroll when the user presses page up or page down.
in property <length> page-height;
/// The width of the text cursor.
/// \default provided at run-time by the selected widget style
in property <length> text-cursor-width; // StyleMetrics.text-cursor-width set in apply_default_properties_from_style
/// Use this to configure `TextInput` for editing special input, such as password fields.
/// \default text
in property <InputType> input-type;
/// Hints for the platform's input method (such as a soft keyboard), for example to configure auto-capitalization.
/// The input method may take these hints into account, but might also ignore them.
in property <InputMethodHints> input-method-hints;
// Internal, undocumented property, only exposed for tests.
out property <int> cursor-position-byte-offset;
// Internal, undocumented property, only exposed for tests.
out property <int> anchor-position-byte-offset;
/// `TextInput` sets this to `true` when it's focused. Only then it receives <Link type="KeyEvent"/>s.
out property <bool> has-focus;
/// Invoked when the enter key is pressed.
callback accepted;
/// Invoked when the text has changed because the user modified it.
callback edited;
/// The cursor was moved to the new (x, y) position described by the `Point` argument.
callback cursor-position-changed(position: Point);
/// Invoked when a key is pressed, the argument is a <Link type="KeyEvent" /> struct. Use this callback to
/// handle keys before `TextInput` does. Return `accept` to indicate that you've handled the event, or return
/// `reject` to let `TextInput` handle it.
callback key-pressed(event: KeyEvent) -> EventResult;
/// Invoked when a key is released, the argument is a <Link type="KeyEvent" /> struct. Use this callback to
/// handle keys before `TextInput` does. Return `accept` to indicate that you've handled the event, or return
/// `reject` to let `TextInput` handle it.
callback key-released(event: KeyEvent) -> EventResult;
in property <bool> enabled: true;
/// When set to `true`, the text is always rendered as a single line, regardless of new line separators in the text.
in property <bool> single-line: true;
/// When set to `true`, text editing via keyboard and mouse is disabled but selecting text is still enabled as well as editing text programmatically.
in property <bool> read-only: false;
// Internal, undocumented property, only exposed for IME.
out property <string> preedit-text;
/// The design metrics of the font scaled to the font pixel size used by the element.
out property <FontMetrics> font-metrics { BuiltinFunction.ItemFontMetrics }
/// Selects the text between two UTF-8 offsets.
/// `anchor` is the end of the selection that stays put and `focus` the end the cursor moves to,
/// so `focus` may precede `anchor` to select backwards.
/// Pass the same value for both to place the text cursor at that offset without selecting anything.
function set-selection-offsets(anchor: int, focus: int) { BuiltinFunction.SetSelectionOffsets }
/// Selects all text.
function select-all() { }
/// Clears the selection.
function clear-selection() { }
/// Copies the selected text to the clipboard and removes it from the editable area.
function cut() { }
/// Copies the selected text to the clipboard.
function copy() { }
/// Pastes the text content of the clipboard at the cursor position.
function paste() { }
/// Undoes the last text operation.
function undo() { }
/// Redoes the last undone text operation.
function redo() { }
//! ### focus()
//! Call this function to focus the text input and make it receive future keyboard events.
//!
//! ### clear-focus()
//! Call this function to remove keyboard focus from this `TextInput` if it currently has the focus. See also <Link type="FocusHandling" />.
} }
element! {
/// The `TextInput` is a lower-level item that shows text and allows entering text.
/// You should probably not use this directly, but instead use the <Link type="LineEdit" /> or <Link type="TextEdit" /> component.
///
/// When not part of a layout, its width and height defaults to 100% of the parent element.
///
/// The `TextInput` does not scroll automatically when the cursor is outside of the visible area.
/// This is the responsibility of the enclosing widget to ensure using the `cursor-position-changed` callback.
///
/// ## Example
///
/// ```slint playground
/// export component Example inherits Window {
/// width: 270px;
/// height: 40px;
/// Rectangle {
/// clip: true;
///
/// TextInput {
/// text: "Edit me";
/// width: max(parent.width, self.preferred-width);
/// vertical-alignment: center;
///
/// private property <length> margin: 1rem;
/// cursor-position-changed(cursor-position) => {
/// if cursor-position.x + self.x < margin {
/// self.x = - cursor-position.x + margin;
/// } else if cursor-position.x + self.x > parent.width - margin - self.text-cursor-width {
/// self.x = parent.width - cursor-position.x - margin - self.text-cursor-width;
/// }
/// }
/// }
/// }
/// }
/// ```
///
/// \footer
/// ## Accessibility
///
/// By default, `TextInput` elements have the following accessibility properties set:
///
/// - `accessible-role: text-input;`
/// - `accessible-value: text;`
/// - `accessible-enabled: enabled;`
/// - `accessible-read-only: read-only; `
/// \group:keyboard-input
@accepts_focus @expands_to_parent_geometry
TextInput: TextInput
}
item! { Clip {
in property <length> border-top-left-radius;
in property <length> border-top-right-radius;
in property <length> border-bottom-left-radius;
in property <length> border-bottom-right-radius;
in property <length> border-width;
in property <bool> clip;
in property <bool> is-visibility-clip;
} }
element! {
@is_internal @expands_to_parent_geometry
Clip: Clip
}
item! { Opacity {
in property <float> opacity: 1;
} }
element! {
@is_internal @expands_to_parent_geometry
Opacity: Opacity
}
item! { Layer: Empty {
in property <bool> cache-rendering-hint;
} }
element! {
@is_internal @expands_to_parent_geometry
Layer: Layer
}
element! {
@is_non_item_type
Row
}
element! {
/// `GridLayout` places elements on a grid.
///
/// `GridLayout` covers its entire surface with cells. Cells are not aligned.
/// The elements constituting the cells will be stretched inside their allocated
/// space, unless their size constraints—like, e.g., `min-height` or
/// `max-width`—work against this.
///
///
/// ```slint playground imageAlt="gridlayout example" width="200" height="100"
/// // This example uses the `Row` element
/// export component Foo inherits Window {
/// width: 200px;
/// height: 200px;
/// GridLayout {
/// spacing: 5px;
/// Row {
/// Rectangle { background: red; }
/// Rectangle { background: blue; }
/// }
/// Row {
/// Rectangle { background: yellow; }
/// Rectangle { background: green; }
/// }
/// }
/// }
/// ```
///
///
/// ```slint playground imageAlt="gridlayout example2" width="200" height="100"
/// // This example uses the `col` and `row` properties
/// export component Foo inherits Window {
/// width: 200px;
/// height: 150px;
/// GridLayout {
/// Rectangle { background: red; }
/// Rectangle { background: blue; }
/// Rectangle { background: yellow; row: 1; }
/// Rectangle { background: green; }
/// Rectangle { background: black; col: 2; row: 0; }
/// }
/// }
/// ```
///
/// \footer
/// ## Cell elements
/// Cell elements inside a `GridLayout` obtain the following new properties. Any bindings to these properties must be compile-time constants:
///
/// ### row
/// <SlintProperty propName="row" typeName="int" defaultValue="auto">
/// The index of the element's row within the grid. Setting this property resets the element's column to zero, unless explicitly set.
/// </SlintProperty>
///
/// ### col
/// <SlintProperty propName="col" typeName="int" defaultValue="auto">
/// The index of the element's column within the grid. Set this property to override the sequential column assignment (e.g., to skip a column).
/// </SlintProperty>
///
/// ### rowspan
/// <SlintProperty propName="rowspan" typeName="int" defaultValue="1">
/// The number of rows this element should span.
/// </SlintProperty>
///
/// ### colspan
/// <SlintProperty propName="colspan" typeName="int" defaultValue="1">
/// The number of columns this element should span.
/// </SlintProperty>
///
/// To implicitly sequentially assign row indices—just like with `col`—wrap cell elements in `Row` elements.
///
/// The following example creates a 2-by-2 grid with `Row` elements, omitting one cell:
///
/// ```slint
/// import { Button } from "std-widgets.slint";
/// export component Foo inherits Window {
/// width: 200px;
/// height: 100px;
/// GridLayout {
/// Row { // children implicitly on row 0
/// Button { col: 1; text: "Top Right"; } // implicit column after this would be 2
/// }
/// Row { // children implicitly on row 1
/// Button { text: "Bottom Left"; } // implicitly in column 0...
/// Button { text: "Bottom Right"; } // ...and 1
/// }
/// }
/// }
/// ```
///
/// The following example creates the same grid using the `row` property. Row indices must be taken care of manually:
///
/// ```slint
/// import { Button } from "std-widgets.slint";
/// export component Foo inherits Window {
/// width: 200px;
/// height: 100px;
/// GridLayout {
/// Button { row: 0; col: 1; text: "Top Right"; } // `row: 0;` could even be left out at the start
/// Button { row: 1; text: "Bottom Left"; } // new row, implicitly resets column to 0
/// Button { text: "Bottom Right"; } // same row, sequentially assigned column 1
/// }
/// }
/// ```
/// \group:layouts
GridLayout {
//! ## Spacing Properties
/// The distance between the elements in the layout. This single value is applied to both horizontal and vertical spacing.
in property <length> spacing;
//! To target specific axis with different values use the following properties:
///
in property <length> spacing-horizontal;
///
in property <length> spacing-vertical;
//! ## Padding Properties
//!
//! ### padding
//! <SlintProperty propName="padding" typeName="length">
//! The padding around the grid structure as a whole. This single value is applied to all sides.
//! </SlintProperty>
//!
//! To target specific sides with different values use the following properties:
//!
//! ### padding-left
//! <SlintProperty propName="padding-left" typeName="length"/>
//!
//! ### padding-right
//! <SlintProperty propName="padding-right" typeName="length"/>
//!
//! ### padding-top
//! <SlintProperty propName="padding-top" typeName="length"/>
//!
//! ### padding-bottom
//! <SlintProperty propName="padding-bottom" typeName="length"/>
// Additional accepted child
children: Row;
}
}
element! {
/// ```slint
/// export component Foo inherits Window {
/// width: 200px;
/// height: 100px;
/// VerticalLayout {
/// spacing: 5px;
/// Rectangle { background: red; width: 10px; }
/// Rectangle { background: blue; min-width: 10px; }
/// Rectangle { background: yellow; vertical-stretch: 1; }
/// Rectangle { background: green; vertical-stretch: 2; }
/// }
/// }
/// ```
///
/// Places its children next to each other vertically.
/// The size of elements can either be fixed with the `width` or `height` property, or if they aren't set
/// they will be computed by the layout respecting the minimum and maximum sizes and the stretch factor.
/// \footer
/// ## Cell elements
/// Cell elements inside a `VerticalLayout` obtain the following new properties:
///
/// ### cross-axis-self-alignment
/// <SlintProperty propName="cross-axis-self-alignment" typeName="enum" enumName="CrossAxisAlignment" defaultValue="auto">
/// Overrides the container's `cross-axis-alignment` for this element.
/// The default value `auto` uses the container's `cross-axis-alignment`.
/// </SlintProperty>
///
/// ### layout-order
/// <SlintProperty propName="layout-order" typeName="int" defaultValue="0">
/// Controls the visual order of the elements: they are laid out in ascending
/// order value, and elements with the same value keep their declaration order.
/// ```slint no-test
/// VerticalLayout {
/// Rectangle { layout-order: 2; }
/// Rectangle { layout-order: 1; } // appears first
/// }
/// ```
/// Only the visual order changes: keyboard focus still moves in declaration order.
/// </SlintProperty>
/// \group:layouts
VerticalLayout {
//! ## Spacing Properties
/// The distance between the elements in the layout.
in property <length> spacing;
//! ## Padding Properties
//! ### padding
//! <SlintProperty propName="padding" typeName="length">
//! The padding within the layout as a whole. This single value is applied to all sides.
//! </SlintProperty>
//!
//! To target specific sides with different values use the following properties:
//! ### padding-left
//! <SlintProperty propName="padding-left" typeName="length"/>
//!
//! ### padding-right
//! <SlintProperty propName="padding-right" typeName="length"/>
//!
//! ### padding-top
//! <SlintProperty propName="padding-top" typeName="length"/>
//!
//! ### padding-bottom
//! <SlintProperty propName="padding-bottom" typeName="length"/>
//!
//! ## Alignment Properties
/// Set the alignment along the main (vertical) axis. Matches the CSS flex box.
in property <LayoutAlignment> alignment;
/// Set the alignment of items along the cross (horizontal) axis.
/// The default is `stretch`, meaning each item fills the full width of the layout.
/// The other values (`start`, `end`, `center`) size each
/// item to its preferred width, clamped to its min/max, and position it at the
/// left, right, or center of the layout's content box.
///
/// ```slint
/// export component Example inherits Window {
/// width: 200px;
/// height: 100px;
/// VerticalLayout {
/// cross-axis-alignment: end;
/// Rectangle { background: red; preferred-width: 30px; preferred-height: 20px; }
/// Rectangle { background: blue; preferred-width: 60px; preferred-height: 20px; }
/// Rectangle { background: green; preferred-width: 90px; preferred-height: 20px; }
/// }
/// }
/// ```
in property <CrossAxisAlignment> cross-axis-alignment;
}
}
element! {
/// ```slint
/// export component Foo inherits Window {
/// width: 200px;
/// height: 100px;
/// HorizontalLayout {
/// spacing: 5px;
/// Rectangle { background: red; width: 10px; }
/// Rectangle { background: blue; min-width: 10px; }
/// Rectangle { background: yellow; horizontal-stretch: 1; }
/// Rectangle { background: green; horizontal-stretch: 2; }
/// }
/// }
/// ```
///
/// Places its children next to each other horizontally.
/// The size of elements can either be fixed with the `width` or `height` property, or if they aren't set
/// they will be computed by the layout respecting the minimum and maximum sizes and the stretch factor.
/// \footer
/// ## Cell elements
/// Cell elements inside a `HorizontalLayout` obtain the following new properties:
///
/// ### cross-axis-self-alignment
/// <SlintProperty propName="cross-axis-self-alignment" typeName="enum" enumName="CrossAxisAlignment" defaultValue="auto">
/// Overrides the container's `cross-axis-alignment` for this element.
/// The default value `auto` uses the container's `cross-axis-alignment`.
/// </SlintProperty>
///
/// ### layout-order
/// <SlintProperty propName="layout-order" typeName="int" defaultValue="0">
/// Controls the visual order of the elements: they are laid out in ascending
/// order value, and elements with the same value keep their declaration order.
/// ```slint no-test
/// HorizontalLayout {
/// Rectangle { layout-order: 2; }
/// Rectangle { layout-order: 1; } // appears first
/// }
/// ```
/// Only the visual order changes: keyboard focus still moves in declaration order.
/// </SlintProperty>
/// \group:layouts
HorizontalLayout {
//! ## Spacing Properties
/// The distance between the elements in the layout.
in property <length> spacing;
//! ## Padding Properties
//!
//! ### padding
//! <SlintProperty propName="padding" typeName="length">
//! The padding within the layout as a whole. This single value is applied to all sides.
//! </SlintProperty>
//!
//! To target specific sides with different values use the following properties:
//!
//! ### padding-left
//! <SlintProperty propName="padding-left" typeName="length"/>
//!
//! ### padding-right
//! <SlintProperty propName="padding-right" typeName="length"/>
//!
//! ### padding-top
//! <SlintProperty propName="padding-top" typeName="length"/>
//!
//! ### padding-bottom
//! <SlintProperty propName="padding-bottom" typeName="length"/>
//!
//! ## Alignment Properties
/// Set the alignment along the main (horizontal) axis. Matches the CSS flex box.
in property <LayoutAlignment> alignment;
/// Set the alignment of items along the cross (vertical) axis.
/// The default is `stretch`, meaning each item fills the full height of the layout.
/// The other values (`start`, `end`, `center`) size each
/// item to its preferred height, clamped to its min/max, and position it at the
/// top, bottom, or center of the layout's content box.
///
/// ```slint
/// export component Example inherits Window {
/// width: 200px;
/// height: 100px;
/// HorizontalLayout {
/// cross-axis-alignment: center;
/// Rectangle { background: red; preferred-width: 30px; preferred-height: 20px; }
/// Rectangle { background: blue; preferred-width: 30px; preferred-height: 40px; }
/// Rectangle { background: green; preferred-width: 30px; preferred-height: 60px; }
/// }
/// }
/// ```
in property <CrossAxisAlignment> cross-axis-alignment;
}
}
element! {
/// `FlexboxLayout` is a flexible box layout that arranges its children in rows or columns with automatic wrapping.
/// It implements a CSS Flexbox-like layout model suitable for creating flexible, responsive UIs.
///
/// Use `FlexboxLayout` when the items should wrap: items that don't fit continue on the next line.
/// That's why `flex-wrap` defaults to `wrap`, unlike CSS.
/// For a single row or column, use the simpler and faster
/// <Link type="HorizontalLayout" /> or <Link type="VerticalLayout" /> instead,
/// unless you need a `flex-direction` that changes at runtime,
/// or the reversed directions (`row-reverse` / `column-reverse`).
///
///
/// ```slint playground imageAlt="flexboxlayout example with row direction" width="300" height="150"
/// // This example demonstrates FlexboxLayout with row direction (default)
/// export component Foo inherits Window {
/// width: 300px;
/// height: 150px;
/// FlexboxLayout {
/// spacing: 8px;
/// padding: 8px;
/// flex-direction: row;
/// Rectangle { background: red; width: 60px; height: 50px; }
/// Rectangle { background: blue; width: 60px; height: 50px; }
/// Rectangle { background: yellow; width: 60px; height: 50px; }
/// Rectangle { background: green; width: 60px; height: 50px; }
/// Rectangle { background: purple; width: 60px; height: 50px; }
/// }
/// }
/// ```
///
///
/// ```slint playground imageAlt="flexboxlayout example with column direction" width="200" height="300"
/// // This example demonstrates FlexboxLayout with column direction
/// export component Foo inherits Window {
/// width: 200px;
/// height: 300px;
/// FlexboxLayout {
/// spacing: 8px;
/// padding: 8px;
/// flex-direction: column;
/// Rectangle { background: red; width: 50px; height: 60px; }
/// Rectangle { background: blue; width: 50px; height: 60px; }
/// Rectangle { background: yellow; width: 50px; height: 60px; }
/// Rectangle { background: green; width: 50px; height: 60px; }
/// Rectangle { background: purple; width: 50px; height: 60px; }
/// }
/// }
/// ```
///
/// ## Overview
///
/// In row direction, items are placed from left to right. When the available width is exceeded, items automatically wrap to the next row. In column direction, items are placed from top to bottom and wrap to the next column when the available height is exceeded.
///
/// A wrapping column direction container reports the width of all its columns
/// only when its `height` is set to a plain length, such as `height: 200px`.
/// `phx` and `rem` do not count, since they depend on the window's scale factor
/// and the default font size, which are only known while running.
/// Set it on the container, on a component it inherits from, or where the container is used.
/// A height a parent layout assigns, a percentage, and an expression all report
/// the width of a single column instead,
/// as for a CSS column flex container with an automatic height.
/// A height on the root of a component used elsewhere does not count for the elements inside it,
/// since each use may override it: set the height on the container instead.
/// A `wrap` column container never wraps into columns wider than its width:
/// the content overflows downward instead, like a wrapping `Text` given too little height.
/// A `wrap-reverse` one still wraps, since its lines are anchored at the opposite edge.
/// To wrap without setting a height, give the container more width,
/// with `horizontal-stretch` or a `min-width`: it wraps into whatever width it gets.
///
/// \footer
/// ## Cell elements
/// Cell elements inside a `FlexboxLayout` obtain the following new properties:
///
/// ### cross-axis-self-alignment
/// <SlintProperty propName="cross-axis-self-alignment" typeName="enum" enumName="CrossAxisAlignment" defaultValue="auto">
/// Overrides the container's `cross-axis-alignment` for this element. CSS Flexbox calls this "align-self".
/// The default value `auto` uses the container's `cross-axis-alignment`.
/// </SlintProperty>
///
/// ### layout-order
/// <SlintProperty propName="layout-order" typeName="int" defaultValue="0">
/// Controls the visual order of the items, like the CSS `order` property:
/// items are laid out in ascending order value, and items with the same value keep
/// their declaration order.
/// ```slint no-test
/// FlexboxLayout {
/// Rectangle { layout-order: 2; }
/// Rectangle { layout-order: 1; } // appears first
/// }
/// ```
/// Only the visual order changes: keyboard focus still moves in declaration order.
/// </SlintProperty>
///
/// ## CSS Mapping
///
/// The container properties map to CSS Flexbox as follows:
///
/// | CSS | Slint |
/// | ----------------- | --------------------------------------------------------- |
/// | `flex-direction` | `flex-direction` |
/// | `flex-wrap` | `flex-wrap`, but the default is `wrap` (CSS: `nowrap`) |
/// | `justify-content` | `alignment` |
/// | `align-items` | `cross-axis-alignment` |
/// | `align-content` | `cross-axis-line-alignment` |
/// | `gap` | `spacing` |
/// | `column-gap` | `spacing-horizontal` |
/// | `row-gap` | `spacing-vertical` |
/// | `padding` | `padding`, `padding-left` / `-right` / `-top` / `-bottom` |
///
/// The CSS per-item flexbox properties are expressed with the properties the
/// other layouts already use:
///
/// | CSS | Slint |
/// | ------------- | -------------------------------------------------------------- |
/// | `flex-grow` | `alignment: stretch` on the container, weighted per item by `horizontal-stretch` / `vertical-stretch`; `max-width` / `max-height` caps growing (space a capped item cannot take stays free) |
/// | `flex-shrink` | nothing to opt into: every item shrinks, in proportion to its preferred size; `min-width` / `min-height` refuses shrinking |
/// | `flex-basis` | `preferred-width` (row) / `preferred-height` (column) |
/// | `align-self` | `cross-axis-self-alignment` |
///
/// ## Layout Behavior
///
/// The layouting algorithm for FlexboxLayout is entirely implemented by <a href="https://github.com/DioxusLabs/taffy">taffy</a>
///
/// You can learn more about the CSS Flexbox specification from
/// - <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Flexible_box_layout/Basic_concepts">the Mozilla developer website</a>
/// - <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/">A Complete Guide To Flexbox by CSS Tricks</a>. This is detailed guide with illustrations and comprehensive written explanation of the different Flexbox properties and how they work.
///
/// \group:layouts
FlexboxLayout {
//! ## Spacing Properties
/// The distance between the elements in the layout. CSS Flexbox usually calls this "gap", but "spacing" is used in Slint for consistency with other layout types.
/// This single value is applied as both horizontal and vertical spacing between items.
in property <length> spacing;
//! To target specific directions with different values use the following properties:
/// The horizontal distance between items in the layout. CSS Flexbox calls this "column-gap".
in property <length> spacing-horizontal;
/// The vertical distance between items in the layout. CSS Flexbox calls this "row-gap".
in property <length> spacing-vertical;
//! ## Padding Properties
//!
//! ### padding
//! <SlintProperty propName="padding" typeName="length">
//! The padding around the layout as a whole. This single value is applied to all sides.
//! </SlintProperty>
//!
//! To target specific sides with different values use the following properties:
//! ### padding-left
//! <SlintProperty propName="padding-left" typeName="length"/>
//!
//! ### padding-right
//! <SlintProperty propName="padding-right" typeName="length"/>
//!
//! ### padding-top
//! <SlintProperty propName="padding-top" typeName="length"/>
//!
//! ### padding-bottom
//! <SlintProperty propName="padding-bottom" typeName="length"/>
//!
//! ## Alignment Properties
/// Set the alignment of items along the main axis. CSS Flexbox calls this "justify-content".
/// With `stretch`, items grow along the main axis to fill each line,
/// weighted by their `horizontal-stretch` (row) or `vertical-stretch` (column) factor.
/// When every factor is 0, the free space is split evenly.
/// Use `max-width`/`max-height` to cap an item's growth;
/// space a capped item cannot take stays free at the end of the line.
/// CSS Flexbox expresses this per item with `flex-grow` instead.
in property <LayoutAlignment> alignment: LayoutAlignment.start; // CSS default is flex-start
//! ## Direction Properties
/// The primary direction in which items are placed. Set to `row` to place items horizontally left-to-right (default), or `column` to place items vertically top-to-bottom.
/// It also supports `row-reverse` and `column-reverse` which invert the flow: `row-reverse` places items right-to-left (starting at the right edge), and `column-reverse` places items bottom-to-top (starting at the bottom edge).
in property <FlexboxLayoutDirection> flex-direction;
/// Set the distribution of flex lines along the cross axis. CSS Flexbox calls this "align-content";
/// the name here pairs with `cross-axis-alignment`, which aligns the items within one line.
/// The default value is `stretch`.
in property <LayoutAlignment> cross-axis-line-alignment;
/// Set the alignment of individual items along the cross axis within each flex line.
/// CSS Flexbox calls this "align-items". The default value is `stretch`.
in property <CrossAxisAlignment> cross-axis-alignment;
/// Controls whether flex items wrap onto multiple lines when they don't fit in the container.
/// The default value is `wrap`, unlike CSS where it is `nowrap`.
in property <FlexboxLayoutWrap> flex-wrap;
}
}
element! {
/// The `MoveTo` sub-element closes the current sub-path, if present, and moves the current point
/// to the location specified by the `x` and `y` properties. Subsequent elements such as `LineTo`
/// will use this new position as their starting point, therefore this starts a new sub-path.
@is_non_item_type @builtin_struct(PathMoveTo)
MoveTo {
/// The x position of the new current point.
in property <float> x;
/// The y position of the new current point.
in property <float> y;
}
}
element! {
/// The `LineTo` sub-element describes a line from the path's current position to the
/// location specified by the `x` and `y` properties.
@is_non_item_type @builtin_struct(PathLineTo)
LineTo {
/// The target x position of the line.
in property <float> x;
/// The target y position of the line.
in property <float> y;
}
}
element! {
/// The `ArcTo` sub-element describes the portion of an ellipse. The arc is drawn from the path's
/// current position to the location specified by the `x` and `y` properties. The remaining properties
/// are modelled after the SVG specification and allow tuning visual features such as the direction
/// or angle.
@is_non_item_type @builtin_struct(PathArcTo)
ArcTo {
/// Out of the two arcs of a closed ellipse, this flag selects that the larger arc is to be rendered. If the property is `false`, the shorter arc is rendered instead.
in property <bool> large-arc;
/// The x-radius of the ellipse.
in property <float> radius-x;
/// The y-radius of the ellipse.
in property <float> radius-y;
/// If the property is `true`, the arc will be drawn as a clockwise turning arc; anti-clockwise otherwise.
in property <bool> sweep;
/// The x-axis of the ellipse will be rotated by the value of this properties, specified in as angle in degrees from 0 to 360.
in property <float> x-rotation;
/// The target x position of the line.
in property <float> x;
/// The target y position of the line.
in property <float> y;
}
}
element! {
/// The `CubicTo` sub-element describes a smooth Bézier from the path's current position to the
/// location specified by the `x` and `y` properties, using two control points specified by their
/// respective properties.
@is_non_item_type @builtin_struct(PathCubicTo)
CubicTo {
/// The x coordinate of the curve's first control point.
in property <float> control-1-x;
/// The y coordinate of the curve's first control point.
in property <float> control-1-y;
/// The x coordinate of the curve's second control point.
in property <float> control-2-x;
/// The y coordinate of the curve's second control point.
in property <float> control-2-y;
/// The target x position of the curve.
in property <float> x;
/// The target y position of the curve.
in property <float> y;
}
}
element! {
/// The QuadraticTo sub-element describes a smooth Bézier from the path's current position to the
/// location specified by the `x` and `y` properties, using the control points specified by the
/// `control-x` and `control-y` properties.
@is_non_item_type @builtin_struct(PathQuadraticTo)
QuadraticTo {
/// The x coordinate of the curve's control point.
in property <float> control-x;
/// The y coordinate of the curve's control point.
in property <float> control-y;
/// The target x position of the curve.
in property <float> x;
/// The target y position of the curve.
in property <float> y;
}
}
element! {
/// The `Close` element closes the current sub-path and draws a straight line from the current
/// position to the beginning of the path.
@is_non_item_type @builtin_struct(PathClose)
Close
}
item! { Path {
/// The color for filling the shape of the path.
in property <brush> fill;
/// The fill rule to use for the path.
/// \default nonzero
in property <FillRule> fill-rule;
/// The color for drawing the outline of the path.
in property <brush> stroke;
/// The width of the outline.
in property <length> stroke-width;
/// The appearance of the ends of the path's outline.
/// \default butt
in property <LineCap> stroke-line-cap;
/// The appearance of the joins between segments of stroked paths.
/// \default miter
in property <LineJoin> stroke-line-join;
/// The limit on the ratio of the miter length to the stroke width when `stroke-line-join` is set to `miter`.
/// When the limit is exceeded, the join is rendered as a bevel instead.
in property <float> stroke-miter-limit: 4; // SVG default is 4
//! ### width
//! <SlintProperty propName="width" typeName="length">
//! If non-zero, the path will be scaled to fit into the specified width.
//! </SlintProperty>
//!
//! ### height
//! <SlintProperty propName="height" typeName="length">
//! If non-zero, the path will be scaled to fit into the specified height.
//! </SlintProperty>
//!
@fake in property <string> commands;
/// Defines how the path's view box is scaled to fit the element's width and height.
/// If no view box is defined, the implicit bounding rectangle is used.
/// \default contain
in property <ImageFit> fit: ImageFit.contain;
/// By default, when a path has a view box defined and the elements render
/// outside of it, they are still rendered. When this property is set to `true`, then rendering will be
/// clipped at the boundaries of the view box.
/// \default false
in property <bool> clip;
/// By default, the fill and stroke of a path is rendered with anti-aliasing, for best quality. Some GPUs
/// have performance issues when rendering with anti-aliasing and animation. Setting the value to `false`
/// might improve the frame-rate at the expense of a smoother looking path.
/// \default true
in property <bool> anti-alias: true;
//! ## Viewbox Properties
//!
//! These four properties allow defining the position and size of the viewport of the path in path coordinates.
//!
//! If the `viewbox-width` or `viewbox-height` is less or equal than zero, the viewbox properties are
//! ignored and instead the bounding rectangle of all path elements is used to define the view port.
///
in property <float> viewbox-x;
///
in property <float> viewbox-y;
///
in property <float> viewbox-width;
///
in property <float> viewbox-height;
/// Returns a point at the given percent along the path in the Path element's coordinate space.
/// Returns (0, 0) if the path is empty.
///
/// If a `t` outside the bounds of 0 and 1 is passed, it will be converted to its decimal fraction.
/// Ex: 1.5 -> 0.5 and 2.0 -> 1.0. This allows for N iterations of a loop
/// by animating t from 0 to N. If `t` is animated from N to 0, it will loop N times backwards.
@pure function point-at(t: float) -> Point { BuiltinFunction.PathPointAt }
/// Returns the angle (in degrees) between the x-axis and the path's tangent vector at the given `t`.
/// The tangent points in the direction the path was defined, so this reflects the path's shape and not
/// the object's current direction of travel. Returns 0 if the path is empty.
/// If a `t` outside the bounds of 0 and 1 is passed, the decimal fraction will be passed.
@pure function angle-at(t: float) -> angle { BuiltinFunction.PathAngleAt }
//!
//! ## Path Using SVG Commands
//!
//! SVG is a popular file format for defining scalable graphics, which are often composed of paths. In SVG
//! paths are composed using [commands](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#path_commands),
//! which in turn are written in a string. In `.slint` the path commands are provided to the `commands`
//! property. The following example renders a shape consists of an arc and a rectangle, composed of `line-to`,
//! `move-to` and `arc` commands:
//!
//! ```slint
//! export component Example inherits Path {
//! width: 100px;
//! height: 100px;
//! commands: "M 0 0 L 0 100 A 1 1 0 0 0 100 100 L 100 0 Z";
//! stroke: red;
//! stroke-width: 1px;
//! }
//! ```
//!
//! The commands are provided in a property:
//!
//! ### Commands
//! <SlintProperty propName="commands" typeName="string">
//! A string providing the commands according to the SVG path specification.
//! This property can only be set in a binding and cannot be accessed in an expression.
//! </SlintProperty>
//!
//! ## Path Using SVG Path Elements
//!
//! The shape of the path can also be described using elements that resemble the SVG path commands but use the
//! `.slint` markup syntax. The earlier example using SVG commands can also be written like that:
//!
//! ```slint
//! export component Example inherits Path {
//! width: 100px;
//! height: 100px;
//! stroke: blue;
//! stroke-width: 1px;
//!
//! MoveTo {
//! x: 0;
//! y: 0;
//! }
//! LineTo {
//! x: 0;
//! y: 100;
//! }
//! ArcTo {
//! radius-x: 1;
//! radius-y: 1;
//! x: 100;
//! y: 100;
//! }
//! LineTo {
//! x: 100;
//! y: 0;
//! }
//! Close {
//! }
//! }
//! ```
//!
//! Note how the coordinates of the path elements don't use units - they operate within the imaginary
//! coordinate system of the scalable path.
} }
element! {
/// The `Path` element allows rendering a generic shape, composed of different geometric commands. A path
/// shape can be filled and outlined.
///
/// When not part of a layout, its width or height defaults to 100% of the parent element when not specified.
///
/// A path can be defined in two different ways:
///
/// - Using SVG path commands as a string
/// - Using path command elements in `.slint` markup.
///
/// The coordinates used in the geometric commands are within the imaginary coordinate system of the path.
/// When rendering on the screen, the shape is drawn relative to the `x` and `y` properties. If the `width`
/// and `height` properties are non-zero, then the entire shape is fit into these bounds - by scaling
/// accordingly.
/// \group:elements
@disallow_global_types_as_child_elements @expands_to_parent_geometry
Path: Path {
children: MoveTo, LineTo, ArcTo, CubicTo, QuadraticTo, Close;
}
}
element! {
Tab {
in property <string> title;
}
}
element! {
// Note: not a native class, handled in the lower_tabs pass
@is_internal @disallow_global_types_as_child_elements @expands_to_parent_geometry
TabWidget {
in-out property <int> current-index;
@constexpr in property <Orientation> orientation;
children: Tab;
}
}
element! {
RadioButton {
in property <string> text;
in property <bool> enabled: true;
in-out property <bool> checked;
callback toggled;
}
}
element! {
// Note: not a native class, handled in the lower_radiogroup pass
@is_internal @disallow_global_types_as_child_elements
RadioGroup {
in property <string> title;
in property <bool> enabled: true;
in property <Orientation> orientation;
out property <string> current-value;
out property <bool> has-focus;
callback selected(value: string);
children: RadioButton;
}
}
element! {
/// ```slint playground
/// export component Example inherits Window {
/// width: 100px;
/// height: 100px;
///
/// popup := PopupWindow {
/// Rectangle { height:100%; width: 100%; background: yellow; }
/// x: 20px; y: 20px; height: 50px; width: 50px;
/// }
///
/// TouchArea {
/// height:100%; width: 100%;
/// clicked => { popup.show(); }
/// }
/// }
/// ```
///
/// Use this element to show a popup window like a tooltip or a popup menu.
///
/// :::note{Note}
/// It isn't allowed to access properties of elements within the popup from outside of the `PopupWindow`. See [#4438](https://github.com/slint-ui/slint/issues/4438).
/// :::
/// \group:window
PopupWindow {
//property <length> x;
//property <length> y;
in property <length> width;
in property <length> height;
/*property <length> anchor_x;
in property <length> anchor-y;
in property <length> anchor-height;
in property <length> anchor-width;*/
@constexpr in property <bool> close-on-click;
/// By default, a PopupWindow closes when the user clicks. Set this to false to prevent that behavior and close it manually using the `close()` function.
/// \default close-on-click
@constexpr in property <PopupClosePolicy> close-policy;
/// Use this read-only property to style the element that opened the popup, for example
/// to rotate a ComboBox's arrow while the dropdown is open.
/// `true` while the popup is shown on the screen, and `false` once it is closed, for example
/// when dismissed by a click, by a selection, or by a programmatic `close()`.
out property <bool> is-open;
/// Show the popup on the screen.
function show() { BuiltinFunction.ShowPopupWindow }
/// Closes the popup. Use this if you set the `close-policy` property to `no-auto-close`.
function close() { BuiltinFunction.ClosePopupWindow }
}
}
item! { TooltipArea: Empty {
// Set when the mouse is over the parent's region while this area is expanded to fill it during lowering.
out property <bool> has-hover;
// Pointer x within this area during hover.
out property <length> mouse-x;
// Pointer y within this area during hover.
out property <length> mouse-y;
// Tooltip configuration folded from the user-facing Tooltip element during lowering.
in property <styled-text> text;
// Delay and offset are not user-facing in 1.17; the values used here are the
// built-in defaults applied to the synthesized element on instantiation.
in property <duration> delay: 500ms;
in property <length> offset: 8px;
callback show;
callback hide;
} }
element! {
// Internal hover tracker used with `Tooltip` lowering (the compiler inserts `TooltipArea` so `Tooltip` can react to hover and pointer position).
@is_internal @expands_to_parent_geometry
TooltipArea: TooltipArea
}
element! {
/// ```slint playground
/// import { Button } from "std-widgets.slint";
///
/// export component Example inherits Window {
/// width: 280px;
/// height: 160px;
///
/// VerticalLayout {
/// alignment: center;
///
/// Button {
/// text: "Hover me";
///
/// Tooltip {
/// text: @markdown("This is a tooltip");
/// }
/// }
/// }
/// }
/// ```
///
/// Place a `Tooltip` inside any element to show helpful information when hovering over it.
/// The tooltip appears after a short delay near the pointer and hides when the pointer leaves.
///
/// Set the `text` property for a simple text tooltip,
/// or add a child element instead for custom content.
///
/// Each element can contain at most one `Tooltip`.
///
/// \footer
/// ## Custom Content
///
/// For richer tooltips, omit `text` and provide your own layout inside a single child element.
///
///
/// ```slint playground
/// import { Button, VerticalBox, HorizontalBox } from "std-widgets.slint";
///
/// export component Example inherits Window {
/// width: 320px;
/// height: 200px;
///
/// VerticalLayout {
/// alignment: center;
///
/// Button {
/// text: "Custom tooltip";
///
/// Tooltip {
/// VerticalBox {
/// padding: 10px;
/// spacing: 6px;
///
/// Text {
/// text: "Quick Actions";
/// font-weight: 700;
/// color: #fff;
/// }
///
/// Text {
/// text: "Open command palette and search settings.";
/// color: #d1d5db;
/// wrap: word-wrap;
/// }
///
/// HorizontalBox {
/// spacing: 6px;
///
/// Rectangle {
/// border-radius: 4px;
/// background: #374151;
/// HorizontalBox {
/// padding: 4px;
/// Text { text: "Ctrl"; color: #fff; }
/// }
/// }
///
/// Rectangle {
/// border-radius: 4px;
/// background: #374151;
/// HorizontalBox {
/// padding: 4px;
/// Text { text: "K"; color: #fff; }
/// }
/// }
/// }
/// }
/// }
/// }
/// }
/// }
/// ```
/// \group:window
@is_non_item_type @can_be_declared_without_children_slot
Tooltip: Empty {
/// The text to display in the tooltip.
/// Don't set this property when using custom content.
in property <styled-text> text;
}
}
element! {
/// :::note[Note]
/// Timer is not an actual element visible in the tree, therefore it doesn't have the common properties such as `x`, `y`, `width`, `height`, etc. It also doesn't take room in a layout and cannot have any children or be inherited from.
/// :::
///
/// This example shows a timer that counts down from 10 to 0 every second:
///
/// ```slint playground
/// import { Button } from "std-widgets.slint";
/// export component Example inherits Window {
/// property <int> value: 10;
/// timer := Timer {
/// interval: 1s;
/// running: true;
/// triggered() => {
/// value -= 1;
/// if (value == 0) {
/// self.running = false;
/// }
/// }
/// }
/// HorizontalLayout {
/// Text { text: value; }
/// Button {
/// text: "Reset";
/// clicked() => { value = 10; timer.running = true; }
/// }
/// }
/// }
/// ```
///
///
///
/// Use the Timer pseudo-element to schedule a callback at a given interval.
/// The timer is only running when the `running` property is set to `true`. To stop or start the timer, set that property to `true` or `false`.
/// It can be also set to a binding expression.
/// When already running, the timer will be restarted if the `interval` property is changed.
///
/// :::caution[Caution]
/// By default the `Timer` is always running `running: true`. This can result in constant CPU usage and
/// power usage so ensure that you set `running` to `false` when you don't want the timer to run.
/// :::
///
/// ```slint
/// property <int> count: 0;
/// Timer {
/// interval: 8s; // every 8 seconds the timer will activate (tick)
/// triggered() => { // The triggered callback activates every time the timer ticks
/// if count >= 5 {
/// self.running = false; // stop the timer after 5 ticks
/// }
/// count += 1;
/// }
/// }
/// ```
@is_non_item_type @disallow_global_types_as_child_elements
Timer {
/// The interval between timer ticks. This property is mandatory.
/// ```slint "interval: 250ms;"
/// Timer {
/// property <int> count: 0;
/// interval: 250ms;
/// triggered() => {
/// debug("count is:", count);
/// count += 1;
/// }
/// }
/// ```
in property <duration> interval;
/// `true` if the timer is running.
/// ```slint "running: false; // timer is not running"
/// Timer {
/// property <int> count: 0;
/// interval: 250ms;
/// running: false; // timer is not running
/// triggered() => {
/// debug("count is:", count);
/// }
/// }
/// ```
in property <bool> running: true;
/// Invoked every time the timer ticks (every `interval`).
/// ```slint {4-6}
/// Timer {
/// property <int> count: 0;
/// interval: 250ms;
/// triggered() => {
/// debug("count is:", count);
/// }
/// }
/// ```
callback triggered;
/// Start the timer (equivalent to setting `running` to true).
function start() { BuiltinFunction.StartTimer }
/// Stop the timer (equivalent to setting `running` to false).
function stop() { BuiltinFunction.StopTimer }
/// Restarts the timer if it was previously started.
function restart() { BuiltinFunction.RestartTimer }
}
}
element! {
/// ```slint playground imageAlt="dialog example" width="200" height="100"
/// import { StandardButton, Button } from "std-widgets.slint";
/// export component Example inherits Dialog {
/// Text {
/// text: "This is a dialog box";
/// }
/// StandardButton { kind: ok; }
/// StandardButton { kind: cancel; }
/// Button {
/// text: "More Info";
/// dialog-button-role: action;
/// }
/// }
/// ```
///
/// Dialog can be used in place of <Link type="Window"/>, but it has buttons that are automatically laid out.
///
/// A Dialog should have one main element as child, that isn't a button.
/// The dialog can have any number of `StandardButton` widgets or other buttons
/// with the `dialog-button-role` property.
/// The buttons will be placed in an order that depends on the target platform at run-time.
///
/// The `kind` property of the `StandardButton`s and the `dialog-button-role` properties need to be set to a constant value, it can't be an arbitrary variable expression.
/// There can't be several `StandardButton`s of the same kind.
///
/// A callback `<kind>_clicked` is automatically added for each `StandardButton` which doesn't have an explicit
/// callback handler, so it can be handled from the native code: For example if there is a button of kind `cancel`,
/// a `cancel_clicked` callback will be added.
/// Each of these automatically-generated callbacks is an alias for the `clicked` callback of the associated `StandardButton`.
///
/// ## Properties
///
/// Same as <Link type="Window"/>.
///
/// ## Functions
///
/// Same as <Link type="Window"/>.
/// \group:window
@skip_inherited
Dialog: WindowItem
}
element! {
@is_non_item_type
PropertyAnimation {
in property <duration> delay;
in property <duration> duration;
in property <AnimationDirection> direction;
in property <easing> easing;
in property <float> iteration-count: 1.0;
in property <bool> enabled: true;
}
}
element! {
/// ```slint
/// import { LineEdit } from "std-widgets.slint";
///
/// component VKB {
/// Rectangle { background: yellow; }
/// }
///
/// export component Example inherits Window {
/// width: 200px;
/// height: 100px;
/// VerticalLayout {
/// LineEdit {}
/// FocusScope {}
/// if TextInputInterface.text-input-focused: VKB {}
/// }
/// }
/// ```
///
/// \group:keyboard-input
@is_global
TextInputInterface {
//! ## Properties
//!
//! The `TextInputInterface.text-input-focused` property can be used to find out if a `TextInput` element has the focus.
//! If you're implementing your own virtual keyboard, this property is an indicator whether the virtual keyboard should be shown or hidden.
/// True if an `TextInput` element has the focus; false otherwise.
in property <bool> text-input-focused;
}
}
element! {
/// The **Platform** namespace contains properties that help deal with platform specific differences.
@is_global
Platform {
/// This property holds the type of the operating system detected at run-time.
///
/// :::note{Note}
/// When running in a web browser, the value of this property is computed at run-time by querying the web browser's navigator properties.
/// :::
///
/// :::note{Note}
/// When Slint is ported to new operating systems in the future, new enum values will be added.
/// :::
out property <OperatingSystemType> os;
/// `true` when the `.slint` file is being interpreted on its own, with nothing behind it, such as
/// when previewed with `slint-viewer` or the editor's preview, and `false` when the user interface
/// is driven by a host application: your business logic written in Rust, C++, JavaScript or Python.
///
/// Use it to provide placeholder data and preview-only decorations that are removed from your
/// compiled application. This property is a compile-time constant, so branches that depend on it
/// are optimized away when the value is known to be `false` or `true`.
//
// ```slint playground
// import { ListView, VerticalBox } from "std-widgets.slint";
//
// export struct Data {
// text: string,
// color: color,
// bg: color,
// }
// export component Example inherits Window {
// width: 150px;
// height: 150px;
// in property<[Data]> data: Platform.uses-mock-data ? [
// { text: "Blue", color: #0000ff, bg: #eeeeee},
// { text: "Red", color: #ff0000, bg: #eeeeee},
// { text: "Green", color: #00ff00, bg: #eeeeee},
// { text: "Yellow", color: #ffff00, bg: #222222 },
// { text: "Black", color: #000000, bg: #eeeeee },
// { text: "White", color: #ffffff, bg: #222222 },
// { text: "Magenta", color: #ff00ff, bg: #eeeeee },
// { text: "Cyan", color: #00ffff, bg: #222222 },
// ] : [];
//
// VerticalBox {
// ListView {
// for data in root.data : Rectangle {
// height: 30px;
// background: data.bg;
// width: parent.width;
// Text {
// x: 0;
// text: data.text;
// color: data.color;
// }
// }
// }
// }
// }
// ```
out property <bool> uses-mock-data;
/// The name of the currently selected <Link type="StyleWidgets" label="widget style"/>. Some widget
/// styles have dark and light variant suffixes, such as `fluent-light`. This property contains the
/// style name without the suffix. Use <Link type="Palette" label="Palette"/>'s `color-scheme` to
/// determine the currently used scheme.
out property <string> style-name;
/// The decimal separator used when converting between `float` and `string`.
/// It defaults to the dot (`.`) and is determined by the locale.
/// See the <Link type="translations" label="translations guide"/> for details.
out property <string> decimal-separator;
/// Opens the specified URL in an external browser. This function invokes the platform's URL opening mechanism.
/// Returns `true` on success, or `false` if the platform doesn't support opening URLs or the operation failed.
///
/// ```slint playground
/// import { Button } from "std-widgets.slint";
///
/// export component Example inherits Window {
/// Button {
/// text: "Open Slint Website";
/// clicked => {
/// Platform.open-url("https://slint.dev");
/// }
/// }
/// }
/// ```
function open-url(url: string) -> bool { }
/// Brings all application windows to the front of the screen.
///
/// On macOS this invokes `[NSApp arrangeInFront:]`, which raises every application window
/// to the top of the window stack. On other platforms this function is a no-op.
///
/// This corresponds to the standard macOS **Window › Bring All to Front** menu item.
function macos-bring-all-windows-to-front() { }
}
}
item! { NativeButton {
in property <string> text;
in property <image> icon;
out property <bool> pressed;
in property <bool> checkable;
in-out property <bool> checked;
out property <bool> has-focus;
in property <bool> primary;
in property <bool> colorize-icon;
in property <length> icon-size;
callback clicked;
in property <bool> enabled: true;
in property <StandardButtonKind> standard-button-kind;
in property <bool> is-standard-button;
} }
element! {
@is_internal @accepts_focus
NativeButton: NativeButton
}
item! { NativeCheckBox {
in property <bool> enabled: true;
in property <string> text;
in-out property <bool> checked;
out property <bool> has-focus;
callback toggled;
} }
element! {
@is_internal @accepts_focus
NativeCheckBox: NativeCheckBox
}
item! { NativeSpinBox {
in property <bool> enabled: true;
out property <bool> has-focus;
in-out property <int> value;
in property <int> minimum;
in property <int> maximum: 100;
in property <int> step-size: 1;
in property <TextHorizontalAlignment> horizontal-alignment;
in property <bool> read-only;
callback edited(value: int);
} }
element! {
@is_internal @accepts_focus
NativeSpinBox: NativeSpinBox
}
item! { NativeSlider {
in property <bool> enabled: true;
out property <bool> has-focus;
in-out property <float> value;
in property <float> minimum;
in property <float> maximum: 100;
in property <float> step: 1;
in property <Orientation> orientation: Orientation.horizontal;
callback changed(value: float);
callback released(value: float);
} }
element! {
@is_internal @accepts_focus
NativeSlider: NativeSlider
}
item! { NativeProgressIndicator {
in property <bool> indeterminate;
in property <float> progress;
} }
element! {
@is_internal
NativeProgressIndicator: NativeProgressIndicator
}
item! { NativeGroupBox {
in property <bool> enabled: true;
in property <string> title;
out property <length> native-padding-left;
out property <length> native-padding-right;
out property <length> native-padding-top;
out property <length> native-padding-bottom;
} }
element! {
@is_internal @expands_to_parent_geometry
NativeGroupBox: NativeGroupBox
}
item! { NativeLineEdit {
out property <length> native-padding-left;
out property <length> native-padding-right;
out property <length> native-padding-top;
out property <length> native-padding-bottom;
out property <image> clear-icon;
in property <bool> has-focus;
in property <bool> enabled: true;
} }
element! {
@is_internal
NativeLineEdit: NativeLineEdit
}
item! { NativeScrollView {
in property <length> horizontal-max;
in property <length> horizontal-page-size;
in property <length> horizontal-value;
in property <length> vertical-max;
in property <length> vertical-page-size;
in-out property <length> vertical-value;
out property <length> native-padding-left;
out property <length> native-padding-right;
out property <length> native-padding-top;
out property <length> native-padding-bottom;
in property <bool> has-focus;
in property <ScrollBarPolicy> vertical-scrollbar-policy;
in property <ScrollBarPolicy> horizontal-scrollbar-policy;
in property <bool> enabled: true;
callback scrolled;
} }
element! {
@is_internal @expands_to_parent_geometry
NativeScrollView: NativeScrollView
}
item! { NativeStandardListViewItem {
in property <int> index;
in property <StandardListViewItem> item;
in-out property <bool> is-selected;
in property <bool> has-hover;
in property <bool> has-focus;
in property <bool> pressed;
in property <bool> combobox;
in property <length> pressed-x;
in property <length> pressed-y;
} }
element! {
@is_internal
NativeStandardListViewItem: NativeStandardListViewItem
}
item! { NativeTableHeaderSection {
in property <int> index;
in property <TableColumn> item;
in property <bool> has-hover;
} }
element! {
@is_internal
NativeTableHeaderSection: NativeTableHeaderSection
}
item! { NativeComboBox {
in-out property <string> current-value;
in property <bool> enabled: true;
in property <bool> has-focus;
} }
element! {
@is_internal
NativeComboBox: NativeComboBox
}
item! { NativeComboBoxPopup { } }
element! {
@is_internal
NativeComboBoxPopup: NativeComboBoxPopup
}
item! { NativeTabWidget {
in property <length> width;
in property <length> height;
out property <length> content-x;
out property <length> content-y;
out property <length> content-height;
out property <length> content-width;
out property <length> tabbar-x;
out property <length> tabbar-y;
out property <length> tabbar-height;
out property <length> tabbar-width;
in property <length> tabbar-preferred-height;
in property <length> tabbar-preferred-width;
in property <length> content-min-height;
in property <length> content-min-width;
in property <int> current-index;
in property <int> current-focused;
in property <Orientation> orientation: Orientation.horizontal;
} }
element! {
@is_internal @expands_to_parent_geometry
NativeTabWidget: NativeTabWidget
}
item! { NativeTab {
in property <string> title;
in property <image> icon;
in property <bool> enabled: true;
in-out property <int> current; // supposed to be a binding to the tab
in property <int> tab-index;
in property <int> current-focused;
in property <int> num-tabs;
} }
element! {
@is_internal
NativeTab: NativeTab
}
item! { NativeStyleMetrics {
out property <length> layout-spacing;
out property <length> layout-padding;
out property <length> text-cursor-width;
out property <color> window-background;
out property <color> default-text-color;
out property <color> textedit-background;
out property <color> textedit-text-color;
out property <color> textedit-background-disabled;
out property <color> textedit-text-color-disabled;
out property <bool> dark-color-scheme;
// specific to the Native one
out property <color> placeholder-color;
out property <color> placeholder-color-disabled;
// Tab Bar metrics:
out property <LayoutAlignment> tab-bar-alignment;
} }
element! {
@is_internal @is_non_item_type @is_global
NativeStyleMetrics: NativeStyleMetrics
}
item! { NativePalette {
out property <brush> background;
out property <brush> foreground;
out property <brush> alternate-background;
out property <brush> alternate-foreground;
out property <brush> control-background;
out property <brush> control-foreground;
out property <brush> accent-background;
out property <brush> accent-foreground;
out property <brush> selection-background;
out property <brush> selection-foreground;
out property <brush> border;
in-out property <ColorScheme> color-scheme;
} }
element! {
@is_internal @is_non_item_type @is_global
NativePalette: NativePalette
}
item! { SystemTrayIcon {
/// The icon shown in the system tray. The image is scaled by the platform to the size expected
/// for tray icons. Use `@image-url(...)` to embed an icon asset, or bind to an `image` property
/// fed from your code. The tray icon is only created once a non-empty image has been assigned.
in property <image> icon;
/// The hover text shown over the tray icon.
/// Typically the application name or a short status message.
in property <string> tooltip;
/// Whether the tray icon is registered with the OS.
/// Set it to `false` to hide the icon without dropping the component instance, and back to `true` to show it again.
/// The `show()` and `hide()` methods on the language-binding side are convenience aliases that set this property.
in property <bool> visible: true;
/// A descriptive name for the tray entry, separate from the hover tooltip.
/// Where it actually shows up depends on the platform:
///
/// | Platform | Where `title` appears |
/// | ------------- | ------------------------------------------------------------------------------------------------ |
/// | Linux, \*BSD | Used by accessibility tools and shown by some desktops when listing tray icons (e.g. an overflow menu). Set as the [StatusNotifierItem `Title`](https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem/) property. |
/// | macOS | The visible text label rendered next to the icon in the menu bar (think battery percent, clock). |
/// | Windows | Has no visible effect; the notification area renders only the icon. |
in property <string> title;
/// Invoked when the user left-clicks the tray icon itself, as opposed to picking an entry from its menu.
/// Whether it's invoked at all depends on the platform:
///
/// | Platform | Click behavior |
/// | ------------- | ------------------------------------------------------------------------------------- |
/// | Linux, \*BSD | Invoked on a left-click of the icon. The exact gesture is decided by the desktop environment or shell extension hosting the tray. |
/// | macOS | Invoked on a left-click when no `Menu` is attached (or when an `if cond : Menu { ... }`'s condition is currently false). When a populated menu is attached, AppKit pops it open instead and `clicked` doesn't fire. |
/// | Windows | Invoked on a left-click of the icon. Right-click opens the menu. |
callback clicked;
} }
element! {
// Lowered in lower_menus pass. See that pass documentation for more info.
// The optional Menu child is lifted into a separate item tree and wired via
// the `SetupSystemTrayIcon` builtin.
/// Use the `SystemTrayIcon` element to add an icon and menu to the desktop's system tray,
/// also known as the notification area, status area, or menu bar extras, depending on the platform.
///
/// `SystemTrayIcon` is a top-level component: derive your own component
/// from it with `inherits SystemTrayIcon` instead of placing it inside a <Link type="Window" />.
/// A `SystemTrayIcon` component has no window of its own — the icon lives in the tray, and the only UI
/// it presents is the menu.
///
/// ```slint
/// export component ExampleTray inherits SystemTrayIcon {
/// icon: @image-url("tray-icon.png");
/// tooltip: "My App";
///
/// Menu {
/// MenuItem {
/// title: "Quit";
/// activated => { quit(); }
/// }
/// }
///
/// callback quit();
/// }
/// ```
///
/// Create the component from your language binding as you would any other Slint component;
/// the tray icon appears as soon as the instance is created and an event loop is running,
/// and disappears when the instance is dropped.
///
/// :::note{Note}
/// A `SystemTrayIcon` exported alongside a `Window` doesn't share <Link type="Globals" label="globals" /> with that window — each instance gets its own copy.
/// You may need to initialize the relevant globals on each instance, the same way you would across multiple windows.
/// :::
///
/// :::note{Note}
/// A `SystemTrayIcon` must contain exactly one <Link type="Menu" /> child, and that `Menu` must not
/// be inside an `if` or a `for`. No other child element types are permitted. The menu itself may
/// use `if` / `for` to build its entries dynamically.
/// :::
///
/// \skip_children
/// \footer
/// ## Menu
///
/// The child `Menu` defines the menu that is shown when the user clicks or right-clicks the tray
/// icon. Its structure is the same as for <Link type="MenuBar" /> and `ContextMenuArea`: use
/// `MenuItem` for entries, nested `Menu` elements for sub-menus, and `MenuSeparator` for
/// separators. See <Link type="Menu" /> for the properties and callbacks available on those
/// elements.
///
/// The menu tree is reactive: when any property the menu reads changes (for example the `title`,
/// `enabled`, or `checked` binding of a `MenuItem`), Slint rebuilds the platform menu so the tray
/// reflects the new state on its next open.
///
/// Keyboard `shortcut` bindings on `MenuItem`s within a `SystemTrayIcon` are ignored — tray menus are
/// not attached to a focused window, so there is nothing for the shortcut to fire against.
///
/// ## Language Bindings
///
/// The generated public API for a `SystemTrayIcon`-rooted component is smaller than the one
/// for a `Window`-rooted component. Construction, property and callback accessors, and global
/// access work the same way. Two things are missing:
///
/// | Operation | Window-rooted | SystemTrayIcon-rooted |
/// | ---------------------- | :-----------: | :---------------: |
/// | access the window | yes | **no** |
/// | run the event loop | yes | **no** |
///
/// `show` and `hide` exist on both, but on a `SystemTrayIcon` they set the `visible` property,
/// and the platform backend translates that into the native tray API.
/// A visible `SystemTrayIcon` keeps the event loop alive the same way a visible window does.
///
/// A typical app instantiates both a main window and a tray, shows them, and runs the event loop.
/// The snippets below also wire the built-in `clicked` callback so a left-click on the tray icon
/// brings the window back if the user has hidden it.
///
/// <Tabs syncKey="dev-language">
/// <TabItem label="Rust">
/// ```rust
/// fn main() -> Result<(), slint::PlatformError> {
/// let window = MainWindow::new()?;
/// let tray = ExampleTray::new()?;
///
/// let window_weak = window.as_weak();
/// tray.on_clicked(move || {
/// if let Some(w) = window_weak.upgrade() {
/// let _ = w.show();
/// }
/// });
///
/// window.show()?;
/// tray.show()?;
/// slint::run_event_loop()
/// }
/// ```
/// </TabItem>
/// <TabItem label="C++">
/// ```cpp
/// int main() {
/// auto window = MainWindow::create();
/// auto tray = ExampleTray::create();
///
/// auto window_weak = slint::ComponentWeakHandle(window);
/// tray->on_clicked([window_weak] {
/// if (auto w = window_weak.lock()) {
/// (*w)->show();
/// }
/// });
///
/// window->show();
/// tray->show();
/// slint::run_event_loop();
/// }
/// ```
/// </TabItem>
/// <TabItem label="NodeJS">
/// ```js
/// const window = new ui.MainWindow();
/// const tray = new ui.ExampleTray();
/// tray.clicked = () => window.show();
/// window.show();
/// tray.show();
/// await slint.runEventLoop();
/// ```
/// </TabItem>
/// <TabItem label="Python">
/// ```python
/// window = module.MainWindow()
/// tray = module.ExampleTray()
/// tray.clicked = lambda: window.show()
/// window.show()
/// tray.show()
/// slint.run_event_loop()
/// ```
/// </TabItem>
/// </Tabs>
///
/// A program that exposes only a `SystemTrayIcon` and no window is also valid: skip the
/// `MainWindow` instance, and the loop quits once the tray is hidden (or `slint::quit_event_loop`
/// is called). No `WindowAdapter` is created in that case — the platform backend is still
/// selected the usual way, but no window opens.
///
/// ## Platform Support
///
/// | Platform | Mechanism |
/// | ------------- | ----------------------------------------------------- |
/// | Linux, \*BSD | `StatusNotifierItem` / `AppIndicator` on D-Bus |
/// | macOS | `NSStatusItem` in the menu bar |
/// | Windows | Shell notification area icon (`Shell_NotifyIcon`) |
///
/// On Linux, a desktop environment or shell extension that implements the `StatusNotifierItem`
/// specification is required; plain X11 system trays are not supported. GNOME, for example,
/// needs an extension such as *AppIndicator and KStatusNotifierItem Support*.
///
/// \group:window
@is_non_item_type @disallow_global_types_as_child_elements
SystemTrayIcon: SystemTrayIcon {
children: Menu;
}
}
}
/// Fill `register` with the builtin elements. It must already contain the basic types
/// (string, int, ...), the builtin structs and enums.
pub(crate) fn load(register: &mut TypeRegister) {
let mut loader = Loader { register, items: HashMap::new(), elements: HashMap::new() };
build(&mut loader);
let Loader { register, elements, .. } = loader;
// Elements that are accepted children of another one are only reachable through it.
let is_child = |name: &SmolStr| {
elements.values().any(|e| e.additional_accepted_child_types.contains_key(name))
};
for (name, element) in &elements {
match name.as_str() {
"Empty" => register.empty_type = ElementType::Builtin(element.clone()),
"PropertyAnimation" => {
register.property_animation_type = ElementType::Builtin(element.clone())
}
_ if !element.is_global && !is_child(name) => register.add_builtin(element.clone()),
_ => {}
}
}
}