github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/dos/ui/form.go (about) 1 package ui 2 3 type Screen struct { 4 Forms []*Form 5 Actions chan Action 6 } 7 8 func (screen *Screen) NewForm() *Form { 9 return &Form{Screen: screen} 10 } 11 12 func (screen *Screen) Push(form *Form) { screen.Forms = append(screen.Forms, form) } 13 func (screen *Screen) Pop() { screen.Forms = screen.Forms[:len(screen.Forms)-1] } 14 15 type Form struct { 16 BoundsRect Rect 17 ClientRect Rect 18 19 Screen *Screen 20 21 Close bool 22 Save bool 23 24 Record Record 25 26 Components []*Component 27 FocusedIndex int 28 } 29 30 type Action interface{} 31 32 type Record interface { 33 Caption() string 34 35 Load() error 36 Save() error 37 } 38 39 type Component struct { 40 Rect 41 Focused bool 42 Widget Widget 43 } 44 45 type Widget interface { 46 Focusable() bool 47 Handle(screen *Form, action Action) 48 49 Unserialize(data []byte) error 50 Serialize() ([]byte, error) 51 52 Render(screen *Form, component *Component) 53 }