Documentation
¶
Overview ¶
Package menu implements vigo's top-of-screen menu bar and bottom-of-screen status line. v0.1 paints the bars with a fixed list of items; activation and pull-down menus arrive in v0.2.
Index ¶
- Variables
- func SaveTOML(w io.Writer, menus []Item) error
- type Bar
- type Hint
- type Item
- type Line
- type MenuBox
- func (m *MenuBox) AckChild()
- func (m *MenuBox) ChildOpen() bool
- func (m *MenuBox) Chosen() event.CommandID
- func (m *MenuBox) Draw(s *vio.Surface)
- func (m *MenuBox) HandleEvent(e *event.Event)
- func (m *MenuBox) IsEnabled(i int) bool
- func (m *MenuBox) Result() event.CommandID
- func (m *MenuBox) Selected() Item
- func (m *MenuBox) SelectedIndex() int
- func (m *MenuBox) SetSelectedIndex(i int)
- type MenuRunner
Constants ¶
This section is empty.
Variables ¶
var DefaultHints = []Hint{ {Key: "F1", Action: "Help", Cmd: event.CmdHelp}, {Key: "F10", Action: "Menu", Cmd: event.CmdMenu}, {Key: "Alt-X", Action: "Exit", Cmd: event.CmdQuit}, }
DefaultHints is the v0.1 status line: F1 Help, F10 Menu, Alt-X Exit.
var DefaultItems = []Item{
{Title: "≡", Hotkey: -1},
{Title: "File", Hotkey: 0},
{Title: "Edit", Hotkey: 0},
{Title: "Search", Hotkey: 0},
{Title: "Run", Hotkey: 0},
{Title: "Compile", Hotkey: 0},
{Title: "Debug", Hotkey: 0},
{Title: "Project", Hotkey: 0},
{Title: "Options", Hotkey: 0},
{Title: "Window", Hotkey: 0},
{Title: "Help", Hotkey: 0},
}
DefaultItems is the Turbo Vision IDE menu list: the system menu marker, followed by the nine top-level menus.
Functions ¶
Types ¶
type Bar ¶
type Bar struct {
*view.View
Items []Item
Enabler *cmd.Enabler
Runner MenuRunner
// Last command chosen from a pull-down. Hosts read it after a Bar
// event returns to broadcast a CmdCommand on its behalf.
LastChosen event.CommandID
}
Bar is the horizontal strip of menu titles painted at the top of the screen. With Runner installed and Children populated on each Item, the Bar opens pull-downs on click, F10, and Alt-letter accelerators.
func NewBar ¶
NewBar returns a one-row menu bar pinned to the top of an owner of width w, populated with the supplied items. Pass DefaultItems for the IDE list.
func (*Bar) Draw ¶
Draw paints the bar background and each item separated by spaces. The hotkey character is drawn in the menu-shortcut palette color.
func (*Bar) HandleEvent ¶
HandleEvent intercepts F10 and Alt-letter accelerators, plus mouse clicks on the bar itself, and runs the corresponding pull-down via Runner. It is a pre-process handler so the accelerators work even when focus is in a window.
type Hint ¶
Hint is a single label on the status line: a key indicator (e.g. "F1") and the action it triggers ("Help"). The Cmd field is the command broadcast when the key is pressed; v0.1 paints the labels but does not fire commands yet (that ships with menu activation in v0.2).
type Item ¶
type Item struct {
Title string
Hotkey int
Cmd event.CommandID
Shortcut string
Children []Item
Sep bool
}
Item is a single label on the menu bar or a row in a pull-down. Hotkey is the index of the highlighted character within Title, or -1 for none. Cmd is the command fired when the row is activated. Shortcut is the right-aligned accelerator label (e.g. "F3"). Children, when non-empty, marks this row as a submenu trigger. Sep == true renders as a horizontal separator and ignores every other field.
func LoadTOML ¶ added in v0.2.0
LoadTOML reads a menu tree from r. The format is a minimal TOML subset: each top-level menu starts with [menu], each row inside a menu starts with [[menu.items]]. Recognized keys are title, hotkey, cmd, shortcut, sep. Unknown keys are ignored.
[[menu]] title = "File" hotkey = 0 [[menu.items]] title = "New" cmd = 101 shortcut = "F3" [[menu.items]] sep = true
Returns the slice of top-level Items (each with Children populated) or an error pointing at the first malformed line.
type Line ¶
Line is the one-row status bar pinned to the bottom of the screen.
func NewLine ¶
NewLine returns a status line of width w, anchored at row y, with the supplied hints. Pass DefaultHints for the IDE defaults.
func (*Line) HandleEvent ¶
HandleEvent is a no-op for v0.1; the demo binary handles Alt-X directly.
type MenuBox ¶ added in v0.2.0
type MenuBox struct {
*view.View
Items []Item
Enabler *cmd.Enabler
// contains filtered or unexported fields
}
MenuBox is the vertical pull-down that drops below a Bar item or nests under another MenuBox. It paints a single-line border, lays out items top to bottom, and exposes Result so a host can drive it like a modal sub-loop.
Disabled rows are dimmed, separators paint as a horizontal rule, submenu rows show a "▶" cap. Arrow keys move focus skipping separators; Enter fires the row's command (or sets ChildOpen on a submenu); Esc closes; a hot-key letter jumps to the matching row and fires it.
func NewMenuBox ¶ added in v0.2.0
NewMenuBox returns a pull-down anchored at (x, y) sized to fit items. The width is the longest title plus shortcut plus padding; the height is len(items) plus 2 for the border.
func (*MenuBox) AckChild ¶ added in v0.2.0
func (m *MenuBox) AckChild()
AckChild clears the ChildOpen flag.
func (*MenuBox) ChildOpen ¶ added in v0.2.0
ChildOpen reports whether the focused row is a submenu trigger that the user just activated. The Bar/host clears this after spawning a nested MenuBox.
func (*MenuBox) Chosen ¶ added in v0.2.0
Chosen returns the command attached to the activated row, or CmdNone if the user canceled.
func (*MenuBox) HandleEvent ¶ added in v0.2.0
HandleEvent moves focus and dispatches.
func (*MenuBox) IsEnabled ¶ added in v0.2.0
IsEnabled reports whether row i can be activated. Separators, out-of-range indices, and rows whose Cmd is in a disabled state return false.
func (*MenuBox) Result ¶ added in v0.2.0
Result returns CmdNone while the menu is still open, CmdCancel when the user closed it without picking, CmdMenu when a row fired a command (the bound command is available via Chosen), or CmdNext / CmdPrev when the user pressed ArrowRight / ArrowLeft on a non- submenu row to walk to the adjacent Bar item.
func (*MenuBox) SelectedIndex ¶ added in v0.2.0
SelectedIndex returns the focused row index.
func (*MenuBox) SetSelectedIndex ¶ added in v0.2.0
SetSelectedIndex moves focus to i, skipping separators and disabled rows in the supplied direction (1 forward, -1 backward, 0 forward).
type MenuRunner ¶ added in v0.2.0
MenuRunner runs an open MenuBox to completion. The host (typically the Application) installs one that wraps ExecView; the Bar invokes it whenever the user opens a pull-down. Tests pass a stub that drives the box synchronously.