1package selection
2
3import "github.com/bnema/nefergui"
4
5// view draws the scene. Geometry goes through Node.Rect, so no CSS strings
6// are built per frame; classes come from the embedded stylesheet. Boxes with no
7// area are not emitted at all, so an idle surface is one dim box plus the
8// header and footer, and no empty chip is painted.
9func view(f *nefergui.Frame, m *model) {
10 m.syncMode() // a Tab on another overlay redraws this one
11 m.refreshFooter()
12 root := f.Root(nefergui.Class("root"))
13 st := root.Stack(nefergui.Class("scene"))
14 s := m.scene()
15 for i, r := range s.dim {
16 box(st, dimKeys[i], "dim", r)
17 }
18 for i, r := range s.grid {
19 box(st, gridKeys[i], "grid", r)
20 }
21 for i, r := range s.edges {
22 box(st, edgeKeys[i], "edge", r)
23 }
24 if n := tag(st, "label", s.label); n.ok {
25 n.node.Text(m.label.text)
26 }
27 if n := tag(st, "badge", s.badge); n.ok {
28 n.node.Text(badgeText(m.mode))
29 }
30 if n := tag(st, "header", s.header); n.ok {
31 n.node.Text(m.header)
32 }
33 if n := tag(st, "footer", s.footer); n.ok {
34 n.node.Text(m.footerText)
35 }
36}
37
38type tagged struct {
39 node nefergui.Node
40 ok bool
41}
42
43func box(st nefergui.Node, key, class string, r frect) {
44 if r.w > 0 && r.h > 0 {
45 st.Box(nefergui.Key(key), nefergui.Class(class)).Rect(r.x, r.y, r.w, r.h)
46 }
47}
48
49func tag(st nefergui.Node, key string, r frect) tagged {
50 if r.w <= 0 || r.h <= 0 {
51 return tagged{}
52 }
53 return tagged{st.Box(nefergui.Key(key), nefergui.Class("tag")).Rect(r.x, r.y, r.w, r.h), true}
54}
55
56// Static keys avoid building identity strings per frame.
57var (
58 dimKeys = [4]string{"dim0", "dim1", "dim2", "dim3"}
59 gridKeys = [6]string{"grid0", "grid1", "grid2", "grid3", "grid4", "grid5"}
60 edgeKeys = [4]string{"edge0", "edge1", "edge2", "edge3"}
61)