Skip to content

Commit 94d3d15

Browse files
committed
docs(components/image): add Image component documentation and preview image
1 parent aaab97b commit 94d3d15

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

docs/en/components/image.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Image component
3+
order: 11
4+
---
5+
6+
# Image
7+
8+
```rust
9+
pub fn image(args: impl Into<ImageArgs>)
10+
```
11+
12+
The `image` component is used to display images.
13+
14+
Notably, the `image` component itself does not own image data; instead it references image data via an `Arc<ImageData>` passed in through `ImageArgs`.
15+
16+
The `ImageData` must be loaded via `tessera_ui_basic_components::image::load_image_from_source`, with the following definition:
17+
18+
```rust
19+
pub fn load_image_from_source(
20+
source: &ImageSource,
21+
) -> Result<ImageData, ImageError>;
22+
23+
pub enum ImageSource {
24+
Path(String),
25+
Bytes(Arc<[u8]>),
26+
}
27+
```
28+
29+
Below is an example that loads embedded binary image data into `ImageData`:
30+
31+
```rust
32+
let image_bytes = Arc::new(*include_bytes!("../../example/examples/assets/scarlet_ut.jpg"));
33+
let image_data = load_image_from_source(&ImageSource::Bytes(image_bytes))
34+
.expect("Failed to load image");
35+
```
36+
37+
## Arguments
38+
39+
- `args: impl Into<ImageArgs>`
40+
41+
This argument configures the `image` component, including image data, component size, and other properties. You can use `ImageArgsBuilder` to construct it.
42+
43+
## Preview
44+
45+
![image](/image_example.png)

docs/public/image_example.png

754 KB
Loading

docs/zhHans/components/image.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Image 组件
3+
order: 11
4+
---
5+
6+
# Image
7+
8+
```rust
9+
pub fn image(args: impl Into<ImageArgs>)
10+
```
11+
12+
`image` 组件用于显示图片。
13+
14+
值得一提的是,`image` 组件本身不持有图片数据,而是通过 `ImageArgs` 传入 `Arc<ImageData>` 来引用图片数据。
15+
16+
而 `ImageData` 需通过 `tessera_ui_basic_components::image::load_image_from_source` 加载,其相关定义如下
17+
18+
```rust
19+
pub fn load_image_from_source(
20+
source: &ImageSource,
21+
) -> Result<ImageData, ImageError>;
22+
23+
pub enum ImageSource {
24+
Path(String),
25+
Bytes(Arc<[u8]>),
26+
}
27+
```
28+
29+
下面给出一个加载内嵌二进制的图片内容为 `ImageData` 的例子
30+
31+
```rust
32+
let image_bytes = Arc::new(*include_bytes!("../../example/examples/assets/scarlet_ut.jpg"));
33+
let image_data = load_image_from_source(&ImageSource::Bytes(image_bytes))
34+
.expect("Failed to load image");
35+
```
36+
37+
## 参数
38+
39+
- `args: impl Into<ImageArgs>`
40+
41+
该参数用于配置 `image` 组件,包括图片数据、组件大小等属性。可以使用 `ImageArgsBuilder` 来构建。
42+
43+
## 预览
44+
45+
![image](/image_example.png)

0 commit comments

Comments
 (0)