Email compose dialog

The layout of our compose dialog window is slightly more basic: a vertical box named layout manages the stack of controls into which the input elements are appended. We need to create another box, in horizontal arrangement, to place the To label before the input field; make sure to turn the padding on to provide some spacing. Each of the text input boxes is created using ui.NewEntry(), which creates a simple one-line input field. Unfortunately, at the time of writing, there was no multi-line input field—a constraint that does not have an obvious workaround at this stage. The next release of the UI library will have a new ui.MultilineEntry, which will provide this functionality.

The last of the compose layout is the second horizontal box, buttonBox, which uses the familiar empty label trick to cause the Cancel and Send buttons to be right-aligned within the available space:

window := ui.NewWindow("New GoMail", 400, 320, false)
window.SetMargined(true)
window.OnClosing(func(*ui.Window) bool {
return true
})

subject := ui.NewEntry()
subject.SetText("subject")

toBox := ui.NewHorizontalBox()
toBox.setPadded(true)
toBox.Append(ui.NewLabel("To"), false)
to := ui.NewEntry()
to.SetText("email")
toBox.Append(to, true)

content := ui.NewEntry()
content.SetText("email content")

buttonBox := ui.NewHorizontalBox()
buttonBox.SetPadded(true)
buttonBox.Append(ui.NewLabel(""), true)
buttonBox.Append(ui.NewButton("Cancel"), false)
buttonBox.Append(ui.NewButton("Send"), false)

layout := ui.NewVerticalBox()
layout.SetPadded(true)
layout.Append(subject, false)
layout.Append(toBox, false)
layout.Append(content, true)
layout.Append(buttonBox, false)

window.SetChild(layout)
window.Show()

As you can see in the preceding code, it uses the same ui.NewWindow() as the main email browser code—this is because andlabs UI doesn't differentiate between types of windows. Various dialog windows do exist but they are predefined for specific purposes, and so for our custom dialog, we will use a normal window. Therefore, you can test this code easily by using the same main() method as the previous code examples. Once run, you should see something similar to these screenshots:

The email compose window:

Email compose on macOS:

Loaded on a Windows computer:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.137.67