-
Notifications
You must be signed in to change notification settings - Fork 1
/
window_test.go
51 lines (43 loc) · 1.4 KB
/
window_test.go
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
51
package ui_test
import (
"git.kirsle.net/go/render"
"git.kirsle.net/go/ui"
)
// Example of using the Supervisor Window Manager.
func ExampleWindow() {
mw, err := ui.NewMainWindow("Window Manager Example", 800, 600)
if err != nil {
panic(err)
}
// Create a window as normal.
window := ui.NewWindow("Hello world!")
window.Configure(ui.Config{
Width: 320,
Height: 240,
})
// Configure its title bar colors (optional; these are the defaults)
window.ActiveTitleBackground = render.Blue
window.ActiveTitleForeground = render.White
window.InactiveTitleBackground = render.DarkGrey
window.InactiveTitleForeground = render.Grey
// Configure its window buttons (optional); default has no window buttons.
// Window buttons are only functional in managed windows.
window.SetButtons(ui.CloseButton | ui.MaximizeButton | ui.MinimizeButton)
// Add some widgets to the window.
btn := ui.NewButton("My Button", ui.NewLabel(ui.Label{
Text: "Hello world!",
}))
window.Place(btn, ui.Place{
Center: true,
Middle: true,
})
// To enable the window manager controls, the key step is to give it
// the Supervisor so it can be managed:
window.Compute(mw.Engine)
window.Supervise(mw.Supervisor())
// Each loop you must then:
// - Call Supervisor.Loop() as normal to handle events.
// - Call Supervisor.Present() to draw the managed windows.
// MainLoop() of the MainWindow does this for you.
mw.MainLoop()
}