Fyne: Embedded struct of Entry not refreshing

Created on 17 Nov 2019  ·  5Comments  ·  Source: fyne-io/fyne

Describe the bug

I want my chat interface to pass on my string when I hit enter.
I've created a struct that embeds the Entry widget like so:

type ChatEntry struct {
    widget.Entry
}

func (e *ChatEntry) TypedKey(key *fyne.KeyEvent) {
        // Call the function as defined in widget.Entry
    e.Entry.TypedKey(key)

        // Do something else on hitting the enter key.
    if (key.Name == fyne.KeyReturn || key.Name == fyne.KeyEnter) {
        fmt.Sprint("Enter pressed! Text: ", e.Text)
        e.SetText("")
    }
}

I then put widget w on one of my screens:

var chat *ChatEntry= &ChatEntry{*widget.NewEntry()}`
w := widget.NewGroup("Chat",
    widget.NewEntry(), // for comparison
    chat)

The console is showing expected behavior.
However, the widget is not refreshing its display at all: it will not show that it's focused, it won't even remove placeholder text if I set one.

I can't even find a way to manually refresh it. After digging a bit I hoped the following works but it doesn't:

// doesn't visually refresh the widget
widget.Refresh(e)
e.CreateRenderer().Refresh()

To Reproduce
Steps to reproduce the behavior:

  1. Add ChatEntry as defined above to your project.
  2. During runtime, click into the widget and type.

Device (please complete the following information):

  • OS: Windows 10.0.18362
  • go version go1.13 windows/amd64
  • fyne.io/fyne v1.1.2

Thanks in advance!

bug enhancement

All 5 comments

Thanks, this is indeed something that should “just work” - but doesn’t.
We intend to have this fixed in a widget refactor that will be released soon. In fact I have it working locally and your code makes a great test case thanks :).

Short answer is that right now there is not a workaround but it will work as you expected in 1.2 - apologies for the delay.

That is very good news. Thank you so much!

This is now pushed to develop and ready for pre-release testing if you are interested.
It does require an additional line of code but that is all. Update your var chat *ChatEntry line to:

    chat := &ChatEntry{}
    chat.ExtendBaseWidget(chat)

That code could also be moved to a constructor function as it's important that the ExtendBaseWidget call is before any sub-widgets are initialised.

This is now pushed to develop and ready for pre-release testing if you are interested.
It does require an additional line of code but that is all. Update your var chat *ChatEntry line to:

  chat := &ChatEntry{}
  chat.ExtendBaseWidget(chat)

That code could also be moved to a constructor function as it's important that the ExtendBaseWidget call is before any sub-widgets are initialised.

Thank you very much, it was just a problem I had with a chat application that I try to do. I initially edited the entry to make it happen. I also edited the groupScroll so that I could go all the way when new text was added with the enter. I've never contributed to the community but I'd like to try.
Thanks

All contributions welcome. If you can't find something you need then open an issue or join us on the #fyne channel of the Gopher Slack server (links from our website footer https://fyne.io).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiajunhuang picture jiajunhuang  ·  7Comments

HeyDon-Lee picture HeyDon-Lee  ·  9Comments

andydotxyz picture andydotxyz  ·  9Comments

codenoid picture codenoid  ·  4Comments

gazhayes picture gazhayes  ·  8Comments