mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
added mouse wheel scrolling + font face/size settings in toml configs
This commit is contained in:
parent
483066ab6f
commit
7c4706356b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
glew.h
|
||||||
phi-editor
|
phi-editor
|
||||||
fmt.sh
|
fmt.sh
|
||||||
|
|
||||||
|
@ -112,6 +112,8 @@ type EditorConfig struct {
|
|||||||
Match_Braces bool
|
Match_Braces bool
|
||||||
Maintain_Indentation bool
|
Maintain_Indentation bool
|
||||||
Highlight_Line bool
|
Highlight_Line bool
|
||||||
|
Font_Face string
|
||||||
|
Font_Size int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultConfig() *TomlConfig {
|
func NewDefaultConfig() *TomlConfig {
|
||||||
|
@ -7,13 +7,26 @@ 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 Bold"
|
||||||
|
font_size = 20
|
||||||
|
|
||||||
[render]
|
[render]
|
||||||
aliased = true
|
aliased = true
|
||||||
accelerated = true
|
accelerated = true
|
||||||
throttle_cpu_usage = true
|
throttle_cpu_usage = true
|
||||||
always_render = false
|
always_render = true
|
||||||
|
|
||||||
|
[theme]
|
||||||
|
background = 0x002649
|
||||||
|
foreground = 0xf2f4f6
|
||||||
|
cursor = 0xf2f4f6
|
||||||
|
cursor_invert = 0x000000
|
||||||
|
|
||||||
|
[cursor]
|
||||||
|
flash_rate = 400
|
||||||
|
reset_delay = 400
|
||||||
|
draw = true
|
||||||
|
flash = true
|
||||||
|
|
||||||
[file_associations]
|
[file_associations]
|
||||||
[file_associations.c]
|
[file_associations.c]
|
||||||
@ -29,7 +42,7 @@ match = [
|
|||||||
"type", "import", "package", "func", "struct",
|
"type", "import", "package", "func", "struct",
|
||||||
"append", "delete", "make", "for", "if", "while",
|
"append", "delete", "make", "for", "if", "while",
|
||||||
"switch", "select", "chan", "else", "var", "const",
|
"switch", "select", "chan", "else", "var", "const",
|
||||||
"iota"
|
"iota", "case"
|
||||||
]
|
]
|
||||||
|
|
||||||
[syntax.go.type]
|
[syntax.go.type]
|
||||||
@ -42,8 +55,8 @@ match = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[syntax.go.comment]
|
[syntax.go.comment]
|
||||||
colouring = 0xff00ff
|
colouring = 0x4b79fc
|
||||||
pattern = "[\/]+.*"
|
pattern = "[\\/]+.*"
|
||||||
|
|
||||||
[syntax.go.symbol]
|
[syntax.go.symbol]
|
||||||
colouring = 0xf0a400
|
colouring = 0xf0a400
|
||||||
@ -68,18 +81,6 @@ match = [
|
|||||||
"goto", "static", "extern", "const", "typedef",
|
"goto", "static", "extern", "const", "typedef",
|
||||||
]
|
]
|
||||||
|
|
||||||
[theme]
|
|
||||||
background = 0x002649
|
|
||||||
foreground = 0xf2f4f6
|
|
||||||
cursor = 0xf2f4f6
|
|
||||||
cursor_invert = 0x000000
|
|
||||||
|
|
||||||
[cursor]
|
|
||||||
flash_rate = 400
|
|
||||||
reset_delay = 400
|
|
||||||
draw = true
|
|
||||||
flash = true
|
|
||||||
|
|
||||||
[commands]
|
[commands]
|
||||||
[commands.save]
|
[commands.save]
|
||||||
shortcut = "super+s"
|
shortcut = "super+s"
|
||||||
@ -88,5 +89,4 @@ shortcut = "super+s"
|
|||||||
shortcut = "super+w"
|
shortcut = "super+w"
|
||||||
|
|
||||||
[commands.delete_line]
|
[commands.delete_line]
|
||||||
shortcut = "super+d"
|
shortcut = "super+d"`
|
||||||
`
|
|
||||||
|
@ -12,8 +12,7 @@ highlight_line = true
|
|||||||
aliased = true
|
aliased = true
|
||||||
accelerated = true
|
accelerated = true
|
||||||
throttle_cpu_usage = true
|
throttle_cpu_usage = true
|
||||||
always_render = false
|
always_render = true
|
||||||
|
|
||||||
|
|
||||||
[file_associations]
|
[file_associations]
|
||||||
[file_associations.c]
|
[file_associations.c]
|
||||||
@ -29,7 +28,7 @@ match = [
|
|||||||
"type", "import", "package", "func", "struct",
|
"type", "import", "package", "func", "struct",
|
||||||
"append", "delete", "make", "for", "if", "while",
|
"append", "delete", "make", "for", "if", "while",
|
||||||
"switch", "select", "chan", "else", "var", "const",
|
"switch", "select", "chan", "else", "var", "const",
|
||||||
"iota"
|
"iota", "case"
|
||||||
]
|
]
|
||||||
|
|
||||||
[syntax.go.type]
|
[syntax.go.type]
|
||||||
@ -42,8 +41,8 @@ match = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[syntax.go.comment]
|
[syntax.go.comment]
|
||||||
colouring = 0xff00ff
|
colouring = 0x4b79fc
|
||||||
pattern = "[\/]+.*"
|
pattern = "[\\/]+.*"
|
||||||
|
|
||||||
[syntax.go.symbol]
|
[syntax.go.symbol]
|
||||||
colouring = 0xf0a400
|
colouring = 0xf0a400
|
||||||
@ -88,5 +87,4 @@ shortcut = "ctrl+s"
|
|||||||
shortcut = "ctrl+w"
|
shortcut = "ctrl+w"
|
||||||
|
|
||||||
[commands.delete_line]
|
[commands.delete_line]
|
||||||
shortcut = "ctrl+d"
|
shortcut = "ctrl+d"`
|
||||||
`
|
|
||||||
|
@ -357,13 +357,16 @@ func (b *Buffer) swapLineDown() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) scrollUp() {
|
func (b *Buffer) scrollUp() {
|
||||||
// TODO move the cursor down 45 lines
|
if b.cam.y > 0 {
|
||||||
// IF the buffer exceeds the window size.
|
// TODO move the cursor down 45 lines
|
||||||
lineScrollAmount := 10
|
// IF the buffer exceeds the window size.
|
||||||
b.cam.y -= lineScrollAmount
|
lineScrollAmount := 10
|
||||||
for i := 0; i < lineScrollAmount; i++ {
|
b.cam.y -= lineScrollAmount
|
||||||
b.moveUp()
|
for i := 0; i < lineScrollAmount; i++ {
|
||||||
|
b.moveUp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) scrollDown() {
|
func (b *Buffer) scrollDown() {
|
||||||
@ -625,6 +628,18 @@ func (b *Buffer) makeTab() string {
|
|||||||
return string(blah)
|
return string(blah)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Buffer) HandleEvent(evt strife.StrifeEvent) {
|
||||||
|
switch event := evt.(type) {
|
||||||
|
case *strife.MouseWheelEvent:
|
||||||
|
if event.Y > 0 {
|
||||||
|
b.scrollDown()
|
||||||
|
}
|
||||||
|
if event.Y < 0 {
|
||||||
|
b.scrollUp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Buffer) OnUpdate() bool {
|
func (b *Buffer) OnUpdate() bool {
|
||||||
b.HasFocus = true
|
b.HasFocus = true
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ type Component interface {
|
|||||||
AddComponent(c Component)
|
AddComponent(c Component)
|
||||||
GetComponents() []Component
|
GetComponents() []Component
|
||||||
|
|
||||||
|
HandleEvent(evt strife.StrifeEvent)
|
||||||
|
|
||||||
GetInputHandler() *InputHandler
|
GetInputHandler() *InputHandler
|
||||||
SetInputHandler(h *InputHandler)
|
SetInputHandler(h *InputHandler)
|
||||||
}
|
}
|
||||||
@ -30,6 +32,10 @@ type BaseComponent struct {
|
|||||||
inputHandler *InputHandler
|
inputHandler *InputHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BaseComponent) HandleEvent(evt strife.StrifeEvent) {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BaseComponent) DeleteComponent(index int) {
|
func (b *BaseComponent) DeleteComponent(index int) {
|
||||||
b.components[index] = nil
|
b.components[index] = nil
|
||||||
b.numComponents--
|
b.numComponents--
|
||||||
|
15
gui/input.go
15
gui/input.go
@ -1,7 +1,20 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
import "github.com/veandco/go-sdl2/sdl"
|
import (
|
||||||
|
"github.com/felixangell/strife"
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
|
)
|
||||||
|
|
||||||
type InputHandler struct {
|
type InputHandler struct {
|
||||||
Event sdl.Event
|
Event sdl.Event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandleEvent(comp Component, evt strife.StrifeEvent) {
|
||||||
|
comp.HandleEvent(evt)
|
||||||
|
for _, child := range comp.GetComponents() {
|
||||||
|
if child == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
child.HandleEvent(evt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
33
main.go
33
main.go
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -23,6 +24,12 @@ type PhiEditor struct {
|
|||||||
defaultFont *strife.Font
|
defaultFont *strife.Font
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *PhiEditor) handleEvent(evt strife.StrifeEvent) {
|
||||||
|
for _, comp := range n.GetComponents() {
|
||||||
|
gui.HandleEvent(comp, evt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
||||||
mainView := gui.NewView(1280, 720, cfg)
|
mainView := gui.NewView(1280, 720, cfg)
|
||||||
|
|
||||||
@ -46,7 +53,22 @@ func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
|||||||
|
|
||||||
n.AddComponent(mainView)
|
n.AddComponent(mainView)
|
||||||
|
|
||||||
font, err := strife.LoadFont("./res/firacode.ttf", 20)
|
// TODO put me somewhere else:
|
||||||
|
// also improve the font loading code
|
||||||
|
var fontFolder string
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
fontFolder = path.Join(os.Getenv("%WINDIR%"), "fonts")
|
||||||
|
case "darwin":
|
||||||
|
fontFolder = "/Library/Fonts/"
|
||||||
|
case "linux":
|
||||||
|
fontFolder = "/usr/share/fonts/"
|
||||||
|
}
|
||||||
|
|
||||||
|
fontPath := path.Join(fontFolder, cfg.Editor.Font_Face) + ".ttf"
|
||||||
|
|
||||||
|
font, err := strife.LoadFont(fontPath, cfg.Editor.Font_Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -91,6 +113,8 @@ func main() {
|
|||||||
switch evt.(type) {
|
switch evt.(type) {
|
||||||
case *strife.CloseEvent:
|
case *strife.CloseEvent:
|
||||||
window.Close()
|
window.Close()
|
||||||
|
default:
|
||||||
|
editor.handleEvent(evt)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -111,10 +135,11 @@ func main() {
|
|||||||
|
|
||||||
icon, err := strife.LoadImage("./res/icons/icon" + size + ".png")
|
icon, err := strife.LoadImage("./res/icons/icon" + size + ".png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Println("Failed to load icon ", err.Error())
|
||||||
|
} else {
|
||||||
|
window.SetIconImage(icon)
|
||||||
|
defer icon.Destroy()
|
||||||
}
|
}
|
||||||
window.SetIconImage(icon)
|
|
||||||
defer icon.Destroy()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.init(&config)
|
editor.init(&config)
|
||||||
|
Loading…
Reference in New Issue
Block a user