Skip to content

Commit 4000edf

Browse files
committed
docs(components/boxed): add Boxed component documentation and preview image
1 parent df4dff1 commit 4000edf

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

docs/en/components/boxed.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Boxed component
3+
order: 8
4+
---
5+
6+
# Boxed
7+
8+
```rust
9+
pub fn boxed<F>(args: BoxedArgs, scope_config: F)
10+
where
11+
F: FnOnce(&mut BoxedScope<'_>),
12+
```
13+
14+
The `boxed` component is used to stack a set of child components.
15+
16+
Unlike other container components, `boxed` requires you to use methods like `BoxedScope::child` to add children, instead of calling child component functions directly inside the closure.
17+
18+
::: warning
19+
If you attempt to call child component functions directly inside the closure, the `boxed` component will panic at runtime.
20+
:::
21+
22+
Below is a correct example of using `boxed`:
23+
24+
```rust
25+
use tessera_ui_basic_components::{
26+
boxed::{boxed, BoxedArgs},
27+
surface::{surface, SurfaceArgs},
28+
text::text,
29+
};
30+
31+
boxed(
32+
BoxedArgs {
33+
alignment: Alignment::Center,
34+
..Default::default()
35+
},
36+
|scope| {
37+
scope.child(|| {
38+
surface(
39+
SurfaceArgs {
40+
width: DimensionValue::from(Dp(300.0)),
41+
height: DimensionValue::from(Dp(300.0)),
42+
..Default::default()
43+
},
44+
None,
45+
|| {},
46+
)
47+
});
48+
scope.child(|| text("test"));
49+
},
50+
);
51+
```
52+
53+
## Arguments
54+
55+
- `args: BoxedArgs`
56+
57+
This argument configures the `boxed` component's style, including width, height, alignment, etc. Use `BoxedArgsBuilder` to construct it.
58+
59+
- `scope_config: F`
60+
61+
A closure used to add child components into the `boxed` component. The closure receives a `&mut BoxedScope` and you should use its `child`, `child_weighted`, etc. methods to add children.
62+
63+
## Preview
64+
65+
![boxed](/boxed_example.png)

docs/public/boxed_example.png

12.7 KB
Loading

docs/zhHans/components/boxed.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Boxed 组件
3+
order: 8
4+
---
5+
6+
# Boxed
7+
8+
```rust
9+
pub fn boxed<F>(args: BoxedArgs, scope_config: F)
10+
where
11+
F: FnOnce(&mut BoxedScope<'_>),
12+
```
13+
14+
`boxed` 组件用于堆叠一组子组件。
15+
16+
不像别的容器组件,`boxed` 组件要求你使用 `BoxedScope::child` 等方法来添加子组件,而非直接在闭包中调用子组件函数。
17+
18+
::: warning
19+
如果尝试在闭包中直接调用子组件函数,`boxed` 组件将在运行时崩溃。
20+
:::
21+
22+
以下是一个正确使用 `boxed` 组件的例子:
23+
24+
```rust
25+
use tessera_ui_basic_components::{
26+
boxed::{boxed, BoxedArgs},
27+
surface::{surface, SurfaceArgs},
28+
text::text,
29+
};
30+
31+
boxed(
32+
BoxedArgs {
33+
alignment: Alignment::Center,
34+
..Default::default()
35+
},
36+
|scope| {
37+
scope.child(|| {
38+
surface(
39+
SurfaceArgs {
40+
width: DimensionValue::from(Dp(300.0)),
41+
height: DimensionValue::from(Dp(300.0)),
42+
..Default::default()
43+
},
44+
None,
45+
|| {},
46+
)
47+
});
48+
scope.child(|| text("test"));
49+
},
50+
);
51+
```
52+
53+
## 参数
54+
55+
- `args: BoxedArgs`
56+
57+
该参数用于配置 `boxed` 组件的样式,包括宽高、对齐方式等。使用 `BoxedArgsBuilder` 来构建它。
58+
59+
- `scope_config: F`
60+
该参数是一个闭包,用于添加子组件到 `boxed` 组件中。闭包接收一个 `&mut BoxedScope` 参数,使用它的 `child``child_weighted` 等方法来添加子组件。
61+
62+
## 预览
63+
64+
![boxed](/boxed_example.png)

0 commit comments

Comments
 (0)