fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design

Home Page:https://fyne.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dweymouth opened this issue · comments

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.

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.

Related: #4374

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

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).

Also semi-related: #4374

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.