| 🛟 Updated. 28d5985 k33g 18h ago | 1 | package ui_test |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "codeberg.org/turbo-editors/turbo-core/ui" |
| 7 | ) |
| 8 | |
| 9 | // Building a menu, the way the editor's File menu is put together. |
| 10 | func ExampleNewMenuBar() { |
| 11 | bar := ui.NewMenuBar(&ui.Menu{ |
| 12 | Label: "~F~ile", |
| 13 | Items: []*ui.MenuItem{ |
| 14 | {Label: "~O~pen…", Shortcut: "F3", Action: func() {}}, |
| 15 | {Separator: true}, |
| 16 | {Label: "E~x~it", Shortcut: "Alt-X", Action: func() {}}, |
| 17 | }, |
| 18 | }) |
| 19 | |
| 20 | fmt.Println(bar.Open()) |
| 21 | bar.OpenMenu(0) |
| 22 | fmt.Println(bar.Open()) |
| 23 | // Output: |
| 24 | // false |
| 25 | // true |
| 26 | } |
| 27 | |
| 28 | // Hot keys are written with tildes and read back with SplitHotKey. |
| 29 | func ExampleSplitHotKey() { |
| 30 | text, key, index := ui.SplitHotKey("Save ~A~s…") |
| 31 | |
| 32 | fmt.Printf("%q %c %d\n", text, key, index) |
| 33 | fmt.Println(ui.MatchesHotKey("Save ~A~s…", 'A')) |
| 34 | // Output: |
| 35 | // "Save As…" a 5 |
| 36 | // true |
| 37 | } |
| 38 | |
| 39 | // A rectangle is placed and clipped with plain geometry; the painter does the |
| 40 | // rest. |
| 41 | func ExampleRect() { |
| 42 | screen := ui.Rect{W: 80, H: 24} |
| 43 | dialog := ui.Rect{W: 40, H: 10}.CenteredIn(screen) |
| 44 | |
| 45 | fmt.Printf("%+v\n", dialog) |
| 46 | fmt.Printf("%+v\n", dialog.Inset(1, 1)) |
| 47 | // Output: |
| 48 | // {X:20 Y:7 W:40 H:10} |
| 49 | // {X:21 Y:8 W:38 H:8} |
| 50 | } |