-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix code readability issues. Support screenshot scale. Bring back types and tweak screenshots.
- Loading branch information
1 parent
b0fe8d6
commit 98e5df9
Showing
17 changed files
with
147 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions
44
docs/src/content/docs/reference/builtins/type-conversions.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
<!-- Copyright © SixtyFPS GmbH <[email protected]> ; SPDX-License-Identifier: MIT --> | ||
title: Type Conversions | ||
description: Type Conversions | ||
--- | ||
|
||
Slint supports conversions between different types. Explicit | ||
conversions are required to make the UI description more robust, but implicit | ||
conversions are allowed between some types for convenience. | ||
|
||
The following conversions are possible: | ||
|
||
- `int` can be converted implicitly to `float` and vice-versa. | ||
When converting from `float` to `int`, the value is truncated. | ||
- `int` and `float` can be converted implicitly to `string` | ||
- `physical-length`, `relative-font-size`, and `length` can be converted implicitly to each other only in | ||
context where the pixel ratio is known. | ||
- the units type (`length`, `physical-length`, `duration`, ...) can't be converted to numbers (`float` or `int`) | ||
but they can be divided by themselves to result in a number. Similarly, a number can be multiplied by one of | ||
these unit. The idea is that one would multiply by `1px` or divide by `1px` to do such conversions | ||
- The literal `0` can be converted to any of these types that have associated unit. | ||
- Struct types convert with another struct type if they have the same property names and their types can be converted. | ||
The source struct can have either missing properties, or extra properties. But not both. | ||
- Arrays generally don't convert between each other. Array literals can be converted if the element types are convertible. | ||
- String can be converted to float by using the `to-float` function. That function returns 0 if the string isn't | ||
a valid number. You can check with `is-float()` if the string contains a valid number | ||
|
||
```slint | ||
export component Example { | ||
// OK: int converts to string | ||
property<{a: string, b: int}> prop1: {a: 12, b: 12 }; | ||
// OK: even if a is missing, it will just have the default value ("") | ||
property<{a: string, b: int}> prop2: { b: 12 }; | ||
// OK: even if c is too many, it will be discarded | ||
property<{a: string, b: int}> prop3: { a: "x", b: 12, c: 42 }; | ||
// ERROR: b is missing and c is extra, this doesn't compile, because it could be a typo. | ||
// property<{a: string, b: int}> prop4: { a: "x", c: 42 }; | ||
property<string> xxx: "42.1"; | ||
property<float> xxx1: xxx.to-float(); // 42.1 | ||
property<bool> xxx2: xxx.is-float(); // true | ||
property<int> xxx3: 45.8; // 45 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters