Commit b440edd
authored
Add
This is a slightly different flavor of the existing
`Property::prop_changed` method. The difference being that `matches`
doesn't decide what flag must be set. This is important for more generic
properties that can have varied uses.
For example, one widget might use a thickness property in a way that
affects layout, but for another widget it will only affect paint. This
will become even more relevant with linebender#1593 introducing
`Widget::pre_paint` as then we will have three different paint methods.
Widgets can disagree which of the three need to re-run if `ContentColor`
changes.
I am guessing that it will make sense to standardize on `matches`
instead of `prop_changed`, however this PR does not do that. For now I
just want to introduce it so we can get some real use of it in and see
how it goes.
---
I'm aware that it's a slim method that barely does anything, however I
think it's still a sufficient ergonomics win.
`property_type == TypeId::of::<ContentColor>()` has less tab completion
in it and is awkward to remember.
`ContentColor::matches(property_type)` is easier to remember and can be
fully auto-completed with the input parameter not even needing a tab.
Whether it should be part of the `Property` trait is a question. The
benefit is that it'll definitely be implemented for every property. The
downside is that widgets will need to import the `Property` trait for
the method to be available. I'm leaning towards the trait, because the
import needs to happen only once per widget so isn't that bad. When a
property is missing this method it will be a bad experience for someone
who is used to it and has never directly written the `TypeId::of`
turbofish.Property::matches method. (linebender#1595)1 parent 12e09b0 commit b440edd
1 file changed
+6
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
0 commit comments