Skip to content

Commit d6f83a2

Browse files
authored
Docs: Explain a bit more the image type with more examples
1 parent e125da1 commit d6f83a2

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

docs/astro/src/content/docs/reference/primitive-types.mdx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,57 @@ RGB color with an alpha channel, with 8 bit precision for each channel. CSS colo
106106
<SlintProperty propName="image" typeName="image" defaultValue='empty image'>
107107

108108
The `image` type is a reference to an image. It's defined using the `@image-url("...")` construct.
109-
The address within the `@image-url` function must be known at compile time.
109+
The address within the `@image-url` function must be a string literal and the image is resolved at compile time.
110110

111111
Slint looks for images in the following places:
112112

113113
1. The absolute path or the path relative to the current `.slint` file.
114114
2. The include path used by the compiler to look up `.slint` files.
115115

116+
Loading image from `http` is only supported in [SlintPad](https://slintpad.com).
117+
116118
Access an `image`'s dimension using its `width` and `height` properties.
117119

118120
```slint
119121
export component Example inherits Window {
120122
preferred-width: 150px;
121123
preferred-height: 50px;
122124
125+
// Note: http URL only work on the web version.
123126
in property <image> some_image: @image-url("https://slint.dev/logo/slint-logo-full-light.svg");
124127
125-
Text {
126-
text: "The image is " + some_image.width + "x" + some_image.height;
128+
HorizontalLayout {
129+
Text {
130+
text: "The image is " + some_image.width + "x" + some_image.height;
131+
}
132+
133+
// Check the size to find out if the image is empty.
134+
if some_image.width > 0 : Image {
135+
source: some_image
136+
}
127137
}
128138
}
129139
```
130140

131141
It is also possible to load images supporting [9 slice scaling](https://en.wikipedia.org/wiki/9-slice_scaling) (also called nine patch or border images)
132142
by adding a `nine-slice(...)` argument. The argument can have either one, two, or four numbers that specifies the size of the edges.
133143
The numbers are either `top right bottom left` or `vertical horizontal`, or one number for everything
144+
145+
```slint
146+
// nine-slice scaling
147+
export component Example inherits Window {
148+
width: 100px;
149+
height: 150px;
150+
VerticalLayout {
151+
Image {
152+
source: @image-url("https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png", nine-slice(30 30 30 30));
153+
}
154+
}
155+
}
156+
```
157+
158+
See also the <Link type="Image" label="Image element"/>.
159+
134160
</SlintProperty>
135161

136162
## Animation

0 commit comments

Comments
 (0)