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