1package display
2
3import (
4	"github.com/zyedidia/micro/v2/internal/buffer"
5	"github.com/zyedidia/micro/v2/internal/config"
6	"github.com/zyedidia/micro/v2/internal/screen"
7	"github.com/zyedidia/micro/v2/internal/util"
8	"github.com/zyedidia/micro/v2/internal/views"
9)
10
11type UIWindow struct {
12	root *views.Node
13}
14
15func NewUIWindow(n *views.Node) *UIWindow {
16	uw := new(UIWindow)
17	uw.root = n
18	return uw
19}
20
21func (w *UIWindow) drawNode(n *views.Node) {
22	cs := n.Children()
23	dividerStyle := config.DefStyle
24	if style, ok := config.Colorscheme["divider"]; ok {
25		dividerStyle = style
26	}
27
28	divchars := config.GetGlobalOption("divchars").(string)
29	if util.CharacterCountInString(divchars) != 2 {
30		divchars = "|-"
31	}
32
33	divchar, combc, _ := util.DecodeCharacterInString(divchars)
34
35	divreverse := config.GetGlobalOption("divreverse").(bool)
36	if divreverse {
37		dividerStyle = dividerStyle.Reverse(true)
38	}
39
40	for i, c := range cs {
41		if c.Kind == views.STVert {
42			if i != len(cs)-1 {
43				for h := 0; h < c.H; h++ {
44					screen.SetContent(c.X+c.W, c.Y+h, divchar, combc, dividerStyle)
45				}
46			}
47		}
48		w.drawNode(c)
49	}
50}
51
52func (w *UIWindow) Display() {
53	w.drawNode(w.root)
54}
55
56func (w *UIWindow) GetMouseSplitNode(vloc buffer.Loc) *views.Node {
57	var mouseLoc func(*views.Node) *views.Node
58	mouseLoc = func(n *views.Node) *views.Node {
59		cs := n.Children()
60		for i, c := range cs {
61			if c.Kind == views.STVert {
62				if i != len(cs)-1 {
63					if vloc.X == c.X+c.W && vloc.Y >= c.Y && vloc.Y < c.Y+c.H {
64						return c
65					}
66				}
67			} else if c.Kind == views.STHoriz {
68				if i != len(cs)-1 {
69					if vloc.Y == c.Y+c.H-1 && vloc.X >= c.X && vloc.X < c.X+c.W {
70						return c
71					}
72				}
73			}
74		}
75		for _, c := range cs {
76			m := mouseLoc(c)
77			if m != nil {
78				return m
79			}
80		}
81		return nil
82	}
83	return mouseLoc(w.root)
84}
85func (w *UIWindow) Resize(width, height int) {}
86func (w *UIWindow) SetActive(b bool)         {}
87