mirror of
https://github.com/bloeys/gopad.git
synced 2025-12-29 06:58:21 +00:00
New font and basic ui
This commit is contained in:
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/bloeys/gopad
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224025919-577e6250a8e5
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224035035-36ac96d64163
|
||||
github.com/inkyblackness/imgui-go/v4 v4.3.0
|
||||
github.com/veandco/go-sdl2 v0.4.14
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@ -1,8 +1,8 @@
|
||||
github.com/bloeys/assimp-go v0.4.2/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0=
|
||||
github.com/bloeys/gglm v0.3.1 h1:Sy9upW7SBsBfDXrSmEhid3aQ+7J7itej+upwcxOnPMQ=
|
||||
github.com/bloeys/gglm v0.3.1/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk=
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224025919-577e6250a8e5 h1:stKgJ7DAhmmYy+meP0j7vyjmlfgrAO7jcz6+BwZAVbg=
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224025919-577e6250a8e5/go.mod h1:4h2tKtMvk9ab8r/+rem4QonPXEBTho6VWvpCMm0M6iM=
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224035035-36ac96d64163 h1:nX0RshsywmSpkK1D2uHrmyUFMbnCDrPYSm5xIYYq8/Y=
|
||||
github.com/bloeys/nmage v0.0.7-0.20220224035035-36ac96d64163/go.mod h1:4h2tKtMvk9ab8r/+rem4QonPXEBTho6VWvpCMm0M6iM=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-gl/gl v0.0.0-20211025173605-bda47ffaa784/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
|
||||
|
||||
21
main.go
21
main.go
@ -26,7 +26,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
window, err := engine.CreateOpenGLWindowCentered("nMage", 1280, 720, engine.WindowFlags_RESIZABLE)
|
||||
window, err := engine.CreateOpenGLWindowCentered("nMage", 1280, 720, engine.WindowFlags_RESIZABLE|engine.WindowFlags_ALLOW_HIGHDPI)
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to create window. Err: ", err)
|
||||
}
|
||||
@ -35,14 +35,24 @@ func main() {
|
||||
g := Gopad{
|
||||
Win: window,
|
||||
ImGUIInfo: nmageimgui.NewImGUI(),
|
||||
buffer: make([]rune, 0, 10000),
|
||||
}
|
||||
|
||||
engine.Run(&g)
|
||||
}
|
||||
|
||||
func (g *Gopad) Init() {
|
||||
|
||||
g.Win.EventCallbacks = append(g.Win.EventCallbacks, g.handleWindowEvents)
|
||||
g.mainFont = g.ImGUIInfo.AddFontTTF("./res/fonts/courier-new.ttf", 24)
|
||||
|
||||
var fontSize float32 = 16
|
||||
|
||||
fConfig := imgui.NewFontConfig()
|
||||
defer fConfig.Delete()
|
||||
|
||||
fConfig.SetOversampleH(2)
|
||||
fConfig.SetOversampleV(2)
|
||||
g.mainFont = g.ImGUIInfo.AddFontTTF("./res/fonts/courier-prime.regular.ttf", fontSize, &fConfig, nil)
|
||||
}
|
||||
|
||||
func (g *Gopad) handleWindowEvents(event sdl.Event) {
|
||||
@ -81,17 +91,16 @@ func (g *Gopad) Update() {
|
||||
if input.KeyClicked(sdl.K_RETURN) || input.KeyClicked(sdl.K_RETURN2) {
|
||||
g.buffer = append(g.buffer, rune('\n'))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (g *Gopad) Render() {
|
||||
|
||||
open := true
|
||||
w, h := g.Win.SDLWin.GetSize()
|
||||
sidebarSize := float32(w) * 0.25
|
||||
sidebarSize := float32(w) * 0.10
|
||||
|
||||
//Global imgui settings
|
||||
imgui.PushStyleColor(imgui.StyleColorText, imgui.Vec4{X: 1, Y: 0, Z: 1, W: 1})
|
||||
imgui.PushStyleColor(imgui.StyleColorText, imgui.Vec4{X: 1, Y: 1, Z: 1, W: 1})
|
||||
imgui.PushFont(g.mainFont)
|
||||
|
||||
//Sidebar
|
||||
@ -104,7 +113,7 @@ func (g *Gopad) Render() {
|
||||
imgui.SetNextWindowPos(imgui.Vec2{X: sidebarSize, Y: 0})
|
||||
imgui.SetNextWindowSize(imgui.Vec2{X: float32(w) - sidebarSize, Y: float32(h)})
|
||||
imgui.BeginV("editor", &open, imgui.WindowFlagsNoCollapse|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoMove)
|
||||
imgui.Text(string(g.buffer))
|
||||
imgui.Text(string(g.buffer) + "|")
|
||||
imgui.End()
|
||||
|
||||
imgui.PopFont()
|
||||
|
||||
Binary file not shown.
BIN
res/fonts/courier-prime.regular.ttf
Executable file
BIN
res/fonts/courier-prime.regular.ttf
Executable file
Binary file not shown.
Reference in New Issue
Block a user