-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
95 lines (72 loc) · 1.7 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
package main
import (
"fmt"
"github.com/egonelbre/exp/dos/ui"
)
var (
Global *ui.Screen
)
func main() {
Global = &ui.Screen{}
Global.Start()
// defer Global.Stop()
ShowRecord(&MainMenu{})
}
func ShowRecord(record ui.Record) {
form := Global.NewForm()
form.Record = record
// TODO: choose sizes more intelligently
form.BoundsRect = ui.Rect{0, 0, 30, 30}
if len(Global.Forms) > 0 {
last := Global.Forms[len(Global.Forms)-1]
form.BoundsRect.Left = last.BoundsRect.Left + last.BoundsRect.Width + 1
}
form.Show()
}
type MainMenu struct {
Patient ui.Button
PatientID ui.Input
Exit ui.Button
}
func (menu *MainMenu) Caption() string {
return "Main Menu"
}
func (menu *MainMenu) Load() error {
menu.Patient = ui.Button{"Open Patient", menu.HandlePatient}
menu.PatientID = ui.Input{"> %v", "0000"}
menu.Exit = ui.Button{"Exit", menu.HandleExit}
return nil
}
func (menu *MainMenu) Save() error { return nil }
func (menu *MainMenu) HandlePatient(screen *ui.Form) {
info := &PatientInfo{}
info.ID = menu.PatientID.Text
ShowRecord(info)
}
func (menu *MainMenu) HandleExit(screen *ui.Form) {
screen.Close = true
}
type PatientInfo struct {
ID string
Name ui.Input
DOB ui.Input
}
func (patient *PatientInfo) Widgets() []ui.Widget {
return []ui.Widget{
&patient.Name,
&patient.DOB,
}
}
func (patient *PatientInfo) Caption() string {
return fmt.Sprintf("%s : %s", patient.ID, patient.Name.Text)
}
func (patient *PatientInfo) Load() error {
// TODO: load from DB, possibly with dynamic mapping
patient.Name = ui.Input{"Name: %v", "John Smith"}
patient.DOB = ui.Input{" DOB: %v", "1962 02 21"}
return nil
}
func (patient *PatientInfo) Save() error {
// TODO: save to DB
return nil
}