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

Feature: menu widget #877

Merged
merged 14 commits into from
Apr 26, 2020
Merged

Feature: menu widget #877

merged 14 commits into from
Apr 26, 2020

Conversation

toaster
Copy link
Member

@toaster toaster commented Apr 17, 2020

Description:

This PR contains the first part of the menu change: internal/widget/menu.
This widget replaces the box that is used for menus up to now.

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

This adds some padding at the top and the bottom of a menu.
It also moves the dismiss action from the MenuItem widget
into the new Menu widget.
This is required for menus (with sub-menus)
which will render their shadow on their own.
Thus sub-menus will have shadows, too.
Also menus outside of pop-ups will have shadows.
@toaster toaster requested a review from andydotxyz April 17, 2020 09:52
@andydotxyz
Copy link
Member

Hmm, thanks for all of this, it's really coming together. I see that the reason for making popup shadow optional is to allow the menu to draw it's own shadow - this seems a little strange.
Can you expand on why this is needed?

require.GreaterOrEqual(t, len(r.Objects()), expectedObjectCount)

bgIdx := 0
if tt.castShadow {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't test the no-shadow state does it?

Copy link
Member Author

@toaster toaster Apr 18, 2020

Choose a reason for hiding this comment

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

Not explicitly, good catch!
If the pop-up would cast a shadow with hideShadow == true, the following assertion regarding the background would fail. I’ll add an explicity assertion to clarify the intention.

@toaster
Copy link
Member Author

toaster commented Apr 18, 2020

Hmm, thanks for all of this, it's really coming together. I see that the reason for making popup shadow optional is to allow the menu to draw it's own shadow - this seems a little strange.
Can you expand on why this is needed?

Because menus will be allowed to have submenus in the next PR (tests just finished). These have to draw another shadow.

@andydotxyz
Copy link
Member

I don’t follow sorry - won’t submenus look like top level menus? A list of items with a shadow around it...

@toaster
Copy link
Member Author

toaster commented Apr 18, 2020

Exactly, and who should draw the shadow?

@toaster toaster mentioned this pull request Apr 20, 2020
3 tasks
@@ -27,6 +27,7 @@ const (
ButtonLevel ElevationLevel = 2
PopUpLevel ElevationLevel = 8
SubmergedContentLevel ElevationLevel = 8
MenuLevel ElevationLevel = 4
Copy link
Member

Choose a reason for hiding this comment

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

nit: move up 2 lines

@andydotxyz
Copy link
Member

I'm having difficulty reading this PR now sorry. The modifications to PopUp coming and going seem to be interleaved with the commits that get to this finished menu.
Is it possible to somehow pick the required commits onto a clean branch?

My other question is around the internal Overlay widget - it is only used by the new PopUpMenu - my normal rule of thumb is to not create an abstraction until there are multiple uses of it, so is the additional code really needed at this time?

@toaster
Copy link
Member Author

toaster commented Apr 24, 2020

My other question is around the internal Overlay widget - it is only used by the new PopUpMenu - my normal rule of thumb is to not create an abstraction until there are multiple uses of it, so is the additional code really needed at this time?

I don’t think this is an abstraction. As I already mentioned in #707 a widget should not be an overlay and another widget at the same time. The PopUpMenu can be moved and resized while an overlay can’t really (it should be canvas’ size at 0,0).
However, there will be another usage of the Overlay by the main menu widget, soon.

@toaster
Copy link
Member Author

toaster commented Apr 24, 2020

I'm having difficulty reading this PR now sorry. The modifications to PopUp coming and going seem to be interleaved with the commits that get to this finished menu.
Is it possible to somehow pick the required commits onto a clean branch?

Technically: yes.
Should I do it: I don’t think so.
It’s not that I’m too lazy (I am, of course), but the revert of the PopUp changes includes NotPadded which is already on the develop branch. In the end we would save like two small commits after investing a couple of hours.

@andydotxyz
Copy link
Member

widget should not be an overlay and another widget at the same time

Hmm, I see what you mean. And yet we publicly expose the AddOverlay but hide the Overlay widget.
I think this may be a naming issue. To avoid confusing developers could something less generic and more meaningful help? Like OverlayWrapper, or OverlayContainer?
I would like to avoid people thinking they need to use this and can't, if they want an overlay. The reality is that any widget could be one, even though (as you say) it shouldn't be both.

Alternatively we could make a much more sweeping change that requires Overlays are in fact Overlays...

@toaster
Copy link
Member Author

toaster commented Apr 25, 2020

I think using a different name is the best way.
WDYT about OverlayBackground or OverlayPresenter?

@andydotxyz
Copy link
Member

WDYT about OverlayBackground or OverlayPresenter?

Presenter is a bit of a trigger word as it's used for defined purposes in MVP https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter.

OverlayBackground sounds servicable, I just proposed Container as we have used that elsewhere. It is both a background and a container I guess. Perhaps background sounds alittle more passive than the object is?

@toaster
Copy link
Member Author

toaster commented Apr 25, 2020

It’s fyne for me if you prefer Container over Background. It’s an internal widget for now and we are free to change the name if a better one occurs :).

andydotxyz
andydotxyz previously approved these changes Apr 25, 2020
@andydotxyz
Copy link
Member

Good by me, though I think Stuart had an open review too?

@toaster
Copy link
Member Author

toaster commented Apr 26, 2020

Now everything should be in @stuartmscott @andydotxyz

@toaster toaster merged commit 32f93b6 into fyne-io:develop Apr 26, 2020
@toaster toaster deleted the feature/menu_widget branch April 26, 2020 11:03
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.

None yet

3 participants