User interface toolkit for Go with support for SDL2 and HTML Canvas render targets.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.6 KiB

package ui
import (
// MenuFont is the default font settings for MenuBar buttons.
var MenuFont = render.Text{
Size: 12,
Color: render.Black,
PadX: 4,
PadY: 2,
// MenuBar is a frame that holds several MenuButtons, such as for the main
// menu at the top of a window.
type MenuBar struct {
name string
supervisor *Supervisor
buttons []*MenuButton
// NewMenuBar creates a new menu bar frame.
func NewMenuBar(name string) *MenuBar {
w := &MenuBar{
name: name,
buttons: []*MenuButton{},
w.IDFunc(func() string {
return fmt.Sprintf("MenuBar<%s>",
return w
// Supervise the menu bar, making its child menu buttons work correctly.
func (w *MenuBar) Supervise(s *Supervisor) {
w.supervisor = s
// Supervise the existing buttons.
for _, btn := range w.buttons {
// AddMenu adds a new menu button to the bar. Returns the MenuButton
// object so that you can add items to it.
func (w *MenuBar) AddMenu(label string) *MenuButton {
btn := NewMenuButton(label, NewLabel(Label{
Text: label,
Font: MenuFont,
w.buttons = append(w.buttons, btn)
// Pack and supervise it.
w.Pack(btn, Pack{
Side: W,
if w.supervisor != nil {
return btn
// PackTop returns the default Frame Pack settings to place the menu
// at the top of the parent widget.
func (w *MenuBar) PackTop() Pack {
return Pack{
Side: N,
FillX: true,