To complete the work on the compose view, we need to update the buttons callback. For the cancel button, all that's necessary is to call Close() on the window object. In the click handler for the send button, we will construct a new email and send it using the server object's Send() function. The client.NewMessage() function handles creation of the email object. All we need to do is use the Entry.Text field for each input in order to access the current state:
send := widget.NewButton("Send", func() {
email := client.NewMessage(subject.Text, content.Text,
client.Email(to.Text), "", time.Now())
server.Send(email)
compose.Close()
})
send.Style = widget.PrimaryButton
buttons := widget.NewHBox(
layout.NewSpacer(),
widget.NewButton("Cancel", func() {
compose.Close()
}),
send)
With this code in place, the application should function in exactly the same way as the previous examples we've built. Although the compose window does not look any different, our email browser window now has some real data in that should look like this:
As Fyne provides two built-in themes, we can also see how the application looks if users prefer a light colored theme. By setting the FYNE_THEME environment variable to "light", we can load the alternative theme, demonstrated as follows:
Setting the correct theme value will result in a light version of the application loading instead:
Before we complete this application, we should also cover the background processing portion—to handle when a new email arrives.