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:
Device (please complete the following information):
Thanks in advance!
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 yourvar chat *ChatEntryline to:chat := &ChatEntry{} chat.ExtendBaseWidget(chat)That code could also be moved to a constructor function as it's important that the
ExtendBaseWidgetcall 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).