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

Provide a smoother menu refresh experience #2853

Merged
merged 6 commits into from May 30, 2022

Conversation

andydotxyz
Copy link
Member

@andydotxyz andydotxyz commented Mar 18, 2022

A work in progress, looking for discussion as it develops.
I think the following is required:

  • Refresh a Window MainMenu
  • Refresh a SystemTray Menu
  • Refresh any Menu
  • (perhaps Refresh any MenuItem?)

Fixes #2852

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.
  • Public APIs match existing style.

@andydotxyz andydotxyz changed the base branch from master to develop March 18, 2022 11:13
@coveralls
Copy link

coveralls commented Mar 18, 2022

Coverage Status

Coverage decreased (-0.05%) to 61.407% when pulling 28ded26 on andydotxyz:feature/menurefresh into 6d0d524 on fyne-io:develop.

@andydotxyz andydotxyz marked this pull request as ready for review May 22, 2022 19:11
Comment on lines +21 to +43
// Refresh will instruct this menu to update its display.
//
// Since: 2.2
func (m *Menu) Refresh() {
for _, w := range CurrentApp().Driver().AllWindows() {
main := w.MainMenu()
if main != nil {
for _, menu := range main.Items {
if menu == m {
w.SetMainMenu(main)
break
}
}
}
}

if d, ok := CurrentApp().Driver().(systemTrayDriver); ok {
if m == d.SystemTrayMenu() {
d.SetSystemTrayMenu(m)
}
}
}

Copy link
Member

Choose a reason for hiding this comment

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

I’d expect the Set* methods to do nothing if the item to set is already set, i.e. I find the refresh effect unexpected. There should be a RefreshMenu method instead.

Thinking about it, IMO, it would be better if the menu would not know about the potential places where it might be used.
Instead, the sys-tray, the main menu widget and the menu widget should register a refresh callback if their fyne.(Main)Menu is being set. They should also deregister this if the menu is changed, of course.
Thus, the changed (main) menu would simply call all registered callbacks.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that would be a cleaner implementation - but I cannot figure out how to do that without additional functionality in our top level APIs.
Because fyne.Menu is a raw struct I am not sure how to support the chance callback hooks without adding complexity to the API - and also exposing the possibility that users could disconnect the callback...

If we do find a way to do it more neatly I would be happy to do so, but also I would hope it could sit behind the same clean public API that mimics how CanvasObject works.

Any thoughts on a way to proceed?

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I thought a little bit about it and didn’t came up with an idea better than an internal registry to decouple the callback handling from the menu. But this is clearly to much complexity. The current approach is not really a blocker. It can be easily refactored if we have a better idea in the future.

However, the usage of Set* for triggering a refresh should be improved like I said in the first paragraph :).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I'm not totally clear about the Set comment - what would your suggested RefreshMenu do different to Menu.Refresh()? I'll try and catch you on Slack so we can disccus

@andydotxyz andydotxyz merged commit 3ba1d69 into fyne-io:develop May 30, 2022
@andydotxyz andydotxyz deleted the feature/menurefresh branch May 30, 2022 07:36
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