Representing enums in the ui
@luleyleo is already working on this.
Since Apr 11, 2020.
- Dominant language
- Rust
- Stars
- 9.7k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
Update: See https://github.com/Finnerale/druid-enums for an implementation of the derive.
I've opened this Issue to continue the discussion about this from #751 and zulip
Currently druid does not offer a good solution to representing enums in the ui.
While structs can be split up into their different fields using Lens, no such feature exists for enums.
Considering how prevalent enums are in Rust, I would argue that druid should provide a good solution for this.
The ideas so far are
- Extending
Lensto work with enums - Introducing a new derive specifically for enums
- Using an immediate mode widget (#751)
I've implemented (examples of) those three here,
also @cmyr expressed similar ideas on #751
My preferred solution would be number 2, introducing a new Match derive similar to Lens which adds a ::matcher() -> MyTypeMatcher function to the deriving type (MyTypeMatcher would be generated).
For example if Option would derive Match:
Option::matcher()
.some(|| make_widget_some())
Having the matcher as a function on the type should be more intuitive than having to know that there is now also a separate struct called OptionMatcher, especially when exporting (pub use) it.
This matcher would provide one method per variant, as well as a default method to mimic _ =>.
Of course this does not event get close to the power match provides but it should be good enough for most cases. Would be nice if we could collect some ideas here and come up with something truly satisfying.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.