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

Entry does not show the last (few) changes when updating a binding.String in a fast succession #4082

Closed
2 tasks done
Roemer opened this issue Jul 21, 2023 · 5 comments
Closed
2 tasks done
Labels
unverified A bug that has been reported but not verified
Milestone

Comments

@Roemer
Copy link
Contributor

Roemer commented Jul 21, 2023

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

As discussed in Slack (https://gophers.slack.com/archives/CB4QUBXGQ/p1689959990702439) there seems to be an issue when a binding.String is bound to an Entry and is quickly updated multiple times. In that case, the Entry does not get all the last changes until the binding is updated again.

How to reproduce

  1. Run the example code from below
  2. Have a look at the Window (and optionally the terminal output). Theoretically it should display a and b randomly counting from 0 to 19. But you will just see a nothing or a few entries. Then after 5 seconds, it will add a final string and suddenly renders all missing parts.

Screenshots

image

Example code

package main

import (
	"fmt"
	"strconv"
	"time"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Test")
	w.Resize(fyne.NewSize(700, 300))

	textBinding := binding.NewString()
	widget := widget.NewEntryWithData(textBinding)

	logChannel := make(chan string, 100)
	go func() {
		for text := range logChannel {
			fmt.Println(text)
			existingText, _ := textBinding.Get()
			fmt.Println(existingText)
			newText := existingText + "," + text
			textBinding.Set(newText)
		}
	}()

	go func() {
		time.Sleep(time.Second * 1)
		for i := 0; i < 20; i++ {
			text := "a" + strconv.Itoa(i)
			logChannel <- text
			time.Sleep(time.Millisecond * 1)
		}
	}()
	go func() {
		time.Sleep(time.Second * 1)
		for i := 0; i < 20; i++ {
			text := "b" + strconv.Itoa(i)
			logChannel <- text
			time.Sleep(time.Millisecond * 1)
		}
	}()

	go func() {
		time.Sleep(time.Second * 5)
		logChannel <- "final"
	}()

	w.SetContent(widget)
	w.CenterOnScreen()
	w.ShowAndRun()
}

Fyne version

v2.3.6-0.20230720061213-19e0c73660eb

Go compiler version

1.20.6

Operating system and version

Linux WSL2, Windows 10

Additional Information

No response

@Roemer Roemer added the unverified A bug that has been reported but not verified label Jul 21, 2023
@Roemer
Copy link
Contributor Author

Roemer commented Jul 21, 2023

Probably related:
When then Entry contains a placeholder, a Set on the binding also seems not to work (at all or at least reliable).
See this example:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Test")
	w.Resize(fyne.NewSize(700, 300))

	// Username
	sshUsernameBinding := binding.NewString()
	sshUsernameControl := widget.NewEntryWithData(sshUsernameBinding)
	sshUsernameControl.SetPlaceHolder("Username")
	sshUsernameBinding.Set("Test")

	w.SetContent(container.New(layout.NewFormLayout(), widget.NewLabel("Username"), sshUsernameControl))
	w.CenterOnScreen()
	w.ShowAndRun()
}

@Jacalz
Copy link
Member

Jacalz commented Aug 19, 2023

I think this might have been fixed on the develop branch. Would someone like to test?

@dan-frohlich
Copy link

Is this related to #4061 ?

@williambrode
Copy link
Contributor

This is still happening on 2.4.3. Here is my test case where you can't get the widget to show the value "2" using the button. I think its a pretty big regression of the Entry widget with a binding - since the value shown to the user is wrong in many cases. I may have to revert back to before the bug on my project or use a different widget.

package main

import (
	"time"

	fyne "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"
)

func main() {
	fyneApp := app.NewWithID("TestApp")

	win := fyneApp.NewWindow("TestWindow")
	win.Resize(fyne.NewSize(500, 500))
	boundString := binding.NewString()
	win.SetContent(
		container.NewVBox(
			widget.NewEntryWithData(boundString),
			widget.NewButton("change", func() {
				_ = boundString.Set("1")
				time.Sleep(10 * time.Millisecond)
				_ = boundString.Set("2")
			}),
		),
	)
	win.Show()

	fyneApp.Run()
}

@andydotxyz
Copy link
Member

fixed on develop, will pick into 2.4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

5 participants