linebender / linebender/druid

Representing enums in the ui

Open
#789 12 comments 1 reaction 1 assignee View on GitHub

@luleyleo is already working on this.

Since Apr 11, 2020.

discussion enhancement
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

  1. Extending Lens to work with enums
  2. Introducing a new derive specifically for enums
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.