github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/dos/ui/render.go (about) 1 package ui 2 3 import termbox "github.com/nsf/termbox-go" 4 5 func (form *Form) Init() { 6 widgets := ReflectLoadWidgets(form.Record) 7 8 form.Components = nil 9 form.FocusedIndex = -1 10 11 form.Components = nil 12 for _, w := range widgets { 13 form.Components = append(form.Components, 14 &Component{Widget: w}) 15 } 16 form.UpdateLayout() 17 18 form.TabFocus(1) 19 } 20 21 func (form *Form) UpdateLayout() { 22 form.ClientRect = form.BoundsRect 23 24 form.ClientRect.Left = 1 25 form.ClientRect.Top = 3 26 form.ClientRect.Width -= 2 27 form.ClientRect.Height -= 4 28 29 box := form.ClientRect 30 box.Height = 1 31 for _, component := range form.Components { 32 component.Rect = box 33 box.Top += 1 34 } 35 } 36 37 func (form *Form) Render() { 38 r := Rect{0, 0, form.BoundsRect.Width, form.BoundsRect.Height} 39 form.DrawBlock(r, termbox.Cell{Ch: ' '}) 40 form.DrawBorder(r) 41 42 r = Rect{1, 1, form.BoundsRect.Width - 2, 1} 43 form.DrawText(r, form.Record.Caption(), false) 44 45 for _, component := range form.Components { 46 component.Widget.Render(form, component) 47 } 48 49 form.DrawFlush() 50 } 51 52 func (form *Form) Erase() { 53 r := Rect{0, 0, form.BoundsRect.Width, form.BoundsRect.Height} 54 form.DrawBlock(r, termbox.Cell{Ch: ' '}) 55 }