-
Notifications
You must be signed in to change notification settings - Fork 59
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
CompletionEntry cannot type word when SetText is called in widget.List #34
Comments
After debugging, I found that whenever I input in the input box, the widget.List.UpdateItem is also called, so the completionentry.text is set back. |
It will be called at least whenever a cell may need to be refreshed (usually due to re-use, for example if list scrolls). Essentially the problem is that you are mutating data that is being re-loaded from static data. |
Referring to your suggestion, I re implemented the code. But when I specified the method I debuged the code, and found: func (c *CompletionEntry) maxSize() fyne.Size {
cnv := fyne.CurrentApp().Driver().CanvasForObject(c) // cnv is nil
...
} The demo code is as beblow: import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
x "fyne.io/x/fyne/widget"
)
var option = []string{"option1", "option2", "option3"}
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("List Data")
data := binding.BindStringList(
&[]string{"Item 1", "Item 2", "Item 3"},
)
list := widget.NewListWithData(
data,
func() fyne.CanvasObject {
return x.NewCompletionEntry(option)
},
func(i binding.DataItem, o fyne.CanvasObject) {
e := o.(*x.CompletionEntry)
e.Bind(i.(binding.String))
e.OnChanged = func(s string) {
e.ShowCompletion()
}
})
add := widget.NewButton("Append", func() {
val := fmt.Sprintf("Item %d", data.Length()+1)
data.Append(val)
})
myWindow.SetContent(container.NewBorder(nil, add, nil, nil, list))
myWindow.CenterOnScreen()
myWindow.Resize(fyne.NewSize(600, 400))
myWindow.ShowAndRun()
} |
I think the problem should still be on the CompletionEntry component. Because I replace with widget.SelectEntry, the issue is resolved. |
That it works this way with a You mentioned that the updated code crashes - can you provide the crash log and the replication steps that led to it please? |
To Reproduce:Steps to reproduce the behaviour:
Crash Log
Example Codepackage main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
x "fyne.io/x/fyne/widget"
)
var option = []string{"option1", "option2", "option3"}
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("List Data")
data := binding.BindStringList(
&[]string{"Item 1", "Item 2", "Item 3"},
)
list := widget.NewListWithData(
data,
func() fyne.CanvasObject {
return x.NewCompletionEntry(option)
},
func(i binding.DataItem, o fyne.CanvasObject) {
e := o.(*x.CompletionEntry)
e.Bind(i.(binding.String))
e.OnChanged = func(s string) {
e.ShowCompletion()
}
})
add := widget.NewButton("Append", func() {
val := fmt.Sprintf("Item %d", data.Length()+1)
data.Append(val)
})
myWindow.SetContent(container.NewBorder(nil, add, nil, nil, list))
myWindow.CenterOnScreen()
myWindow.Resize(fyne.NewSize(600, 400))
myWindow.ShowAndRun()
} |
As the following code shows, the text in CompletionEntry cannot be edited.
Screenshots
Steps to reproduce the behaviour:
The text was updated successfully, but these errors were encountered: