-
Notifications
You must be signed in to change notification settings - Fork 985
Expand file tree
/
Copy pathbuiltins.slint
More file actions
2973 lines (2855 loc) · 118 KB
/
Copy pathbuiltins.slint
File metadata and controls
2973 lines (2855 loc) · 118 KB
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
// 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
/**
This file contains the definition off all builtin items
It is parsed with the normal .slint parser, but the semantic.
`_` means that that this is a langtype::NativeClass with no parent.
Exported components are added to the as BuiltinElement.
comments starting by `//-` have some meanings
Properties with two way bindings (aliases) are deprecated in favor of the property they point to
Properties can have default binding which must be an expression without any reference to
another properties. These binding will be then set by the compiler.
`output` property mean that the property can be modified by the native Item,
otherwise it is assumed the native item don't write to that property.
*/
component Empty {
//-is_internal
}
component Rectangle inherits Empty {
/// The background brush of this `Rectangle`.
///
/// ```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
in property <brush> background;
in property <brush> color <=> background;
}
component BasicBorderRectangle inherits 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;
}
/// 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.
///
/// When not part of a layout, its width and height default to 100% of the parent element.
///
/// ```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
component BorderRectangle inherits 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:
//!
//! ### 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.
//-default_size_binding:expands_to_parent_geometry
}
export { BorderRectangle as Rectangle }
component ImageItem inherits 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` type is a reference to an image. It's defined using the `@image-url("...")` construct.
/// The address within the `@image-url` function must be known at compile time.
///
/// Slint looks for images in the following places:
///
/// 1. The absolute path or the path relative to the current `.slint` file.
/// 2. The include path used by the compiler to look up `.slint` files.
///
/// Images can also be loaded from [`data:` URIs](https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data), with either base64 or URL-encoded content.
/// For example: `@image-url("data:image/png;base64,iVBORw0KGgo...")`.
///
/// Access an `image`'s source dimension using its `source.width` and `source.height` properties.
///
/// ```slint
/// export component Example inherits Window {
/// preferred-width: 150px;
/// preferred-height: 50px;
///
/// in property <image> some_image: @image-url("https://slint.dev/logo/slint-logo-full-light.svg");
///
/// Text {
/// text: "The image is " + some_image.width + "x" + some_image.height;
/// }
/// }
/// ```
///
/// ```slint
/// // nine-slice scaling
/// export component Example inherits Window {
/// width: 100px;
/// height: 150px;
/// VerticalLayout {
/// Image {
/// source: @image-url("https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png", nine-slice(30 30 30 30));
/// }
/// }
/// }
/// ```
///
/// Use the <Link type="ImageType" label="`@image-url` macro" /> to specify the image's path.
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;
in property <angle> rotation-angle <=> transform-rotation;
}
/// ```slint imageAlt="image example" width="300" height="200"
/// Image {
/// source: @image-url("mini-banner.png");
/// }
/// ```
///
/// Use the `Image` element to display an <Link type="ImageType" label="image" />.
///
/// \footer
/// ## 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;
/// }
/// ```
/// \group:elements
export component ClippedImage inherits 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:
//-default_size_binding:implicit_size
}
export { ClippedImage as Image }
export component ComponentContainer inherits Empty {
in property <component-factory> component-factory;
out property <bool> has-component;
in-out property <length> width;
in-out property <length> height;
//-accepts_focus
}
export component Transform inherits Empty {
in property <angle> transform-rotation;
in property <percent> transform-scale-x;
in property <percent> transform-scale-y;
in property <Point> transform-origin;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
component SimpleText inherits 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 text rendered.
/// \default ""
in property <string> text;
/// The vertical alignment of the text.
in property <TextVerticalAlignment> vertical-alignment;
//-default_size_binding:implicit_size
in property <angle> rotation-angle <=> transform-rotation;
}
/// ```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
component ComplexText inherits 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 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;
//! ### font-metrics
//! <SlintProperty propName="font-metrics" typeName="struct" structName="FontMetrics" propertyVisibility="out">
//! The design metrics of the font scaled to the font pixel size used by the element.
//! </SlintProperty>
//-default_size_binding:implicit_size
}
export { ComplexText as Text }
/// 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
component StyledTextItem inherits 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 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);
//-default_size_binding:implicit_size
}
export { StyledTextItem as StyledText }
/// Use `TouchArea` to control what happens when the region it covers is touched or interacted with
/// using the mouse.
///
/// When not part of a layout, its width or height default to 100% of the parent element.
///
/// ```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;
/// }
/// }
/// ```
/// \group:gestures
export component 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 type 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.
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;
//-default_size_binding:expands_to_parent_geometry
}
/// ```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
export component 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);
//-default_size_binding:expands_to_parent_geometry
//-accepts_focus
KeyBinding { }
}
/// 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.
component 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();
//-is_non_item_type
}
/// ```slint playground
/// export component Example inherits Window {
/// width: 270px;
/// height: 100px;
///
/// Flickable {
/// viewport-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 `viewport-width` or the `viewport-height` is greater than the parent's `width` or `height`
/// respectively, the element becomes scrollable.
///
/// When unset, the `viewport-width` and `viewport-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 viewport.
///
/// 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.
/// 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.
///
/// All pointer and mouse events that occur within the bounds of a `Flickable` are intercepted by the `Flickable`
/// itself and are not propagated to any elements underneath it.
///
/// ## Wheel/Scroll Event Interaction
///
/// The `Flickable` also supports scrolling with the mouse wheel and touchpad scroll gestures.
/// It will scroll regardless of the `interactive` property.
/// 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
export component Flickable inherits Empty {
/// ```slint imageAlt="flickable interactive" width="200" height="200"
/// Flickable {
/// interactive: false;
/// }
/// ```
/// When true, the viewport can be scrolled by clicking on it and dragging it with the cursor.
in property <bool> interactive: true;
/// The total width of the scrollable element.
in property <length> viewport-width;
/// The total height of the scrollable element.
in property <length> viewport-height;
/// The position of the scrollable element relative to the `Flickable`. This is usually a negative value.
in-out property <length> viewport-x;
/// The position of the scrollable element relative to the `Flickable`. This is usually a negative value.
in-out property <length> viewport-y;
/// Invoked when `viewport-x` or `viewport-y` is changed by a user action (dragging, scrolling).
callback flicked();
//-default_size_binding:expands_to_parent_geometry
}
/// 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