github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/dos/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/egonelbre/exp/dos/ui" 7 ) 8 9 var ( 10 Global *ui.Screen 11 ) 12 13 func main() { 14 Global = &ui.Screen{} 15 Global.Start() 16 // defer Global.Stop() 17 18 ShowRecord(&MainMenu{}) 19 } 20 21 func ShowRecord(record ui.Record) { 22 form := Global.NewForm() 23 form.Record = record 24 25 // TODO: choose sizes more intelligently 26 form.BoundsRect = ui.Rect{0, 0, 30, 30} 27 if len(Global.Forms) > 0 { 28 last := Global.Forms[len(Global.Forms)-1] 29 form.BoundsRect.Left = last.BoundsRect.Left + last.BoundsRect.Width + 1 30 } 31 32 form.Show() 33 } 34 35 type MainMenu struct { 36 Patient ui.Button 37 PatientID ui.Input 38 39 Exit ui.Button 40 } 41 42 func (menu *MainMenu) Caption() string { 43 return "Main Menu" 44 } 45 46 func (menu *MainMenu) Load() error { 47 menu.Patient = ui.Button{"Open Patient", menu.HandlePatient} 48 menu.PatientID = ui.Input{"> %v", "0000"} 49 menu.Exit = ui.Button{"Exit", menu.HandleExit} 50 51 return nil 52 } 53 func (menu *MainMenu) Save() error { return nil } 54 55 func (menu *MainMenu) HandlePatient(screen *ui.Form) { 56 info := &PatientInfo{} 57 info.ID = menu.PatientID.Text 58 59 ShowRecord(info) 60 } 61 62 func (menu *MainMenu) HandleExit(screen *ui.Form) { 63 screen.Close = true 64 } 65 66 type PatientInfo struct { 67 ID string 68 69 Name ui.Input 70 DOB ui.Input 71 } 72 73 func (patient *PatientInfo) Widgets() []ui.Widget { 74 return []ui.Widget{ 75 &patient.Name, 76 &patient.DOB, 77 } 78 } 79 80 func (patient *PatientInfo) Caption() string { 81 return fmt.Sprintf("%s : %s", patient.ID, patient.Name.Text) 82 } 83 84 func (patient *PatientInfo) Load() error { 85 // TODO: load from DB, possibly with dynamic mapping 86 patient.Name = ui.Input{"Name: %v", "John Smith"} 87 patient.DOB = ui.Input{" DOB: %v", "1962 02 21"} 88 89 return nil 90 } 91 92 func (patient *PatientInfo) Save() error { 93 // TODO: save to DB 94 return nil 95 }