Bring tabpane back

Fix https://github.com/gizak/termui/issues/101
Fix https://github.com/gizak/termui/issues/94
Fix https://github.com/gizak/termui/issue
Fix Buffer.Sync() can not actually take affect
Fix Buffer.Bounds() cutting corner
This commit is contained in:
Zack Guo 2016-11-03 14:23:37 -04:00
parent c8b6d85d42
commit 7cbb70e87e
3 changed files with 8 additions and 6 deletions

View File

@ -69,11 +69,13 @@ func main() {
termui.Handle("/sys/kbd/j", func(termui.Event) {
tabpane.SetActiveLeft()
termui.Clear()
termui.Render(header, tabpane)
})
termui.Handle("/sys/kbd/k", func(termui.Event) {
tabpane.SetActiveRight()
termui.Clear()
termui.Render(header, tabpane)
})

View File

@ -46,7 +46,7 @@ func (b Buffer) Bounds() image.Rectangle {
y0 = p.Y
}
}
return image.Rect(x0, y0, x1, y1)
return image.Rect(x0, y0, x1+1, y1+1)
}
// SetArea assigns a new rect area to Buffer b.
@ -56,7 +56,7 @@ func (b *Buffer) SetArea(r image.Rectangle) {
}
// Sync sets drawing area to the buffer's bound
func (b Buffer) Sync() {
func (b *Buffer) Sync() {
b.SetArea(b.Bounds())
}

View File

@ -122,8 +122,8 @@ type point struct {
X int
Y int
Ch rune
Bg Attribute
Fg Attribute
Bg Attribute
}
func buf2pt(b Buffer) []point {
@ -179,7 +179,8 @@ func (tp *Tabpane) Buffer() Buffer {
tp.Width = tp.posTabText[len(tp.Tabs)] + 2
}
buf := tp.Block.Buffer()
ps := buf2pt(buf)
ps := []point{}
tp.align()
if tp.InnerHeight() <= 0 || tp.InnerWidth() <= 0 {
return NewBuffer()
@ -249,7 +250,6 @@ func (tp *Tabpane) Buffer() Buffer {
//draw tab content below the Tabpane
if i == tp.activeTabIndex {
blockPoints := buf2pt(tab.Buffer())
panic(len(blockPoints))
for i := 0; i < len(blockPoints); i++ {
blockPoints[i].Y += tp.Height + tp.Y
}
@ -260,6 +260,6 @@ func (tp *Tabpane) Buffer() Buffer {
for _, v := range ps {
buf.Set(v.X, v.Y, NewCell(v.Ch, v.Fg, v.Bg))
}
buf.Sync()
return buf
}