change default font to Arial Unicode for mac; small cleanups

This commit is contained in:
Felix Angell 2021-01-09 12:57:32 +00:00
parent fad16bdcaf
commit 6ffcff9600
5 changed files with 23 additions and 88 deletions

View File

@ -19,7 +19,7 @@ type BufferPane struct {
} }
func NewBufferPane(buff *Buffer) *BufferPane { func NewBufferPane(buff *Buffer) *BufferPane {
fontPath := filepath.Join(cfg.FONT_FOLDER, buff.cfg.Editor.Font_Face+".ttf") fontPath := filepath.Join(cfg.FontFolder, buff.cfg.Editor.Font_Face+".ttf")
// FIXME DPI // FIXME DPI
metaPanelFont, err := strife.LoadFont(fontPath, int(14.0*cfg.ScaleFactor)) metaPanelFont, err := strife.LoadFont(fontPath, int(14.0*cfg.ScaleFactor))
if err != nil { if err != nil {

View File

@ -9,7 +9,7 @@ tabs_are_spaces = true
match_braces = false match_braces = false
maintain_indentation = true maintain_indentation = true
highlight_line = true highlight_line = true
font_face = "Courier New" font_face = "Arial Unicode"
font_size = 20 font_size = 20
show_line_numbers = true show_line_numbers = true

View File

@ -23,21 +23,21 @@ import (
// //
const ( const (
CONFIG_DIR_PATH = "/.phi-editor/" ConfigDirPath = "/.phi-editor/"
CONFIG_TOML_FILE = "config.toml" ConfigTomlFile = "config.toml"
) )
var FONT_FOLDER string = "" var FontFolder = ""
// this is the absolute path to the // this is the absolute path to the
// config.toml file. todo rename/refactor // config.toml file. todo rename/refactor
var CONFIG_FULL_PATH string = "" var ConfigFullPath = ""
// the absolute path to the config directory // the absolute path to the config directory
// rename/refactor due here too! // rename/refactor due here too!
var configDirAbsPath string = "" var configDirAbsPath = ""
var ICON_DIR_PATH string = "" var IconDirPath = ""
// TODO we only had double key combos // TODO we only had double key combos
// e.g. cmd+s. we want to handle things // e.g. cmd+s. we want to handle things
@ -85,14 +85,14 @@ func configureAndValidate(conf *TomlConfig) {
if len(conf.Editor.Font_Path) == 0 { if len(conf.Editor.Font_Path) == 0 {
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
FONT_FOLDER = filepath.Join(os.Getenv("WINDIR"), "fonts") FontFolder = filepath.Join(os.Getenv("WINDIR"), "fonts")
case "darwin": case "darwin":
FONT_FOLDER = "/Library/Fonts/" FontFolder = "/Library/Fonts/"
case "linux": case "linux":
FONT_FOLDER = findFontFolder() FontFolder = findFontFolder()
} }
// and set it accordingly. // and set it accordingly.
conf.Editor.Font_Path = FONT_FOLDER conf.Editor.Font_Path = FontFolder
} }
// we only support ttf at the moment. // we only support ttf at the moment.
@ -190,15 +190,15 @@ func Setup() TomlConfig {
home = os.Getenv("USERPROFILE") home = os.Getenv("USERPROFILE")
} }
CONFIG_DIR := filepath.Join(home, CONFIG_DIR_PATH) CONFIG_DIR := filepath.Join(home, ConfigDirPath)
configDirAbsPath = CONFIG_DIR configDirAbsPath = CONFIG_DIR
CONFIG_PATH := filepath.Join(CONFIG_DIR, CONFIG_TOML_FILE) CONFIG_PATH := filepath.Join(CONFIG_DIR, ConfigTomlFile)
// this folder is where we store all of the language syntax // this folder is where we store all of the language syntax
SYNTAX_CONFIG_DIR := filepath.Join(CONFIG_DIR, "syntax") SYNTAX_CONFIG_DIR := filepath.Join(CONFIG_DIR, "syntax")
CONFIG_FULL_PATH = CONFIG_PATH ConfigFullPath = CONFIG_PATH
// if the user doesn't have a /.phi-editor // if the user doesn't have a /.phi-editor
// directory we create it for them. // directory we create it for them.
@ -211,9 +211,9 @@ func Setup() TomlConfig {
// ---- // ----
// downloads the icon from github // downloads the icon from github
// and puts it into the phi-editor config folder. // and puts it into the phi-editor config folder.
ICON_DIR_PATH = filepath.Join(CONFIG_DIR, "icons") IconDirPath = filepath.Join(CONFIG_DIR, "icons")
if _, err := os.Stat(ICON_DIR_PATH); os.IsNotExist(err) { if _, err := os.Stat(IconDirPath); os.IsNotExist(err) {
if err := os.Mkdir(ICON_DIR_PATH, 0775); err != nil { if err := os.Mkdir(IconDirPath, 0775); err != nil {
panic(err) panic(err)
} }
@ -223,7 +223,7 @@ func Setup() TomlConfig {
downloadIcon := func(iconSize int) { downloadIcon := func(iconSize int) {
log.Println("downloading the phi icon ", iconSize, "x", iconSize, " png image.") log.Println("downloading the phi icon ", iconSize, "x", iconSize, " png image.")
file, err := os.Create(filepath.Join(ICON_DIR_PATH, fmt.Sprintf("icon%d.png", iconSize))) file, err := os.Create(filepath.Join(IconDirPath, fmt.Sprintf("icon%d.png", iconSize)))
defer file.Close() defer file.Close()
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())

View File

@ -1,67 +0,0 @@
package gui
import (
"github.com/felixangell/strife"
)
type debugPane struct {
fpsGraph *lineGraph
}
type lineGraph struct {
yAxisLabel string
xAxisLabel string
xValues []float64
yValues []float64
}
func newLineGraph(xAxis, yAxis string) *lineGraph {
return &lineGraph{
xAxis,
yAxis,
[]float64{},
[]float64{1, 2, 3, 4, 5, 6, 7},
}
}
func (l *lineGraph) plot(x, y float64) {
l.xValues = append(l.xValues, x)
l.yValues = append(l.yValues, y)
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func (l *lineGraph) render(ctx *strife.Renderer, x, y int) {
graphWidth, graphHeight := 256, 256
ctx.SetColor(strife.RGBA(0, 0, 0, 255))
ctx.Rect(x, y, graphWidth, graphHeight, strife.Fill)
// render last ten values
// xSnip := l.xValues[len(l.xValues)-10:]
ySnip := l.yValues[max(len(l.yValues)-256, 0):]
size := graphHeight / len(ySnip)
for idx, yItem := range ySnip {
ctx.SetColor(strife.RGB(255, 0, 255))
ctx.Rect(x+(idx*size), y+(graphHeight-(int(yItem)*size)), 5, 5, strife.Fill)
}
}
var pane = &debugPane{
newLineGraph("time", "framerate"),
}
func renderDebugPane(ctx *strife.Renderer, x, y int) {
ctx.SetColor(strife.HexRGB(0xff00ff))
{
pane.fpsGraph.render(ctx, x, y)
}
}

View File

@ -106,7 +106,9 @@ func main() {
} }
}) })
window.Create() if err := window.Create(); err != nil {
panic(err)
}
{ {
size := 16 size := 16
@ -122,7 +124,7 @@ func main() {
} }
iconFile := fmt.Sprintf("icon%d.png", size) iconFile := fmt.Sprintf("icon%d.png", size)
icon, err := strife.LoadImage(filepath.Join(cfg.ICON_DIR_PATH, iconFile)) icon, err := strife.LoadImage(filepath.Join(cfg.IconDirPath, iconFile))
if err != nil { if err != nil {
log.Println("Failed to load icon ", err.Error()) log.Println("Failed to load icon ", err.Error())
} else { } else {