mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 11:10:37 +03:00
can now open multiple files from cmd line
This commit is contained in:
parent
69bd7535b9
commit
aa8bf6901f
@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type Component interface {
|
||||
SetPosition(x, y int)
|
||||
Translate(x, y int)
|
||||
Resize(w, h int)
|
||||
|
||||
@ -27,6 +28,14 @@ type BaseComponent struct {
|
||||
inputHandler *InputHandler
|
||||
}
|
||||
|
||||
func (b *BaseComponent) SetPosition(x, y int) {
|
||||
b.x = x
|
||||
b.y = y
|
||||
for _, c := range b.components {
|
||||
c.SetPosition(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BaseComponent) Translate(x, y int) {
|
||||
b.x += x
|
||||
b.y += y
|
||||
@ -38,6 +47,9 @@ func (b *BaseComponent) Translate(x, y int) {
|
||||
func (b *BaseComponent) Resize(w, h int) {
|
||||
b.w = w
|
||||
b.h = h
|
||||
for _, c := range b.components {
|
||||
c.Resize(w, h)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BaseComponent) GetComponents() []Component {
|
||||
|
26
gui/view.go
26
gui/view.go
@ -1,8 +1,6 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/felixangell/phi-editor/cfg"
|
||||
"github.com/felixangell/strife"
|
||||
)
|
||||
@ -20,7 +18,6 @@ func NewView(width, height int, conf *cfg.TomlConfig) *View {
|
||||
}
|
||||
|
||||
func (n *View) OnInit() {
|
||||
n.addBuffer()
|
||||
}
|
||||
|
||||
func (n *View) OnUpdate() bool {
|
||||
@ -31,21 +28,19 @@ func (n *View) OnRender(ctx *strife.Renderer) {}
|
||||
|
||||
func (n *View) OnDispose() {}
|
||||
|
||||
func (n *View) addBuffer() {
|
||||
func (n *View) AddBuffer() *Buffer {
|
||||
c := NewBuffer(n.conf)
|
||||
|
||||
args := os.Args
|
||||
if len(args) > 1 {
|
||||
c.OpenFile(args[1])
|
||||
} else {
|
||||
c.OpenFile(cfg.CONFIG_FULL_PATH)
|
||||
}
|
||||
|
||||
// work out the size of the buffer and set it
|
||||
// note that we +1 the components because
|
||||
// we haven't yet added the panel
|
||||
bufferWidth := n.w / (len(n.components) + 1)
|
||||
c.Resize(bufferWidth, n.h)
|
||||
var bufferWidth int
|
||||
numComponents := len(n.components) + 1
|
||||
if numComponents > 0 {
|
||||
bufferWidth = int(float32(n.w) / float32(numComponents))
|
||||
} else {
|
||||
bufferWidth = n.w
|
||||
}
|
||||
|
||||
// setup and add the panel for the buffer
|
||||
panel := NewPanel(n.inputHandler)
|
||||
@ -55,6 +50,9 @@ func (n *View) addBuffer() {
|
||||
|
||||
// translate all the components accordingly.
|
||||
for i, p := range n.components {
|
||||
p.Translate(bufferWidth*i, 0)
|
||||
p.Resize(bufferWidth, n.h)
|
||||
p.SetPosition(bufferWidth*i, 0)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
12
main.go
12
main.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@ -22,7 +23,16 @@ type PhiEditor struct {
|
||||
}
|
||||
|
||||
func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
||||
n.AddComponent(gui.NewView(1280/2, 720, cfg))
|
||||
mainView := gui.NewView(1280, 720, cfg)
|
||||
|
||||
args := os.Args
|
||||
if len(args) > 1 {
|
||||
for _, arg := range args[1:] {
|
||||
mainView.AddBuffer().OpenFile(arg)
|
||||
}
|
||||
}
|
||||
|
||||
n.AddComponent(mainView)
|
||||
|
||||
font, err := strife.LoadFont("./res/firacode.ttf", 20)
|
||||
if err != nil {
|
||||
|
BIN
phi-editor
BIN
phi-editor
Binary file not shown.
Loading…
Reference in New Issue
Block a user