command palette bug with text offset fixed; added debug mode toggled w

ctrl+f12
This commit is contained in:
Felix Angell 2018-05-09 12:32:02 +01:00
parent e73bc28a14
commit bfe0073f46
5 changed files with 43 additions and 7 deletions

0
foo Normal file
View File

View File

@ -830,9 +830,7 @@ func (b *Buffer) processActionKey(key int) bool {
// if no \t (i.e. start of line) go to
// the start of the line!
b.curs.gotoStart()
}
if ALT_DOWN {
} else if ALT_DOWN {
currLine := b.contents[b.curs.y]
i := b.curs.x
@ -1228,9 +1226,15 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
}
lineHeight := last_h + pad
yPos := b.ey + ((ry + y_col) * lineHeight) + halfPad
xPos := b.ex + (rx + ((x_col - 1) * last_w))
yPos := b.ey + (ry + (y_col * lineHeight)) + halfPad
last_w, last_h = ctx.String(string(char), b.ex+(rx+((x_col-1)*last_w)), yPos)
last_w, last_h = ctx.String(string(char), xPos, yPos)
if DEBUG_MODE {
ctx.SetColor(strife.HexRGB(0xff00ff))
ctx.Rect(xPos, yPos, last_w, last_h, strife.Line)
}
}
if b.cfg.Editor.Show_Line_Numbers {
@ -1248,6 +1252,11 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
ctx.SetColor(strife.HexRGB(b.buffOpts.lineNumBackground))
ctx.Rect(rx, yPos, gutterWidth, b.h, strife.Fill)
if DEBUG_MODE {
ctx.SetColor(strife.HexRGB(0xff00ff))
ctx.Rect(rx, yPos, gutterWidth, b.h, strife.Line)
}
ctx.SetColor(strife.HexRGB(b.buffOpts.lineNumForeground))
ctx.String(fmt.Sprintf("%*d", numLinesCharWidth, (start+lineNum)+1), rx+gutterPadPx, yPos)
@ -1271,6 +1280,11 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
ctx.SetColor(strife.HexRGB(b.buffOpts.cursor))
ctx.Rect(xPos, yPos, cursorWidth, cursorHeight, strife.Fill)
if DEBUG_MODE {
ctx.SetColor(strife.HexRGB(0xff00ff))
ctx.Rect(xPos, yPos, cursorWidth, cursorHeight, strife.Line)
}
}
if b.autoComplete.hasSuggestions() {
@ -1283,6 +1297,11 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
b.autoComplete.renderAt(xPos, yPos, ctx)
}
if DEBUG_MODE {
ctx.SetColor(strife.HexRGB(0xff00ff))
ctx.Rect(b.ex+rx, b.ey+ry, b.w-b.ex, b.h-b.ey, strife.Line)
}
}
func (b *Buffer) OnRender(ctx *strife.Renderer) {

View File

@ -4,6 +4,8 @@ import (
"github.com/felixangell/strife"
)
var DEBUG_MODE = false
type Component interface {
SetPosition(x, y int)
Translate(x, y int)

View File

@ -114,6 +114,7 @@ func NewCommandPalette(conf cfg.TomlConfig, view *View) *CommandPalette {
// general border offsets. this is a real easy fixme
// for general code clean but maybe another day!
palette.buff.ex = 5
palette.buff.ey = 0
suggestionBoxWidth = palette.w
@ -239,8 +240,13 @@ func (b *CommandPalette) OnRender(ctx *strife.Renderer) {
conf := b.conf.Theme.Palette
border := 5
xPos := b.x - border
yPos := b.y - border
paletteWidth := b.w + (border * 2)
paletteHeight := b.h + (border * 2)
ctx.SetColor(strife.HexRGB(conf.Outline))
ctx.Rect(b.x-border, b.y-border, b.w+(border*2), b.h+(border*2), strife.Fill)
ctx.Rect(xPos, yPos, paletteWidth, paletteHeight, strife.Fill)
_, charHeight := ctx.String("foo", -5000, -5000)
b.buff.ey = (suggestionBoxHeight / 2) - (charHeight / 2)
@ -256,4 +262,9 @@ func (b *CommandPalette) OnRender(ctx *strife.Renderer) {
}
}
}
if DEBUG_MODE {
ctx.SetColor(strife.HexRGB(0xff00ff))
ctx.Rect(xPos, yPos, paletteWidth, paletteHeight, strife.Line)
}
}

View File

@ -137,7 +137,7 @@ func (n *View) OnUpdate() bool {
CONTROL_DOWN = strife.KeyPressed(sdl.K_LCTRL) || strife.KeyPressed(sdl.K_RCTRL)
SUPER_DOWN = strife.KeyPressed(sdl.K_LGUI) || strife.KeyPressed(sdl.K_RGUI)
shortcutName := "ctl"
shortcutName := "ctrl"
mainSuper := CONTROL_DOWN
source := cfg.Shortcuts.Controls
@ -151,6 +151,10 @@ func (n *View) OnUpdate() bool {
if mainSuper && strife.PollKeys() {
r := rune(strife.PopKey())
if r == sdl.K_F12 {
DEBUG_MODE = !DEBUG_MODE
}
left := 1073741904
right := 1073741903