font fixes; close buffer behaviour fixes; etc

This commit is contained in:
Felix Angell 2018-05-09 12:49:42 +01:00
parent bfe0073f46
commit f725e0d48c
6 changed files with 38 additions and 11 deletions

View File

@ -29,6 +29,8 @@ const (
CONFIG_TOML_FILE = "config.toml"
)
var FONT_FOLDER string = ""
// this is the absolute path to the
// config.toml file. todo rename/refactor
var CONFIG_FULL_PATH string = ""
@ -80,19 +82,17 @@ func configureAndValidate(conf *TomlConfig) {
// fonts
log.Println("Configuring fonts")
{
var fontFolder string
switch runtime.GOOS {
case "windows":
fontFolder = filepath.Join(os.Getenv("WINDIR"), "fonts")
FONT_FOLDER = filepath.Join(os.Getenv("WINDIR"), "fonts")
case "darwin":
fontFolder = "/Library/Fonts/"
FONT_FOLDER = "/Library/Fonts/"
case "linux":
fontFolder = findFontFolder()
FONT_FOLDER = findFontFolder()
}
// we only support ttf at the moment.
fontPath := filepath.Join(fontFolder, conf.Editor.Font_Face) + ".ttf"
fontPath := filepath.Join(FONT_FOLDER, conf.Editor.Font_Face) + ".ttf"
if _, err := os.Stat(fontPath); os.IsNotExist(err) {
log.Fatal("No such font '" + fontPath + "'")
// TODO cool error messages for the toml format?

View File

@ -118,13 +118,13 @@ type BufferConfig struct {
cursorInvert int32
lineNumBackground int32
lineNumForeground int32
font *strife.Font
}
type Buffer struct {
BaseComponent
index int
parent *View
font *strife.Font
contents []*rope.Rope
curs *Cursor
cfg *cfg.TomlConfig
@ -1305,5 +1305,6 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
}
func (b *Buffer) OnRender(ctx *strife.Renderer) {
ctx.SetFont(b.buffOpts.font)
b.renderAt(ctx, b.x, b.y)
}

View File

@ -2,7 +2,10 @@ package gui
import (
"fmt"
"github.com/felixangell/phi/cfg"
"github.com/felixangell/strife"
"log"
"path/filepath"
)
var metaPanelHeight = 32
@ -10,12 +13,21 @@ var metaPanelHeight = 32
type BufferPane struct {
BaseComponent
Buff *Buffer
font *strife.Font
}
func NewBufferPane(buff *Buffer) *BufferPane {
fontPath := filepath.Join(cfg.FONT_FOLDER, buff.cfg.Editor.Font_Face+".ttf")
metaPanelFont, err := strife.LoadFont(fontPath, 14)
if err != nil {
log.Println("Note: failed to load meta panel font ", fontPath)
metaPanelFont = buff.buffOpts.font
}
return &BufferPane{
BaseComponent{},
buff,
metaPanelFont,
}
}
@ -34,12 +46,15 @@ func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
// tab info etc. on right hand side
{
tabSize := b.Buff.cfg.Editor.Tab_Size
// TODO
syntaxName := "Undefined"
infoLine := fmt.Sprintf("Tab Size: %d Syntax: %s", tabSize, syntaxName)
ctx.SetColor(strife.HexRGB(conf.Suggestion.Foreground))
lastWidth, _ = ctx.String(infoLine, ((b.x + b.w) - (lastWidth + (pad))), mpY+(pad/2)+1)
ctx.SetFont(b.font)
lastWidth, _ = ctx.String(infoLine, ((b.x + b.w) - (lastWidth + (pad))), mpY+(pad/2))
}
{
@ -48,8 +63,15 @@ func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
modified = '*'
}
infoLine := fmt.Sprintf("%s%c Line %d, Column %d", b.Buff.filePath, modified, b.Buff.curs.y+1, b.Buff.curs.x+1)
infoLine := fmt.Sprintf("%s%c Line %d, Column %d", b.Buff.filePath, modified, b.Buff.curs.y+1, b.Buff.curs.x)
if DEBUG_MODE {
infoLine = fmt.Sprintf("%s, BuffIndex: %d", infoLine, b.Buff.index)
}
ctx.SetColor(strife.HexRGB(conf.Suggestion.Foreground))
ctx.SetFont(b.font)
_, strHeight := ctx.String(infoLine, b.x+pad, mpY+(pad/2)+1)
metaPanelHeight = strHeight + pad
}

View File

@ -6,11 +6,13 @@ func CloseBuffer(v *View, commands []string) bool {
return false
}
if len(v.buffers) > 1 {
v.ChangeFocus(-1)
if b.modified {
// do command palette thing!
return false
}
v.removeBuffer(b.index)
v.ChangeFocus(-1)
return false
}

View File

@ -96,6 +96,7 @@ func NewCommandPalette(conf cfg.TomlConfig, view *View) *CommandPalette {
// we dont show line numbers
// so these aren't necessary
0x0, 0x0,
conf.Editor.Loaded_Font,
}, nil, 0),
parentBuff: nil,
}

View File

@ -211,6 +211,7 @@ func (n *View) AddBuffer() *Buffer {
cfg.Theme.Cursor_Invert,
cfg.Theme.Gutter_Background,
cfg.Theme.Gutter_Foreground,
cfg.Editor.Loaded_Font,
}, n, len(n.buffers))
c.SetFocus(true)