Begin tab implementation

This commit is contained in:
Zachary Yedidia
2019-01-09 20:07:18 -05:00
parent 853c143696
commit d54ccace1f
8 changed files with 175 additions and 47 deletions

View File

@@ -0,0 +1,57 @@
package display
import (
"log"
"github.com/zyedidia/micro/cmd/micro/config"
"github.com/zyedidia/micro/cmd/micro/screen"
)
type TabWindow struct {
Names []string
Active int
width int
hscroll int
y int
}
func NewTabWindow(w int, y int) *TabWindow {
tw := new(TabWindow)
tw.width = w
tw.y = y
return tw
}
func (w *TabWindow) Display() {
x := -w.hscroll
draw := func(r rune, n int) {
for i := 0; i < n; i++ {
screen.Screen.SetContent(x, w.y, r, nil, config.DefStyle.Reverse(true))
x++
log.Println(x)
}
}
for i, n := range w.Names {
if i == w.Active {
draw('[', 1)
}
for _, c := range n {
draw(c, 1)
}
if i == w.Active {
draw(']', 1)
draw(' ', 3)
} else {
draw(' ', 4)
}
if x >= w.width {
break
}
}
if x < w.width {
draw(' ', w.width-x)
}
}

View File

@@ -36,36 +36,32 @@ func (w *UIWindow) Display() {
w.drawNode(w.root)
}
func (w *UIWindow) Clear() {}
func (w *UIWindow) Relocate() bool { return false }
func (w *UIWindow) GetView() *View { return nil }
func (w *UIWindow) SetView(*View) {}
func (w *UIWindow) GetMouseLoc(vloc buffer.Loc) buffer.Loc {
var mouseLoc func(*views.Node) buffer.Loc
mouseLoc = func(n *views.Node) buffer.Loc {
func (w *UIWindow) GetMouseSplitID(vloc buffer.Loc) uint64 {
var mouseLoc func(*views.Node) uint64
mouseLoc = func(n *views.Node) uint64 {
cs := n.Children()
for i, c := range cs {
if c.Kind == views.STVert {
if i != len(cs)-1 {
if vloc.X == c.X+c.W && vloc.Y >= c.Y && vloc.Y < c.Y+c.H {
return buffer.Loc{int(c.ID()), 0}
return c.ID()
}
}
} 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 {
return buffer.Loc{int(c.ID()), 0}
return c.ID()
}
}
}
}
for _, c := range cs {
m := mouseLoc(c)
if m.X != -1 {
if m != 0 {
return m
}
}
return buffer.Loc{-1, 0}
return 0
}
return mouseLoc(w.root)
}