added meta panel to buffers with line/col info

This commit is contained in:
Felix Angell 2018-05-06 13:59:14 +01:00
parent faa0d58d3f
commit 58b7cb9d50
2 changed files with 35 additions and 2 deletions

View File

@ -1,9 +1,12 @@
package gui
import (
"fmt"
"github.com/felixangell/strife"
)
var metaPanelHeight = 32
type BufferPane struct {
BaseComponent
Buff *Buffer
@ -16,6 +19,35 @@ func NewBufferPane(buff *Buffer) *BufferPane {
}
}
func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
pad := 10
mpY := (b.y + b.h) - (metaPanelHeight)
// panel backdrop
ctx.SetColor(strife.Black)
ctx.Rect(b.x, mpY, b.w, metaPanelHeight, strife.Fill)
{
infoLine := fmt.Sprintf("Line %d, Column %d", b.Buff.curs.y, b.Buff.curs.x)
ctx.SetColor(strife.White)
_, strHeight := ctx.String(infoLine, b.x+(pad/2), mpY+(pad/2))
metaPanelHeight = strHeight + pad
}
// resize to match new height if any
b.Buff.Resize(b.w, b.h-metaPanelHeight)
}
func (b *BufferPane) Resize(w, h int) {
b.BaseComponent.Resize(w, h)
b.Buff.Resize(w, h)
}
func (b *BufferPane) SetPosition(x, y int) {
b.BaseComponent.SetPosition(x, y)
b.Buff.SetPosition(x, y)
}
func (b *BufferPane) OnUpdate() bool {
b.Buff.processInput(nil)
return b.Buff.OnUpdate()
@ -23,4 +55,5 @@ func (b *BufferPane) OnUpdate() bool {
func (b *BufferPane) OnRender(ctx *strife.Renderer) {
b.Buff.OnRender(ctx)
b.renderMetaPanel(ctx)
}

View File

@ -189,8 +189,8 @@ func (n *View) AddBuffer() *Buffer {
// translate all the buffers accordingly.
for i, buffPane := range n.buffers {
buffPane.Buff.Resize(bufferWidth, n.h)
buffPane.Buff.SetPosition(bufferWidth*i, 0)
buffPane.Resize(bufferWidth, n.h)
buffPane.SetPosition(bufferWidth*i, 0)
}
return c