Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuple optional #1540

Merged
merged 6 commits into from
Feb 9, 2021
Merged

Tuple optional #1540

merged 6 commits into from
Feb 9, 2021

Conversation

derekdreery
Copy link
Collaborator

This patch adds 2 features. Special care is needed with the Optional widget. While I'm sure it is very useful, I'm not sure I've implemented it correctly.

Copy link
Collaborator

@maan2003 maan2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuple lens looks good! For Optional, I recommend moving Runebender's Maybe to druid

@cmyr
Copy link
Member

cmyr commented Jan 18, 2021

I have similar doubts about the correctness of my Maybe widget, but I've worked out at least some of the bugs, and it is certainly useful.

@derekdreery
Copy link
Collaborator Author

derekdreery commented Jan 18, 2021

@cmyr could you comment on the difference between this Optional and runebender's Maybe? I didn't include a None option here, since you can get that functionality using Either, but maybe it makes more sense to include it. Also, how to handle events where the event should go to the widget (should_go_to_hidden, or something like that, and lifecycle events), but we don't have any data to send to the widget? I handled it by just sending the default value of the T of Option<T> to the some widget when the data was None, but this seems suboptimal.

EDIT wrote before I saw @cmyr 's comment 😛. I'd still be interested in your opinions on the questions.

@derekdreery
Copy link
Collaborator Author

And another question, if we have a widget for the None case, could we include a Null widget that lays itself out as bc.min() and does nothing else? It would go nicely with Maybe/Optional.

@cmyr
Copy link
Member

cmyr commented Jan 18, 2021

in no order:

  • there sort of is a Null widget, in the form of SizedBox::empty.
  • I like letting there be a None option, in case you want a custom placeholder.
  • I don't have any good answer about should_go_to_hidden. I think the solution I would advocate to not have the widget be hidden, but instead to create and destroy it as needed.

@derekdreery
Copy link
Collaborator Author

About the SizedBox::empty - it looks to be equivalent to a theoretical Null widget. My question is: how do we make this use of SizedBox discoverable?

@cmyr
Copy link
Member

cmyr commented Jan 21, 2021

I'm open to suggestions!

@derekdreery
Copy link
Collaborator Author

@cmyr I've swapped out the Optional for runebender's Maybe, and added some intra-crate doc links.

@derekdreery
Copy link
Collaborator Author

Ready for review :)

druid/src/lens/lens.rs Outdated Show resolved Hide resolved
@cmyr
Copy link
Member

cmyr commented Jan 25, 2021

Do we need both Maybe and Optional? In my use, Maybe covers the optional category well enough.

@derekdreery
Copy link
Collaborator Author

Do we need both Maybe and Optional? In my use, Maybe covers the optional category well enough.

Oh I thought I had removed Optional. Will do.

 - A `Lens` that combines 2 lenses into a tuple
 - A widget that displays an `Option`, showing nothing if there isn't
   anything to show.
 - Change `Tuple` to `Tuple2`.
 - Put a doc alias of "null" on `SizedBox::empty`.
 - Remove `Optional` which had already been removed from widget `mod`.
@derekdreery
Copy link
Collaborator Author

Ready for review again.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't make strong guarantees about covering all the corner cases in Maybe, but I haven't seen a crash in runebender in a while? 😬

@derekdreery derekdreery merged commit 64689fd into linebender:master Feb 9, 2021
@derekdreery derekdreery deleted the tuple_optional branch February 9, 2021 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants