micro/internal/display/uiwindow.go

88 lines
1.9 KiB
Go
Raw Normal View History

2019-01-06 00:27:04 +03:00
package display
import (
2020-05-04 17:16:15 +03:00
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
"github.com/zyedidia/micro/v2/internal/util"
2020-05-04 17:16:15 +03:00
"github.com/zyedidia/micro/v2/internal/views"
2019-01-06 00:27:04 +03:00
)
type UIWindow struct {
root *views.Node
}
func NewUIWindow(n *views.Node) *UIWindow {
uw := new(UIWindow)
uw.root = n
return uw
}
func (w *UIWindow) drawNode(n *views.Node) {
cs := n.Children()
2019-01-11 00:37:05 +03:00
dividerStyle := config.DefStyle
if style, ok := config.Colorscheme["divider"]; ok {
dividerStyle = style
}
divchars := config.GetGlobalOption("divchars").(string)
if util.CharacterCountInString(divchars) != 2 {
divchars = "|-"
}
divchar, combc, _ := util.DecodeCharacterInString(divchars)
divreverse := config.GetGlobalOption("divreverse").(bool)
if divreverse {
dividerStyle = dividerStyle.Reverse(true)
}
2019-01-06 00:27:04 +03:00
for i, c := range cs {
if c.IsLeaf() && c.Kind == views.STVert {
if i != len(cs)-1 {
for h := 0; h < c.H; h++ {
screen.SetContent(c.X+c.W, c.Y+h, divchar, combc, dividerStyle)
2019-01-06 00:27:04 +03:00
}
}
} else {
w.drawNode(c)
}
}
}
func (w *UIWindow) Display() {
w.drawNode(w.root)
}
2019-01-10 04:07:18 +03:00
func (w *UIWindow) GetMouseSplitID(vloc buffer.Loc) uint64 {
var mouseLoc func(*views.Node) uint64
mouseLoc = func(n *views.Node) uint64 {
2019-01-06 00:27:04 +03:00
cs := n.Children()
for i, c := range cs {
2019-01-10 02:06:31 +03:00
if c.Kind == views.STVert {
2019-01-06 00:27:04 +03:00
if i != len(cs)-1 {
2019-01-10 02:06:31 +03:00
if vloc.X == c.X+c.W && vloc.Y >= c.Y && vloc.Y < c.Y+c.H {
2019-01-10 04:07:18 +03:00
return c.ID()
2019-01-06 00:27:04 +03:00
}
}
2019-01-10 02:06:31 +03:00
} else if c.Kind == views.STHoriz {
if i != len(cs)-1 {
if vloc.Y == c.Y+c.H-1 && vloc.X >= c.X && vloc.X < c.X+c.W {
2019-01-10 04:07:18 +03:00
return c.ID()
2019-01-10 02:06:31 +03:00
}
}
}
}
for _, c := range cs {
m := mouseLoc(c)
2019-01-10 04:07:18 +03:00
if m != 0 {
2019-01-10 02:06:31 +03:00
return m
2019-01-06 00:27:04 +03:00
}
}
2019-01-10 04:07:18 +03:00
return 0
2019-01-06 00:27:04 +03:00
}
return mouseLoc(w.root)
}
func (w *UIWindow) Resize(width, height int) {}
func (w *UIWindow) SetActive(b bool) {}