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

Fix issue with Focus call crashing #1903

Merged
merged 4 commits into from Feb 17, 2021
Merged

Fix issue with Focus call crashing #1903

merged 4 commits into from Feb 17, 2021

Conversation

andydotxyz
Copy link
Member

Remove crash when calling Focus before canvas is visible.
Also fix issue where item focused before visible was not remembered (worked < 2.0.0).

Fixes #1893

Checklist:

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

@toaster
Copy link
Member

toaster commented Feb 15, 2021

Whether or not this should be supported is an interesting question. However what is more important is:
"This used to work, did we mean to break it in 2.0.0"
to which the answer is clearly, No - this was an accident.

So do we want to proagate the break, and put it in the notes for all breaking changes in 2.0 upgrade notes, or should we fix it beacause it has been supported in the past.

I propose the former. Also, disabling the ability to focus an out-of-tree object was a conscious decision and therefore not an accident. I just did not think that this “feature” would be in use.
The bug in the implementation which led to the crash was an accident, of course.

Without this feature a develop that wishes an element to be focused will have to get a callback from the main() of their app to say that it has set the window, so the focusing can happen. This feels like it is bleeding different concerns of the app.

As soon as a developer has added the object to the content tree, it can be focused. I still cannot see where this is a problem.

c.contentFocusMgr = app.NewFocusManager(c.content)
if focused != nil {
c.contentFocusMgr.Focus(focused)
Copy link
Member

Choose a reason for hiding this comment

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

Reasonable feature, but where is the test?

Copy link
Member

Choose a reason for hiding this comment

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

Also, This could be a different PR :).

Copy link
Member Author

Choose a reason for hiding this comment

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

Test added

@andydotxyz
Copy link
Member Author

As soon as a developer has added the object to the content tree, it can be focused. I still cannot see where this is a problem.

We have discussed this many times now - a complex app probably does not want to expose a widget reference all the way up the tree when creating and/or add a new "you're added" callback for main to call.

Let me propose another example (beyond what the original bug reporter showed us).
With data binding the developer no longer needs a reference to any widget to access values, and so they create the object tree and launch the app. Data binding handles all the data transfer so the application no longer needs any widget references. But the developer needs to somehow reach into the heirarchy to access a specific widget after it is set to the window so that it can be focused.

@andydotxyz
Copy link
Member Author

Also, disabling the ability to focus an out-of-tree object was a conscious

In the future we need to get better at documenting the intentional breaks - it would have been ideal to include this in the upgrade notes so it does not surprise more people.

@toaster
Copy link
Member

toaster commented Feb 15, 2021

Let me propose another example (beyond what the original bug reporter showed us).
With data binding the developer no longer needs a reference to any widget to access values, and so they create the object tree and launch the app. Data binding handles all the data transfer so the application no longer needs any widget references. But the developer needs to somehow reach into the heirarchy to access a specific widget after it is set to the window so that it can be focused.

Understood. Seems we need some elegant solution without pitfalls for this.

@toaster
Copy link
Member

toaster commented Feb 15, 2021

Also, disabling the ability to focus an out-of-tree object was a conscious

In the future we need to get better at documenting the intentional breaks - it would have been ideal to include this in the upgrade notes so it does not surprise more people.

Agreed.

Copy link
Member

@toaster toaster left a comment

Choose a reason for hiding this comment

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

Almost there :).

internal/driver/glfw/canvas_test.go Outdated Show resolved Hide resolved
Co-authored-by: Tilo Prütz <tilo@pruetz.net>
@andydotxyz andydotxyz merged commit 25bc694 into develop Feb 17, 2021
@andydotxyz andydotxyz deleted the fix/1893 branch February 17, 2021 15:14
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