-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
123 lines (92 loc) · 2.99 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
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
// Copyright (c) 2020, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// main for GUI interaction with Env for testing
package main
import (
"github.com/emer/etable/etview"
_ "github.com/emer/etable/etview" // include to get gui views
"github.com/goki/gi/gi"
"github.com/goki/gi/gimain"
"github.com/goki/gi/giv"
"github.com/goki/ki/ki"
"github.com/goki/mat32"
)
func main() {
TheSim.Config()
gimain.Main(func() { // this starts gui -- requires valid OpenGL display connection (e.g., X11)
guirun()
})
}
func guirun() {
win := TheSim.ConfigGui()
win.StartEventLoop()
}
// LogPrec is precision for saving float values in logs
const LogPrec = 4
// Sim holds the params, table, etc
type Sim struct {
// the env item
Sac Saccade `desc:"the env item"`
// [view: -] the main view
View *etview.TableView `view:"-" desc:"the main view"`
// [view: -] main GUI window
Win *gi.Window `view:"-" desc:"main GUI window"`
// [view: -] the master toolbar
ToolBar *gi.ToolBar `view:"-" desc:"the master toolbar"`
}
// TheSim is the overall state for this simulation
var TheSim Sim
// Config configures all the elements using the standard functions
func (ss *Sim) Config() {
ss.Sac.Defaults()
// ss.Sac.AddRows = true
ss.Sac.Init()
ss.Sac.Step() // need one in there
}
// ConfigGui configures the GoGi gui interface for this simulation,
func (ss *Sim) ConfigGui() *gi.Window {
width := 1600
height := 1200
// gi.WinEventTrace = true
gi.SetAppName("env")
gi.SetAppAbout(`This tests an Env. See <a href="https://github.com/emer/emergent">emergent on GitHub</a>.</p>`)
win := gi.NewMainWindow("env", "Env Test", width, height)
ss.Win = win
vp := win.WinViewport2D()
updt := vp.UpdateStart()
mfr := win.SetMainFrame()
tbar := gi.AddNewToolBar(mfr, "tbar")
tbar.SetStretchMaxWidth()
ss.ToolBar = tbar
split := gi.AddNewSplitView(mfr, "split")
split.Dim = mat32.X
split.SetStretchMax()
sv := giv.AddNewStructView(split, "sv")
sv.SetStruct(&ss.Sac)
tv := gi.AddNewTabView(split, "tv")
ss.View = tv.AddNewTab(etview.KiT_TableView, "Table").(*etview.TableView)
ss.View.SetTable(ss.Sac.Table, nil)
split.SetSplits(.2, .8)
tbar.AddAction(gi.ActOpts{Label: "Init", Icon: "reset", Tooltip: "Init env."}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
ss.Sac.Init()
ss.View.UpdateTable()
vp.SetNeedsFullRender()
})
tbar.AddAction(gi.ActOpts{Label: "Step", Icon: "step-fwd", Tooltip: "Step env."}, win.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
ss.Sac.Step()
ss.View.UpdateTable()
vp.SetNeedsFullRender()
})
vp.UpdateEndNoSig(updt)
// main menu
appnm := gi.AppName()
mmen := win.MainMenu
mmen.ConfigMenus([]string{appnm, "File", "Edit", "Window"})
amen := win.MainMenu.ChildByName(appnm, 0).(*gi.Action)
amen.Menu.AddAppMenu(win)
emen := win.MainMenu.ChildByName("Edit", 1).(*gi.Action)
emen.Menu.AddCopyCutPaste(win)
win.MainMenuUpdated()
return win
}