Toolbar and menu

Unfortunately there is currently no API support for menu or toolbar features in andlabs UI. Instead, we will simulate a toolbar by using a horizontal box, buttons, and a separator, which should provide the desired effect. As the separator can be very thin, we are padding it with an extra space on either side:

toolbar := ui.NewHorizontalBox()
toolbar.Append(ui.NewButton("New"), false)
toolbar.Append(ui.NewButton("Reply"), false)
toolbar.Append(ui.NewButton("Reply All"), false)

toolbar.Append(ui.NewLabel(" "), false)
toolbar.Append(ui.NewVerticalSeparator(), false)
toolbar.Append(ui.NewLabel(" "), false)
toolbar.Append(ui.NewButton("Delete"), false)
toolbar.Append(ui.NewLabel(" "), false)
toolbar.Append(ui.NewVerticalSeparator(), false)
toolbar.Append(ui.NewLabel(" "), false)

toolbar.Append(ui.NewButton("Cut"), false)
toolbar.Append(ui.NewButton("Copy"), false)
toolbar.Append(ui.NewButton("Paste"), false)

As you can see, we have specified that no buttons, separators, or spacers should expand, so the buttons will be left-aligned on the bar. This behavior could be changed if you'd prefer the buttons to spread out, by passing true for the stretchy parameter, for example, when appending the empty ui.Label controls.

We need to add this to the window—a new vertical box, called layout, is added and the previous content is packed underneath the toolbar. To provide some separation between this toolbar and the main content, we've called SetPadded(true). Notice that the toolbar and space don't stretch (vertically), but the content layout does:

layout := ui.NewVerticalBox()
layout.SetPadding(true)
layout.Append(buildToolbar(), false)
layout.Append(content, true)

window.SetChild(layout)

By combining this code with the main layout described, you should get an application that's approaching the look of the email user interface that we designed in Chapter 4, Walk - Building Graphical Windows Applications:

A box of buttons is added to simulate a toolbar

Notice how the look can vary between different operating systems—the following is running on Microsoft Windows:

The addition of our toolbar box on Windows
..................Content has been hidden....................

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