turbo-editors/turbo-corepublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

example_test.go · 50 lines · 1.1 KBGo Blame HistoryRaw
🛟 Updated. 28d5985 k33g 4h ago1package ui_test
2
3import (
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.
10func 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.
29func 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.
41func 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}