-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (46 loc) · 1.1 KB
/
main.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
package main
import (
"flag"
"io/ioutil"
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/themes/dark"
)
var data = flag.String("data", "data", "path to data folder")
var file = flag.String("file", "file", "file to edit")
func appMain(driver gxui.Driver) {
t := dark.CreateTheme(driver)
w := t.CreateWindow(800, 600, "Editor")
e := t.CreateCodeEditor()
w.AddChild(e)
text, err := ioutil.ReadFile(*file)
if err != nil {
e := displayError(t, err.Error())
e.OnClose(driver.Terminate)
gxui.EventLoop(driver)
}
e.SetText(string(text))
w.OnClose(driver.Terminate)
gxui.EventLoop(driver)
}
func displayError(theme gxui.Theme, m string) gxui.Window {
w := theme.CreateWindow(300, 100, "Error")
ll := theme.CreateLinearLayout()
ll.SetOrientation(gxui.Vertical)
ll.SetHorizontalAlignment(gxui.AlignCenter)
w.AddChild(ll)
l := theme.CreateLabel()
l.SetText(m)
ll.AddChild(l)
b := theme.CreateButton()
b.SetText("Okay")
b.OnClick(func(e gxui.MouseEvent) {
w.Close()
})
ll.AddChild(b)
return w
}
func main() {
flag.Parse()
gl.StartDriver(*data, appMain)
}