package ui_test import ( "fmt" "rickub.com/turbo-editors/turbo-core/ui" ) // Building a menu, the way the editor's File menu is put together. func ExampleNewMenuBar() { bar := ui.NewMenuBar(&ui.Menu{ Label: "~F~ile", Items: []*ui.MenuItem{ {Label: "~O~pen…", Shortcut: "F3", Action: func() {}}, {Separator: true}, {Label: "E~x~it", Shortcut: "Alt-X", Action: func() {}}, }, }) fmt.Println(bar.Open()) bar.OpenMenu(0) fmt.Println(bar.Open()) // Output: // false // true } // Hot keys are written with tildes and read back with SplitHotKey. func ExampleSplitHotKey() { text, key, index := ui.SplitHotKey("Save ~A~s…") fmt.Printf("%q %c %d\n", text, key, index) fmt.Println(ui.MatchesHotKey("Save ~A~s…", 'A')) // Output: // "Save As…" a 5 // true } // A rectangle is placed and clipped with plain geometry; the painter does the // rest. func ExampleRect() { screen := ui.Rect{W: 80, H: 24} dialog := ui.Rect{W: 40, H: 10}.CenteredIn(screen) fmt.Printf("%+v\n", dialog) fmt.Printf("%+v\n", dialog.Inset(1, 1)) // Output: // {X:20 Y:7 W:40 H:10} // {X:21 Y:8 W:38 H:8} }