start of command palette stuff; cleaned up _some_ of the gui component semantics...

still kind of messy though, need to hack away at it on my main pc before i continue
anything properly.
This commit is contained in:
Felix Angell 2018-04-16 20:10:23 +01:00
parent 8b3ec8dda9
commit cececb945b
7 changed files with 75 additions and 30 deletions

View File

@ -689,7 +689,9 @@ func (b *Buffer) HandleEvent(evt strife.StrifeEvent) {
}
func (b *Buffer) OnUpdate() bool {
b.HasFocus = true
if !b.HasFocus {
return false
}
prev_x := b.curs.x
prev_y := b.curs.y

View File

@ -1,6 +1,8 @@
package gui
func CloseBuffer(b *Buffer) bool {
// FIXME
// no parent. this can happen sometimes
// for example if we're trying to close
// a buffer illegal, e.g. a palette has

View File

@ -1,12 +1,25 @@
package gui
import rope "github.com/felixangell/go-rope"
// FIXME
func DeleteLine(b *Buffer) bool {
if b.curs.y == 0 {
b.contents[b.curs.y] = new(rope.Rope)
return false
}
if b.curs.y >= len(b.contents) {
return false
}
prevLineLen := b.contents[b.curs.y].Len()
b.contents = remove(b.contents[:], b.curs.y)
b.contents = remove(b.contents, b.curs.y)
if b.curs.y >= len(b.contents) {
b.moveUp()
return false
}
currLineLen := b.contents[b.curs.y].Len()

View File

@ -1,41 +1,38 @@
package gui
import (
"github.com/veandco/go-sdl2/sdl"
"github.com/felixangell/phi-editor/cfg"
"github.com/felixangell/strife"
)
type CommandBuffer struct {
*Buffer
}
func (b *CommandBuffer) processActionKey() {
// TODO
// b.Buffer.processActionKey()
}
type CommandPalette struct {
BaseComponent
buffer *CommandBuffer
buff *Buffer
}
func NewCommandPalette() *CommandPalette {
palette := &CommandPalette{}
palette.buffer = &CommandBuffer{
Buffer: NewBuffer(nil, nil, 0),
func NewCommandPalette(conf *cfg.TomlConfig) *CommandPalette {
palette := &CommandPalette{
buff: NewBuffer(conf, nil, 0),
}
palette.AddComponent(palette.buffer)
palette.buff.HasFocus = true
return palette
}
func (p *CommandPalette) OnDispose() {}
func (p *CommandPalette) OnInit() {
}
func (c *CommandPalette) OnUpdate() {
func (b *CommandPalette) OnInit() {
}
func (c *CommandPalette) OnRender(ctx *sdl.Renderer) {
func (b *CommandPalette) OnUpdate() bool {
return b.buff.OnUpdate()
}
func (b *CommandPalette) OnRender(ctx *strife.Renderer) {
ctx.SetColor(strife.Red)
ctx.Rect(b.x, b.y, b.w, b.h, strife.Fill)
b.buff.OnRender(ctx)
}
func (b *CommandPalette) OnDispose() {
}

0
gui/untitled Normal file
View File

View File

@ -8,16 +8,28 @@ import (
type View struct {
BaseComponent
conf *cfg.TomlConfig
buffers map[int]*Buffer
focusedBuff int
}
func NewView(width, height int, conf *cfg.TomlConfig) *View {
view := &View{conf: conf}
view := &View{
conf: conf,
buffers: map[int]*Buffer{},
}
view.Translate(width, height)
view.Resize(width, height)
view.focusPalette()
return view
}
func (n *View) focusPalette() {
// clear focus from buffers
for _, buff := range n.buffers {
buff.HasFocus = false
}
}
func sign(dir int) int {
if dir > 0 {
return 1
@ -29,7 +41,7 @@ func sign(dir int) int {
func (n *View) ChangeFocus(dir int) {
// remove focus from the curr buffer.
if buf := n.components[n.focusedBuff].(*Buffer); buf != nil {
if buf, ok := n.buffers[n.focusedBuff]; ok {
buf.HasFocus = false
}
@ -49,10 +61,17 @@ func (n *View) OnInit() {
}
func (n *View) OnUpdate() bool {
if buff := n.components[n.focusedBuff]; buff != nil {
return Update(buff)
dirty := false
for _, comp := range n.components {
if comp == nil {
continue
}
if Update(comp) {
dirty = true
}
}
return false
return dirty
}
func (n *View) OnRender(ctx *strife.Renderer) {}
@ -60,7 +79,12 @@ func (n *View) OnRender(ctx *strife.Renderer) {}
func (n *View) OnDispose() {}
func (n *View) AddBuffer() *Buffer {
if buf, ok := n.buffers[n.focusedBuff]; ok {
buf.HasFocus = false
}
c := NewBuffer(n.conf, n, n.NumComponents())
c.HasFocus = true
// work out the size of the buffer and set it
// note that we +1 the components because
@ -79,6 +103,7 @@ func (n *View) AddBuffer() *Buffer {
}
n.AddComponent(c)
n.buffers[c.index] = c
n.focusedBuff = c.index
// translate all the components accordingly.

View File

@ -51,6 +51,12 @@ func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
mainView.AddBuffer().OpenFile(tempFile.Name())
}
{
palette := gui.NewCommandPalette(cfg)
palette.Resize(1280/3, 72)
// mainView.AddComponent(palette)
}
n.AddComponent(mainView)
// TODO put me somewhere else: