Skip to content

Commit fb9eb6c

Browse files
committed
docs(components/column): add Column docs and preview image
1 parent f724120 commit fb9eb6c

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

docs/en/components/column.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Column
3+
order: 6
4+
---
5+
6+
# Column
7+
8+
```rust
9+
pub fn column<F>(args: ColumnArgs, scope_config: F)
10+
where
11+
F: FnOnce(&mut ColumnScope<'_>),
12+
```
13+
14+
The `column` component arranges a set of child components vertically.
15+
16+
Unlike other container components, `column` requires adding children via methods on `ColumnScope` such as `child`, instead of calling child component functions directly inside the closure.
17+
18+
::: warning
19+
If you try to call child component functions directly inside the closure, the `column` component will panic at runtime.
20+
:::
21+
22+
Here is a correct example of using the `column` component:
23+
24+
```rust
25+
use tessera_ui_basic_components::{
26+
column::{column, ColumnArgs},
27+
text::text,
28+
spacer::{spacer, SpacerArgs},
29+
};
30+
31+
column(ColumnArgs::default(), |scope| {
32+
scope.child(|| text("First item".to_string()));
33+
scope.child_weighted(|| spacer(SpacerArgs::default()), 1.0); // This spacer will be flexible
34+
scope.child(|| text("Last item".to_string()));
35+
});
36+
```
37+
38+
## Arguments
39+
40+
- `args: ColumnArgs`
41+
42+
This argument configures the `column` component's style including width, height, alignment, etc. Use `ColumnArgsBuilder` to construct it.
43+
44+
- `scope_config: F`
45+
46+
A closure used to add child components into the `column`. The closure receives a `&mut ColumnScope` and you should use its `child`, `child_weighted`, etc. methods to add children.
47+
48+
## Preview
49+
50+
![column](/column_example.png)

docs/public/column_example.png

12.2 KB
Loading

docs/zhHans/components/column.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Column 组件
3+
order: 6
4+
---
5+
6+
# Column
7+
8+
```rust
9+
pub fn column<F>(args: ColumnArgs, scope_config: F)
10+
where
11+
F: FnOnce(&mut ColumnScope<'_>),
12+
```
13+
14+
`column` 组件用于垂直排列一组子组件。
15+
16+
不像别的容器组件,`column` 组件要求你使用 `ColumnScope::child` 等方法来添加子组件,而非直接在闭包中调用子组件函数。
17+
18+
::: warning
19+
如果尝试在闭包中直接调用子组件函数,`column` 组件将在运行时崩溃。
20+
:::
21+
22+
以下是一个正确使用 `column` 组件的例子:
23+
24+
```rust
25+
use tessera_ui_basic_components::{
26+
column::{column, ColumnArgs},
27+
text::text,
28+
spacer::{spacer, SpacerArgs},
29+
};
30+
31+
column(ColumnArgs::default(), |scope| {
32+
scope.child(|| text("First item".to_string()));
33+
scope.child_weighted(|| spacer(SpacerArgs::default()), 1.0); // This spacer will be flexible
34+
scope.child(|| text("Last item".to_string()));
35+
});
36+
```
37+
38+
## 参数
39+
40+
- `args: ColumnArgs`
41+
42+
该参数用于配置 `column` 组件的样式,包括宽高、对齐方式等。使用 `ColumnArgsBuilder` 来构建它。
43+
44+
- `scope_config: F`
45+
46+
该参数是一个闭包,用于添加子组件到 `column` 组件中。闭包接收一个 `&mut ColumnScope` 参数,使用它的 `child``child_weighted` 等方法来添加子组件。
47+
48+
## 预览
49+
50+
![column](/column_example.png)

0 commit comments

Comments
 (0)