You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, now we have a problem: our List widget which expected a `Vector<...>` won't know how to handle a struct. So, we need to modify druid's dataflow so that, given the TodoList above, the List widget will have access to the `items` field. This is done with a `Lens`, which we'll explain next chapter.
184
+
However, now we have a problem: our List widget which expected a `Vector<...>` won't know how to handle a struct. So, we need to modify Druid's dataflow so that, given the TodoList above, the List widget will have access to the `items` field. This is done with a `Lens`, which we'll explain next chapter.
185
185
186
186
Furthermore, to pass our type as the a generic parameter to `Widget`, we need it to implement the `Data` trait (and `Clone`), more on that next chapter.
Copy file name to clipboardexpand all lines: docs/src/03_data.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Some widgets (eg Button, TextBox, Checkbox) can mutate the data passed to them b
8
8
9
9
When you mutate a widget's associated data, Druid compares the old and new version, and propagates the change to the widgets that are affected by the change.
10
10
11
-
Note that, in all that workflow, Widgets don't actually store their associated data. A `Button<Vector<String>>` doesn't actually store a `Vector<String>`, the framework just stores one which is provided to the button.
11
+
Note that, in all that workflow, Widgets don't actually store their associated data. A `Button<Vector<String>>` doesn't actually store a `Vector<String>`, instead the framework stores one per button, which is provided to widget methods.
12
12
13
13
For this to work, your model must implement the `Clone` and `Data` traits. The `Data` trait has a single method:
14
14
@@ -21,7 +21,7 @@ This method checks for equality, but allows for false negatives.
21
21
22
22
## Performance
23
23
24
-
It is important that your data be cheap to clone and cheap to compare; we encourage the use of reference counted pointers to allow cheap cloning of more expensive types. `Arc` and `Rc` have blanket `Data` impls that do pointer comparison, so if you have a type that does not implement `Data`, you can always just wrap it in one of those smart pointers.
24
+
It is important that your data is cheap to clone and cheap to compare; we encourage the use of reference counted pointers to allow cheap cloning of more expensive types. `Arc` and `Rc` have blanket `Data` impls that do pointer comparison, so if you have a type that does not implement `Data`, you can always just wrap it in one of those smart pointers.
25
25
26
26
### Collections
27
27
@@ -31,7 +31,7 @@ issues with collection types. For this reason, `Data` is not implemented for
31
31
32
32
You can always put these types inside an `Rc` or an `Arc`, or if you're dealing with
33
33
larger collections you can build Druid with the `im` feature, which brings in
34
-
the [`im crate`], and adds a `Data` impl for the collections there. The [`im`
34
+
the [`im` crate], and adds a `Data` impl for the collections there. The [`im`
35
35
crate] is a collection of immutable data structures that act a lot like the `std`
36
36
collections, but can be cloned efficiently.
37
37
@@ -58,7 +58,7 @@ Here is an example of using `Data` to implement a simple data model:
58
58
59
59
In Druid, most container widgets expect their children to have the same associated data. If you have a `Flex<Foobar>`, you can only append widgets that implement `Widget<Foobar>` to it.
60
60
61
-
In some cases, however, you want compose widgets that operate on different subsets of the data. Maybe you want to add two widgets to the above Flex, one that uses the field `foo` and another that uses the field `bar`, and they might respectively implement `Widget<Foo>` and `Widget<Bar>`.
61
+
In some cases, however, you want to compose widgets that operate on different subsets of the data. Maybe you want to add two widgets to the above Flex, one that uses the field `foo` and another that uses the field `bar`, and they might respectively implement `Widget<Foo>` and `Widget<Bar>`.
62
62
63
63
Lenses allow you to bridge that type difference. A lens is a type that represents a *two-way* mapping between two data types. That is, a lens from X to Y can take an instance of X and give you an instance of Y, and can take a modified Y and apply the modification to X.
Copy file name to clipboardexpand all lines: druid/src/widget/flex.rs
+1-1
Original file line number
Diff line number
Diff line change
@@ -571,7 +571,7 @@ impl<T: Data> Flex<T> {
571
571
flex: params.flex,
572
572
}
573
573
}else{
574
-
tracing::warn!("Flex value should be > 0.0. To add a non-flex child use the add_child or with_child methods.\nSee the docs for more information: https://docs.rs/druid/latest/druid/widget/struct.Flex.html");
574
+
tracing::warn!("Flex value should be > 0.0. To add a non-flex child use the add_child or with_child methods.\nSee the docs for more information: https://docs.rs/druid/0.8.0/druid/widget/struct.Flex.html");
0 commit comments