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

Updating text and calling refresh for Entry doesn't work #607

Closed
Jacalz opened this issue Jan 8, 2020 · 4 comments
Closed

Updating text and calling refresh for Entry doesn't work #607

Jacalz opened this issue Jan 8, 2020 · 4 comments

Comments

@Jacalz
Copy link
Member

Jacalz commented Jan 8, 2020

Describe the bug
When updating the .Text var for Entry and then calling .Refresh() for that widget, nothing happens.

To Reproduce
Steps to reproduce the behaviour:

  1. Create a widget and change it's text with yourWidgetName.Text = "something".
  2. Refresh the widget by calling yourWidgetName.Refresh() afterwords.
  3. Test the application for the change.
  4. See that nothing happens

Example code:

package main

import (
	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/layout"
	"fyne.io/fyne/widget"
	"strconv"
)

func isNumeric(s string) bool {
	_, err := strconv.ParseFloat(s, 64)
	return err == nil
}

func main() {
	a := app.New()
	w := a.NewWindow("Temperature Converter")

	inputC := widget.NewEntry()
	inputF := widget.NewEntry()

	label := widget.NewLabel("Celsius =")

	inputC.OnChanged = func(text string) {
		if !isNumeric(inputC.Text) {
			return
		}

		cDeg, _ := strconv.Atoi(inputC.Text)
		fDeg := float64(cDeg)*(9.0/5.0) + 32

		inputF.Text = strconv.Itoa(int(fDeg))
		inputF.Refresh()
	}

	inputF.OnChanged = func(text string) {
		if !isNumeric(inputF.Text) {
			return
		}

		fDeg, _ := strconv.Atoi(inputF.Text)
		cDeg := (float64(fDeg) - 32) * (5.0 / 9.0)

		inputC.Text = strconv.Itoa(int(cDeg))
		inputC.Refresh()
	}

	w.SetContent(fyne.NewContainerWithLayout(layout.NewGridLayout(4),
		inputC, widget.NewLabel("Celsius ="), inputF, widget.NewLabel("Fahrenheit")))

	w.ShowAndRun()
}

Device (please complete the following information):

  • OS: [e.g. Linux, iOS] Solus (Linux)
  • Version [e.g. 22] 4
  • Go version [e.g. 1.12] 1.13.5
  • Fyne version [e.g. 1.1 or git SHA] 1.2.1
@Kvaz1r
Copy link
Contributor

Kvaz1r commented Jan 8, 2020

You can and probably should use method SetText/1 and not use directly setting value for Text field in that case your code work as expected.

I can reproduce the behavior and it seems that Refresh/0 doesn't call refresh for inner textProvider as it happens in SetText/1 method.

@andydotxyz
Copy link
Member

Text, as with other properties, is available to developers who want to change data without refreshing (like 4 things should be changed and you don’t want to cause 4 refreshes).

This is a valid bug and the use case should be supported.

@andydotxyz
Copy link
Member

on release/v1.2.2 for testing

@Jacalz
Copy link
Member Author

Jacalz commented Jan 23, 2020

Looks like the fix does what it is supposed to do. Good job 👍

@Jacalz Jacalz changed the title Updating text and calling refresh for widget doesn't work Updating text and calling refresh for Entry doesn't work Jan 29, 2020
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

No branches or pull requests

3 participants