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

Exception trying to set labeled checkbox state just after creation #56

Closed
harbdog opened this issue Mar 11, 2023 · 2 comments
Closed

Exception trying to set labeled checkbox state just after creation #56

harbdog opened this issue Mar 11, 2023 · 2 comments

Comments

@harbdog
Copy link
Contributor

harbdog commented Mar 11, 2023

Using ebitenui v0.4.0, I'm creating some labeled checkboxes and sometimes they need to be checked on by default. However, the .Checkbox() function returns nil after initial creation, which is needed to access its .SetState() function. It appears the checkbox object underneath doesn't get set until after the .init.Do() function is called, which is only performed after first calling one of a few functions which aren't always necessary to do up front (GetWidget, PreferredSize, SetLocation, SetupInputLayer, Render, Focus).

At the least I think it would be worth adding a SetState() function directly on the labeled checkbox object which can call the .init.Do() first to ensure it will be present.

@harbdog
Copy link
Contributor Author

harbdog commented Mar 11, 2023

The current workaround looks something like this:

c := widget.NewLabeledCheckbox...

if checked {
    c.GetWidget()
    c.Checkbox().SetState(widget.WidgetChecked)
}

@mcarpenter622
Copy link
Collaborator

Thank you for the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants