-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Canvas.Focus() before window visible causes application to crash #1893
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
Comments
It looks like the FocusManager is |
func createUserpassLoginPageContent(cg *util.CancelGroup,
data *pageData, finished chan<- *pageError) fyne.CanvasObject {
...
username := widget.NewEntry()
...
form := fyne.NewContainerWithLayout(layout.NewGridWrapLayout(formSize),
widget.NewForm(
widget.NewFormItem("Username", username),
widget.NewFormItem("Password", password),
),
)
control := fynecont.NewHBox(
fynex.NewHorizontalMargin(loginPageSubmitMargin),
fynecont.NewVBox(
submit,
progress.CanvasObject(),
),
)
data.container.Canvas().Focus(username) <--- This line causes the crash.
username.DoubleTapped(nil)
return fynecont.NewVBox(
newPageTitle(loginTitle),
newRichText(loginText),
fynex.NewVerticalMargin(loginPageFormMargin),
fynecont.NewHBox(
fynex.NewHorizontalMargin(loginPageFormMargin),
fynecont.NewVBox(
form,
control,
),
),
loggedInIndicator,
)
} |
Ah. I see. I think this is caused because you are focusing an element that is not in the canvas (yet). |
This worked before v2.0.0. |
I thought this was just me, haha. |
Ah, this would have been useful information for the initial bug report, but thanks. |
We are fixing the crash but returning to the 2.0 behaviour whereby an object must be in the tree before you can focus it. |
The problem starts when you develop code that return a complex canvas object that presumes focusing. The returned object isn't aware when it will be attached to the canvas tree. This constraint will frequently force developers to add deferred focusing which will lead to fragile code. |
I agree that there are some areas that are going to need work. No object should assume it has focus - it will be informed when it has gained the window focus. |
On |
Here is a part of the related stack trace:
This happens when trying to focus on
widget.Entry
or a custom control based onwidget.List
.Platform:
OS X 11.1
Go version:
go1.14.1 darwin/amd64
Fyne version:
v2.0.0
The text was updated successfully, but these errors were encountered: