diff --git a/README.md b/README.md index 63cf85c..950db63 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # gopad Notepad in Golang and using nMage and ImGUI. + +## Developer Details + +### Hide Console on Windows + +Running the executable on windows opens a terminal as well. To hide that we build with: `go build -ldflags -H=windowsgui .` + +### Program Icon + +`*.syso` files are used by `go build` on Windows to add information to the executable that Windows can read, such as version and icon. +We use `github.com/tc-hib/go-winres` to generate these via the command: `go-winres simply --icon gopad-icon.ico --manifest gui` diff --git a/editor.go b/editor.go index a58ee35..6015fe1 100755 --- a/editor.go +++ b/editor.go @@ -335,7 +335,7 @@ func getCharIndexFromCursor(l *Line, cursorGridX int) int { return -1 } -//TODO: The offset chars must be how many grid cols between cursor col and the nearest non-tab char. +// TODO: The offset chars must be how many grid cols between cursor col and the nearest non-tab char. func getTabs(l *Line, gridPosX int) (tabCount, charsToOffsetBy int) { charIndex := getCharIndexFromCursor(l, gridPosX) diff --git a/go.mod b/go.mod index a33eb96..cad15b0 100755 --- a/go.mod +++ b/go.mod @@ -1,15 +1,15 @@ module github.com/bloeys/gopad -go 1.17 +go 1.18 require ( - github.com/bloeys/nmage v0.0.10 - github.com/inkyblackness/imgui-go/v4 v4.4.0 - github.com/veandco/go-sdl2 v0.4.14 + github.com/bloeys/nmage v0.16.2 + github.com/inkyblackness/imgui-go/v4 v4.6.0 + github.com/veandco/go-sdl2 v0.4.25 ) require ( - github.com/bloeys/assimp-go v0.4.2 // indirect - github.com/bloeys/gglm v0.3.1 // indirect + github.com/bloeys/assimp-go v0.4.4 // indirect + github.com/bloeys/gglm v0.43.0 // indirect github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect ) diff --git a/go.sum b/go.sum index 7e11ded..93abea8 100755 --- a/go.sum +++ b/go.sum @@ -1,22 +1,19 @@ -github.com/bloeys/assimp-go v0.4.2 h1:ArVK74BCFcTO/rCGj2NgZG9xtbjnJdEn5npIeJx1Z04= -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.10 h1:6Ryl3qjEbXxeIL+9BnBxOrGaW9mKObyY/JbRYkR8ogQ= -github.com/bloeys/nmage v0.0.10/go.mod h1:4h2tKtMvk9ab8r/+rem4QonPXEBTho6VWvpCMm0M6iM= +github.com/bloeys/assimp-go v0.4.4 h1:Yn5e/RpE0Oes0YMBy8O7KkwAO4R/RpgrZPJCt08dVIU= +github.com/bloeys/assimp-go v0.4.4/go.mod h1:my3yRxT7CfOztmvi+0svmwbaqw0KFrxaHxncoyaEIP0= +github.com/bloeys/gglm v0.43.0 h1:ZpOghR3PHfpkigTDh+FqxLsF0gN8CD6s/bWoei6LyxI= +github.com/bloeys/gglm v0.43.0/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk= +github.com/bloeys/nmage v0.16.2 h1:fuCaMrGW5ev4sRS0E70bv3Y++C84RMItFTBSq4/+Tfc= +github.com/bloeys/nmage v0.16.2/go.mod h1:Z9pqkadzLYP+HUnV11lsomfxIzcpzLX3Yp5YCqiICUM= 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= github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk= github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= -github.com/inkyblackness/imgui-go/v4 v4.3.0/go.mod h1:g8SAGtOYUP7rYaOB2AsVKCEHmPMDmJKgt4z6d+flhb0= -github.com/inkyblackness/imgui-go/v4 v4.4.0 h1:jY32Xl18aRwTBXaDfyefCmPDxJOtGM8kGfu/kMNJpbE= -github.com/inkyblackness/imgui-go/v4 v4.4.0/go.mod h1:g8SAGtOYUP7rYaOB2AsVKCEHmPMDmJKgt4z6d+flhb0= +github.com/inkyblackness/imgui-go/v4 v4.6.0 h1:ShcnXEYl80+xREGBY9OpGWePA6FfJChY9Varsm+3jjE= +github.com/inkyblackness/imgui-go/v4 v4.6.0/go.mod h1:g8SAGtOYUP7rYaOB2AsVKCEHmPMDmJKgt4z6d+flhb0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/veandco/go-sdl2 v0.4.10/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= -github.com/veandco/go-sdl2 v0.4.14 h1:ShagETHJG8NCWVn9rwfZ9WLIaN4c2maw3gfFH+9DlOg= -github.com/veandco/go-sdl2 v0.4.14/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= +github.com/veandco/go-sdl2 v0.4.25 h1:J5ac3KKOccp/0xGJA1PaNYKPUcZm19IxhDGs8lJofPI= +github.com/veandco/go-sdl2 v0.4.25/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY= diff --git a/main.go b/main.go index dd9f63f..8b82776 100755 --- a/main.go +++ b/main.go @@ -22,7 +22,6 @@ type Gopad struct { Win *engine.Window mainFont imgui.Font ImGUIInfo nmageimgui.ImguiInfo - Quitting bool mainMenuBarHeight float32 sidebarWidthFactor float32 @@ -46,8 +45,6 @@ type Gopad struct { winHeight float32 } -var () - func main() { chdirErr := os.Chdir(filepath.Dir(os.Args[0])) @@ -80,8 +77,23 @@ func main() { newRunes: []rune{}, } + // Init runs within an imgui frame, but imgui frames do NOT allow adding fonts, + // so we do it here + g.LoadFonts() + // engine.SetVSync(true) - engine.Run(&g) + engine.Run(&g, g.Win, g.ImGUIInfo) +} + +func (g *Gopad) LoadFonts() { + + fConfig := imgui.NewFontConfig() + fConfig.SetOversampleH(2) + fConfig.SetOversampleV(2) + + g.mainFont = g.ImGUIInfo.AddFontTTF("./res/fonts/courier-prime.regular.ttf", settings.FontSize, &fConfig, nil) + + fConfig.Delete() } func (g *Gopad) Init() { @@ -89,14 +101,6 @@ func (g *Gopad) Init() { g.Win.SDLWin.SetTitle("Gopad") g.Win.EventCallbacks = append(g.Win.EventCallbacks, g.handleWindowEvents) - //Setup font - fConfig := imgui.NewFontConfig() - defer fConfig.Delete() - - fConfig.SetOversampleH(2) - fConfig.SetOversampleV(2) - g.mainFont = g.ImGUIInfo.AddFontTTF("./res/fonts/courier-prime.regular.ttf", settings.FontSize, &fConfig, nil) - //Sidebar g.CurrDirContents = getDirContents(g.CurrDir) @@ -122,9 +126,8 @@ func (g *Gopad) Init() { } g.activeEditor = len(g.editors) - 1 -} -func (g *Gopad) Start() { + // Prepare editors imgui.PushFont(g.mainFont) for i := 0; i < len(g.editors); i++ { e := &g.editors[i] @@ -150,14 +153,6 @@ func (g *Gopad) handleWindowEvents(event sdl.Event) { } } -func (g *Gopad) FrameStart() { - - if g.editorToClose > -1 { - g.closeEditor(g.editorToClose) - g.editorToClose = -1 - } -} - func (g *Gopad) closeEditor(eIndex int) { g.editors = append(g.editors[:eIndex], g.editors[eIndex+1:]...) @@ -172,7 +167,14 @@ func (g *Gopad) closeEditor(eIndex int) { func (g *Gopad) Update() { if input.IsQuitClicked() { - g.Quitting = true + engine.Quit() + return + } + + // Close editors if needed + if g.editorToClose > -1 { + g.closeEditor(g.editorToClose) + g.editorToClose = -1 } if g.haveErr { @@ -448,19 +450,7 @@ func (g *Gopad) FrameEnd() { g.newRunes = []rune{} } -func (g *Gopad) ShouldRun() bool { - return !g.Quitting -} - -func (g *Gopad) GetWindow() *engine.Window { - return g.Win -} - -func (g *Gopad) GetImGUI() nmageimgui.ImguiInfo { - return g.ImGUIInfo -} - -func (g *Gopad) Deinit() { +func (g *Gopad) DeInit() { g.Win.Destroy() } diff --git a/rsrc_windows_386.syso b/rsrc_windows_386.syso new file mode 100755 index 0000000..a0e4841 Binary files /dev/null and b/rsrc_windows_386.syso differ diff --git a/rsrc_windows_amd64.syso b/rsrc_windows_amd64.syso new file mode 100755 index 0000000..75cae12 Binary files /dev/null and b/rsrc_windows_amd64.syso differ