1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package ui_test
import (
"fmt"
"codeberg.org/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}
}
|