The first new function, setMessage(), will simply call SetText() on each of our widget.Label elements. This requires saving a reference to the to, from, date, subject, and content label widgets that were created earlier in this section. Their content can be updated using the SetText() function as follows:
func setMessage(email *client.EmailMessage) {
subject.SetText(email.Subject)
to.SetText(email.ToEmailString())
from.SetText(email.FromEmailString())
date.SetText(email.DateString())
content.SetText(email.Content)
}
We will also create another helper function, addEmail(), to add a new email to the list. This is a change from the initial list of widget.Labels that we added to widget.Group—we are using buttons to utilize their built-in click handling. The button created in this function sets the label to be the email subject, as before, and calls the new setMessage() function if it is tapped:
func addEmail(email *client.EmailMessage) fyne.CanvasObject {
return widget.NewButton(email.Subject, func() {
setMessage(email)
})
}
Then, the list code is updated to call the new addEmail() function when we load the user interface:
list := widget.NewGroup("Inbox")
for _, email := range server.ListMessages() {
list.Append(addEmail(email))
}
Those are the only changes that we need to implement in order to make the browser interface functional. Now, let's add the appropriate handling code to the compose window.