forked from thingalon/goui
/
goui_windows.go
133 lines (112 loc) · 2.49 KB
/
goui_windows.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// +build windows
package goui
import (
"fmt"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"github.com/lxn/win"
)
var mainWindow *walk.MainWindow
var windowStore = make(map[int]walk.Form)
func runWindowsWebView() {
var le *walk.LineEdit
var wv *walk.WebView
fmt.Println("Run MainWindow!")
MainWindow{
AssignTo: &mainWindow,
Title: "Walk WebView Example",
MinSize: Size{800, 600},
Layout: VBox{MarginsZero: true},
Children: []Widget{
LineEdit{
AssignTo: &le,
Text: Bind("wv.URL"),
OnKeyDown: func(key walk.Key) {
if key == walk.KeyReturn {
wv.SetURL(le.Text())
}
},
},
WebView{
AssignTo: &wv,
Name: "wv",
URL: "http://golang.org",
},
},
}.Run()
}
func osInit() {
// runtime.LockOSThread()
guiReadyCallback()
runWindowsWebView()
// fmt.Scanln()
// C.StartApp()
}
func osOpenWindow(window *Window, url string, styleFlags int) {
fmt.Println("osOpenWindow: ", window, url, styleFlags)
var dia *walk.Dialog
var le *walk.LineEdit
var wv *walk.WebView
windowStore[window.handle] = dia
Dialog{
AssignTo: &dia,
Title: "Window Title",
MinSize: Size{800, 600},
Layout: VBox{MarginsZero: true},
Children: []Widget{
LineEdit{
AssignTo: &le,
Text: Bind("wv.URL"),
OnKeyDown: func(key walk.Key) {
if key == walk.KeyReturn {
wv.SetURL(le.Text())
}
},
},
WebView{
AssignTo: &wv,
Name: "wv",
URL: url,
},
},
}.Run(mainWindow)
}
func osStop() {
// C.StopApp()
// mainWindow.Close()
}
func osCloseWindow(window *Window) {
if w, ok := windowStore[window.handle]; ok {
w.AsFormBase().Close()
delete(windowStore, window.handle)
}
}
func osSetWindowTitle(window *Window, title string) {
if w, ok := windowStore[window.handle]; ok {
w.AsFormBase().SetTitle(title)
}
}
func osGetScreenSize() (int, int) {
w := win.GetSystemMetrics(win.SM_CXSCREEN)
h := win.GetSystemMetrics(win.SM_CYSCREEN)
return int(w), int(h)
}
func osSetWindowSize(window *Window, width int, height int) {
if w, ok := windowStore[window.handle]; ok {
w.SetSize(walk.Size{width, height})
}
}
func osSetWindowPosition(window *Window, left int, top int) {
if w, ok := windowStore[window.handle]; ok {
w.SetX(left)
w.SetY(top)
}
}
func osRememberGeometry(window *Window, key string) {
// C.RememberWindowGeometry(C.int(window.handle), C.CString(key))
}
func osRunModal(window *Window) {
// if w, ok := windowStore[window.handle]; ok {
// w.Run()
// }
}