package main import ( "bytes" "red-green/door" "strings" "github.com/mitchellh/go-wordwrap" ) // Build door.Menu (Main menu) func MainMenu() door.Menu { // Make the main menu // Width was 45 var menu door.Menu = door.Menu{Panel: door.Panel{Width: 35, X: 2, Y: 2, Style: door.DOUBLE, Title: "[ Main Menu: ]", TitleOffset: 3, BorderColor: door.ColorText("BRI CYAN ON BLA")}} menu.SelectedR = door.MakeMenuRender(door.ColorText("BOLD CYAN"), door.ColorText("BOLD BLUE"), door.ColorText("BOLD WHITE"), door.ColorText("BOLD CYAN")) menu.UnselectedR = door.MakeMenuRender(door.ColorText("BOLD YEL ON BLUE"), door.ColorText("BOLD WHI ON BLUE"), door.ColorText("BOLD YEL ON BLUE"), door.ColorText("BOLD CYAN ON BLUE")) menu.AddSelection("A", "ANSI Display") // m.AddSelection("C", "Crash") menu.AddSelection("D", "Display Information") menu.AddSelection("F", "Font Demo") menu.AddSelection("I", "Input Demo") menu.AddSelection("M", "Menu Demo") menu.AddSelection("P", "Progress Bars Demo") menu.AddSelection("S", "Show Panel") menu.AddSelection("T", "Test Door About") menu.AddSelection("W", "Screen Width") menu.AddSelection("Q", "Quit") var descriptions []string = []string{ // 12345678901234567890123456789012345678901234567890 "Display an ANSI file. It is compiled into the door itself.", // "Crash go, see a handled error.", // The error shows up in the logs. "Display dropfile information.", "Display TheDraw Fonts. Font information is compiled into the door.", "Input some values, while updating the time.", "Isn't this is a menu?", "Display progress bar styles: half step, display percentage, and gradient.", "Show multiple panels. Panels can be mouse drag/drop around.", "Show about the door, using NoMoreSecrets effect.", "Examples using the full width of the screen.", "Exit this door.", } var widthLeft int = door.Width - (menu.Width + menu.X + 2) var panelWidth int = widthLeft - (2 + 2) var maxLines int = 1 var maxLineLength int // Calculate the max lines needed for each line. for _, line := range descriptions { var wrapped string = wordwrap.WrapString(line, uint(panelWidth)) var lines int = len(strings.Split(wrapped, "\n")) if lines > maxLines { maxLines = lines } if len(line) > maxLineLength { maxLineLength = len(line) } } if maxLines == 1 { // Ok! Everything fits into one line, SO use max line length as width of panel. panelWidth = maxLineLength } // Position the description panel beside the menu. m.Width + m.X + 2 (1 one to give it a space) // var descPanel door.Panel = door.Panel{X: menu.Width + menu.X + 2 + 1, Y: menu.Y, Width: panelWidth, Style: door.SINGLE, BorderColor: door.ColorText("WHI ON BLU")} var descPanel door.Panel = door.Panel{X: 2, Y: menu.Y + len(menu.Lines) + 3, Width: panelWidth, Style: door.SINGLE, BorderColor: door.ColorText("WHI ON BLU")} for x := 0; x < maxLines; x++ { descPanel.Lines = append(descPanel.Lines, &door.Line{Width: panelWidth}) } menu.Activated = func(item int, d *door.Door) { var line string = descriptions[item] var lines []string = strings.Split(wordwrap.WrapString(line, uint(panelWidth)), "\n") for idx := range descPanel.Lines { if idx >= len(lines) { descPanel.Lines[idx].Text = &bytes.Buffer{} } else { descPanel.Lines[idx].Text = bytes.NewBuffer([]byte(lines[idx])) } } d.WriteA(door.SavePos, descPanel.Output(), door.RestorePos) } return menu }