re-implemented close_buffer; fixed highlight line flickering

This commit is contained in:
Felix Angell 2018-04-29 00:54:08 +01:00
parent 445d645ab9
commit e6fa391b06
3 changed files with 24 additions and 6 deletions

View File

@ -926,7 +926,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
highlightLinePosY := ey + (ry + b.curs.ry*last_h) - (b.cam.y * last_h)
highlightLinePosX := ex + rx
ctx.Rect(highlightLinePosX, highlightLinePosY, b.w, last_h, strife.Fill)
ctx.Rect(highlightLinePosX, highlightLinePosY, b.w-ex, last_h, strife.Fill)
}
var visibleLines int = 50

View File

@ -1,5 +1,8 @@
package gui
func CloseBuffer(b *Buffer) bool {
view := b.parent
view.ChangeFocus(-1)
view.removeBuffer(b.index)
return false
}

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/felixangell/phi/cfg"
"github.com/felixangell/strife"
"log"
)
// View is an array of buffers basically.
@ -72,6 +73,24 @@ func sign(dir int) int {
return 0
}
func (n *View) removeBuffer(index int) {
log.Println("Removing buffer index:", index)
delete(n.buffers, index)
// only resize the buffers if we have
// some remaining in the window
if len(n.buffers) > 0 {
bufferWidth := n.w / len(n.buffers)
// translate all the components accordingly.
for i, buff := range n.buffers {
buff.Resize(bufferWidth, n.h)
buff.SetPosition(bufferWidth*i, 0)
}
}
}
func (n *View) ChangeFocus(dir int) {
prevBuff, _ := n.buffers[n.focusedBuff]
@ -132,17 +151,13 @@ func (n *View) AddBuffer() *Buffer {
// note that we +1 the components because
// we haven't yet added the panel
var bufferWidth int
bufferWidth = n.w / (len(n.buffers) + 1)
bufferWidth = n.w / (c.index + 1)
n.buffers[c.index] = c
n.focusedBuff = c.index
// translate all the components accordingly.
for i, buff := range n.buffers {
if buff == nil {
continue
}
buff.Resize(bufferWidth, n.h)
buff.SetPosition(bufferWidth*i, 0)
}