mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 19:20:21 +03:00
font fixes; close buffer behaviour fixes; etc
This commit is contained in:
parent
bfe0073f46
commit
f725e0d48c
@ -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?
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user