-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d601d0e
commit ba75978
Showing
3 changed files
with
141 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# LiveHook | ||
|
||
`LiveHook` 是一个 trait,用于在 Makepad 的 live design 系统中处理和应用 live 属性更新。每个方法的用途如下: | ||
|
||
### `apply_value_unknown` | ||
```rust | ||
fn apply_value_unknown(&mut self, cx: &mut Cx, _apply: &mut Apply, index: usize, nodes: &[LiveNode]) -> usize | ||
``` | ||
- **用途**:当一个属性更新到达时,如果该属性未在该对象上找到,`apply_value_unknown` 被调用。 | ||
- **典型实现**:如果节点没有前缀,则生成一个错误并跳过该节点。 | ||
- **参数**: | ||
- `cx`: 上下文对象,用于处理各种操作。 | ||
- `_apply`: 当前的应用状态。 | ||
- `index`: 当前处理节点的索引。 | ||
- `nodes`: 节点数组。 | ||
|
||
### `apply_value_instance` | ||
```rust | ||
fn apply_value_instance(&mut self, _cx: &mut Cx, _apply: &mut Apply, index: usize, nodes: &[LiveNode]) -> usize | ||
``` | ||
- **用途**:处理实例属性的应用。 | ||
- **典型实现**:通常跳过该节点。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
- `_apply`: 当前的应用状态。 | ||
- `index`: 当前处理节点的索引。 | ||
- `nodes`: 节点数组。 | ||
|
||
### `skip_apply` | ||
```rust | ||
fn skip_apply(&mut self, _cx: &mut Cx, _apply: &mut Apply, _index: usize, _nodes: &[LiveNode]) -> Option<usize> | ||
``` | ||
- **用途**:在应用属性更新之前调用,以确定是否应跳过应用。 | ||
- **返回值**:`Option<usize>` 指定要跳过的节点索引,如果不跳过则返回 `None`。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
- `_apply`: 当前的应用状态。 | ||
- `_index`: 当前处理节点的索引。 | ||
- `_nodes`: 节点数组。 | ||
|
||
### `before_apply` | ||
```rust | ||
fn before_apply(&mut self, _cx: &mut Cx, _apply: &mut Apply, _index: usize, _nodes: &[LiveNode]) | ||
``` | ||
- **用途**:在应用属性更新之前调用。 | ||
- **典型实现**:在应用属性更新之前执行一些准备工作。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
- `_apply`: 当前的应用状态。 | ||
- `_index`: 当前处理节点的索引。 | ||
- `_nodes`: 节点数组。 | ||
|
||
### `after_apply` | ||
```rust | ||
fn after_apply(&mut self, _cx: &mut Cx, _apply: &mut Apply, _index: usize, _nodes: &[LiveNode]) | ||
``` | ||
- **用途**:在应用属性更新之后调用。 | ||
- **典型实现**:在应用属性更新之后执行一些清理或后续操作。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
- `_apply`: 当前的应用状态。 | ||
- `_index`: 当前处理节点的索引。 | ||
- `_nodes`: 节点数组。 | ||
|
||
### `after_apply_from` | ||
```rust | ||
fn after_apply_from(&mut self, cx: &mut Cx, apply: &mut Apply) | ||
``` | ||
- **用途**:在 `apply` 的特定来源完成后调用。 | ||
- **典型实现**:根据应用的来源,调用相应的后续操作方法。 | ||
- **参数**: | ||
- `cx`: 上下文对象。 | ||
- `apply`: 当前的应用状态。 | ||
|
||
### `after_new_from_doc` | ||
```rust | ||
fn after_new_from_doc(&mut self, _cx: &mut Cx) | ||
``` | ||
- **用途**:在文档中创建新的实例后调用。 | ||
- **典型实现**:在从文档创建新实例后执行初始化操作。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
|
||
### `after_update_from_doc` | ||
```rust | ||
fn after_update_from_doc(&mut self, _cx: &mut Cx) | ||
``` | ||
- **用途**:在文档更新后调用。 | ||
- **典型实现**:在从文档更新实例后执行更新操作。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
|
||
### `after_apply_from_doc` | ||
```rust | ||
fn after_apply_from_doc(&mut self, _cx: &mut Cx) | ||
``` | ||
- **用途**:在应用任何文档更新后调用。 | ||
- **典型实现**:在任何文档更新应用之后执行操作。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
|
||
### `after_new_before_apply` | ||
```rust | ||
fn after_new_before_apply(&mut self, _cx: &mut Cx) | ||
``` | ||
- **用途**:在应用新文档更新之前调用。 | ||
- **典型实现**:在应用新文档更新之前执行一些初始化操作。 | ||
- **参数**: | ||
- `_cx`: 上下文对象。 | ||
|
||
这些方法提供了一个钩子系统,使开发者可以在特定的生命周期阶段处理属性更新,以便灵活地控制和扩展 live 属性的行为。 |