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

Automatically remove focus from a widget that is no longer in the object tree #4812

Open
2 tasks done
dweymouth opened this issue Apr 27, 2024 · 6 comments
Open
2 tasks done

Comments

@dweymouth
Copy link
Contributor

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

If you have a widget that is focused, and you update the contents of the app window such that the widget is no longer visible, it will still be focused.

Is it possible to construct a solution with the existing API?

App code can manually unfocus things

Describe the solution you'd like to see.

On Refresh calls, Fyne can walk the object tree and unfocus the focused widget if it is no longer in the object tree. There are possible performance considerations here to think about - we don't want to be walking the tree more than necessary, and if it causes a large performance impact we should probably just not do it.

@sdassow
Copy link

sdassow commented May 4, 2024

This actually confused me recently because after switching content the canvas keyboard/shortcut events weren't working as expected, so I had to sprinkle Unfocus() calls all over the place; just to give an example what it does in terms of behaviour. While logical, it's not very obvious. Also not sure where I would look for it in the documentation though, or if it's even in there already.

@dweymouth
Copy link
Contributor Author

Related: #4374

@dweymouth
Copy link
Contributor Author

Perhaps this should happen on container.Remove. It's less expensive than doing it on every refresh. It does mean you need to use container.Remove instead of directly setting container.Objects to get the benefits though

@andydotxyz
Copy link
Member

Sounds like a good intermediate. Then the complete solution would be set up when we fix the gap that manually removing widgets does not Destroy the renderer ether (IIRC).

@dweymouth
Copy link
Contributor Author

Also semi-related: #4374

@dweymouth
Copy link
Contributor Author

dweymouth commented May 7, 2024

Another note - I would think that destroying renderers should be done on a periodic schedule, like a garbage collection/cache cleaning task. A widget that is removed from display ideally should immediately be unfocused, but that doesn't necessarily apply to render deletion - because the widget could be shown again shortly later. Supersonic is actually using a widget-cache system kind of similar to the collection widgets but for large-scale components of the "pages" or screens of the app, so that quick navigation doesn't create too many new widgets/CanvasObjects.

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

No branches or pull requests

3 participants