New font and basic ui

This commit is contained in:
bloeys
2022-02-24 10:27:43 +04:00
parent a6abed0d35
commit 580ec911ef
5 changed files with 18 additions and 9 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/bloeys/gopad
go 1.17 go 1.17
require ( 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/inkyblackness/imgui-go/v4 v4.3.0
github.com/veandco/go-sdl2 v0.4.14 github.com/veandco/go-sdl2 v0.4.14
) )

4
go.sum
View File

@ -1,8 +1,8 @@
github.com/bloeys/assimp-go v0.4.2/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0= 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 h1:Sy9upW7SBsBfDXrSmEhid3aQ+7J7itej+upwcxOnPMQ=
github.com/bloeys/gglm v0.3.1/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk= 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.20220224035035-36ac96d64163 h1:nX0RshsywmSpkK1D2uHrmyUFMbnCDrPYSm5xIYYq8/Y=
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/go.mod h1:4h2tKtMvk9ab8r/+rem4QonPXEBTho6VWvpCMm0M6iM=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 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/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= github.com/go-gl/gl v0.0.0-20211025173605-bda47ffaa784/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=

21
main.go
View File

@ -26,7 +26,7 @@ func main() {
panic(err) 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 { if err != nil {
logging.ErrLog.Fatalln("Failed to create window. Err: ", err) logging.ErrLog.Fatalln("Failed to create window. Err: ", err)
} }
@ -35,14 +35,24 @@ func main() {
g := Gopad{ g := Gopad{
Win: window, Win: window,
ImGUIInfo: nmageimgui.NewImGUI(), ImGUIInfo: nmageimgui.NewImGUI(),
buffer: make([]rune, 0, 10000),
} }
engine.Run(&g) engine.Run(&g)
} }
func (g *Gopad) Init() { func (g *Gopad) Init() {
g.Win.EventCallbacks = append(g.Win.EventCallbacks, g.handleWindowEvents) 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) { 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) { if input.KeyClicked(sdl.K_RETURN) || input.KeyClicked(sdl.K_RETURN2) {
g.buffer = append(g.buffer, rune('\n')) g.buffer = append(g.buffer, rune('\n'))
} }
} }
func (g *Gopad) Render() { func (g *Gopad) Render() {
open := true open := true
w, h := g.Win.SDLWin.GetSize() w, h := g.Win.SDLWin.GetSize()
sidebarSize := float32(w) * 0.25 sidebarSize := float32(w) * 0.10
//Global imgui settings //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) imgui.PushFont(g.mainFont)
//Sidebar //Sidebar
@ -104,7 +113,7 @@ func (g *Gopad) Render() {
imgui.SetNextWindowPos(imgui.Vec2{X: sidebarSize, Y: 0}) imgui.SetNextWindowPos(imgui.Vec2{X: sidebarSize, Y: 0})
imgui.SetNextWindowSize(imgui.Vec2{X: float32(w) - sidebarSize, Y: float32(h)}) imgui.SetNextWindowSize(imgui.Vec2{X: float32(w) - sidebarSize, Y: float32(h)})
imgui.BeginV("editor", &open, imgui.WindowFlagsNoCollapse|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoMove) imgui.BeginV("editor", &open, imgui.WindowFlagsNoCollapse|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoMove)
imgui.Text(string(g.buffer)) imgui.Text(string(g.buffer) + "|")
imgui.End() imgui.End()
imgui.PopFont() imgui.PopFont()

Binary file not shown.

Binary file not shown.