handle alt f4; buffer pane over buffers

This commit is contained in:
Felix Angell 2018-05-06 13:45:17 +01:00
parent c9d915a7af
commit faa0d58d3f
3 changed files with 56 additions and 22 deletions

View File

@ -549,6 +549,14 @@ func (b *Buffer) processActionKey(key int) bool {
}
}
// temporary for the really slow
// exit times with alt f4...
if ALT_DOWN {
if key == sdl.K_F4 {
os.Exit(0)
}
}
switch key {
case sdl.K_CAPSLOCK:
CAPS_LOCK = !CAPS_LOCK
@ -1051,6 +1059,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
a, colorStack = int32(colorStack[len(colorStack)-1]), colorStack[:len(colorStack)-1]
ctx.SetColor(strife.HexRGB(a))
}
last_w, last_h = ctx.String(string(char), b.ex+(rx+((x_col-1)*last_w)), b.ey+(ry+(y_col*last_h)))
}

26
gui/buffer_pane.go Normal file
View File

@ -0,0 +1,26 @@
package gui
import (
"github.com/felixangell/strife"
)
type BufferPane struct {
BaseComponent
Buff *Buffer
}
func NewBufferPane(buff *Buffer) *BufferPane {
return &BufferPane{
BaseComponent{},
buff,
}
}
func (b *BufferPane) OnUpdate() bool {
b.Buff.processInput(nil)
return b.Buff.OnUpdate()
}
func (b *BufferPane) OnRender(ctx *strife.Renderer) {
b.Buff.OnRender(ctx)
}

View File

@ -13,7 +13,7 @@ type View struct {
BaseComponent
conf *cfg.TomlConfig
buffers map[int]*Buffer
buffers map[int]*BufferPane
focusedBuff int
commandPalette *CommandPalette
}
@ -21,7 +21,7 @@ type View struct {
func NewView(width, height int, conf *cfg.TomlConfig) *View {
view := &View{
conf: conf,
buffers: map[int]*Buffer{},
buffers: map[int]*BufferPane{},
}
view.Translate(width, height)
@ -63,8 +63,8 @@ func (n *View) focusPalette(buff *Buffer) {
func (n *View) UnfocusBuffers() {
// clear focus from buffers
for _, buff := range n.buffers {
buff.SetFocus(false)
for _, buffPane := range n.buffers {
buffPane.Buff.SetFocus(false)
}
}
@ -87,9 +87,9 @@ func (n *View) removeBuffer(index int) {
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)
for i, buffPane := range n.buffers {
buffPane.Buff.Resize(bufferWidth, n.h)
buffPane.Buff.SetPosition(bufferWidth*i, 0)
}
}
@ -110,15 +110,15 @@ func (n *View) ChangeFocus(dir int) {
n.focusedBuff = 0
}
prevBuff.SetFocus(false)
if buff, ok := n.buffers[n.focusedBuff]; ok {
buff.SetFocus(true)
prevBuff.Buff.SetFocus(false)
if buffPane, ok := n.buffers[n.focusedBuff]; ok {
buffPane.Buff.SetFocus(true)
}
}
func (n *View) getCurrentBuff() *Buffer {
if buff, ok := n.buffers[n.focusedBuff]; ok {
return buff
if buffPane, ok := n.buffers[n.focusedBuff]; ok {
return buffPane.Buff
}
return nil
}
@ -144,9 +144,8 @@ func (n *View) OnUpdate() bool {
}
}
if buff, ok := n.buffers[n.focusedBuff]; ok {
buff.processInput(nil)
buff.OnUpdate()
if buffPane, ok := n.buffers[n.focusedBuff]; ok {
buffPane.OnUpdate()
}
n.commandPalette.OnUpdate()
@ -155,8 +154,8 @@ func (n *View) OnUpdate() bool {
}
func (n *View) OnRender(ctx *strife.Renderer) {
for _, buffer := range n.buffers {
buffer.OnRender(ctx)
for _, buffPane := range n.buffers {
buffPane.OnRender(ctx)
}
n.commandPalette.OnRender(ctx)
@ -185,13 +184,13 @@ func (n *View) AddBuffer() *Buffer {
var bufferWidth int
bufferWidth = n.w / (c.index + 1)
n.buffers[c.index] = c
n.buffers[c.index] = NewBufferPane(c)
n.focusedBuff = c.index
// translate all the components accordingly.
for i, buff := range n.buffers {
buff.Resize(bufferWidth, n.h)
buff.SetPosition(bufferWidth*i, 0)
// translate all the buffers accordingly.
for i, buffPane := range n.buffers {
buffPane.Buff.Resize(bufferWidth, n.h)
buffPane.Buff.SetPosition(bufferWidth*i, 0)
}
return c