Update to nmage v0.23.1

This commit is contained in:
bloeys
2024-04-20 12:07:05 +04:00
parent 967c9815a0
commit 5b15017fc6
6 changed files with 50 additions and 53 deletions

View File

@ -5,8 +5,8 @@ import (
"os"
"path/filepath"
imgui "github.com/AllenDang/cimgui-go"
"github.com/bloeys/gopad/settings"
"github.com/inkyblackness/imgui-go/v4"
)
const (
@ -87,7 +87,7 @@ func (e *Editor) RefreshFontSettings() {
//
//That's why instead of getting width of one char, we get the average width from the width of a sentence, which helps us position
//cursors properly for now
e.CharWidth = imgui.CalcTextSize("abcdefghijklmnopqrstuvwxyz", false, 1000).X / 26
e.CharWidth = imgui.CalcTextSizeV("abcdefghijklmnopqrstuvwxyz", false, 1000).X / 26
}
func (e *Editor) RoundToGridX(x float32) float32 {
@ -105,11 +105,11 @@ func (e *Editor) UpdateAndDraw(drawStartPos, winSize *imgui.Vec2, newRunes []run
imgui.SetNextWindowSize(*winSize)
imgui.BeginV("editorText", nil, imgui.WindowFlagsNoCollapse|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoMove)
imgui.PushStyleColor(imgui.StyleColorFrameBg, settings.EditorBgColor)
imgui.PushStyleColor(imgui.StyleColorTextSelectedBg, settings.TextSelectionColor)
imgui.PushStyleColorVec4(imgui.ColFrameBg, settings.EditorBgColor)
imgui.PushStyleColorVec4(imgui.ColTextSelectedBg, settings.TextSelectionColor)
imgui.SetNextItemWidth(winSize.X)
if imgui.InputTextMultilineV("", &e.FileContents, imgui.Vec2{X: winSize.X - winSize.X*0.02, Y: winSize.Y - winSize.Y*0.02}, imgui.InputTextFlagsNone, nil) {
if imgui.InputTextMultiline("", &e.FileContents, imgui.Vec2{X: winSize.X - winSize.X*0.02, Y: winSize.Y - winSize.Y*0.02}, imgui.InputTextFlagsNone, nil) {
e.IsModified = true
}
@ -131,19 +131,19 @@ func (e *Editor) UpdateAndDraw(drawStartPos, winSize *imgui.Vec2, newRunes []run
// posInfo := e.getPositions(&paddedDrawStartPos)
// e.Insert(&posInfo, newRunes)
// if input.KeyClicked(sdl.K_LEFT) {
// if input.KeyClickedCaptured(sdl.K_LEFT) {
// e.MoveMouseXByChars(-1, &posInfo)
// } else if input.KeyClicked(sdl.K_RIGHT) {
// } else if input.KeyClickedCaptured(sdl.K_RIGHT) {
// e.MoveMouseXByChars(1, &posInfo)
// }
// if input.KeyClicked(sdl.K_UP) {
// if input.KeyClickedCaptured(sdl.K_UP) {
// e.MoveMouseYByLines(-1, &posInfo)
// } else if input.KeyClicked(sdl.K_DOWN) {
// } else if input.KeyClickedCaptured(sdl.K_DOWN) {
// e.MoveMouseYByLines(1, &posInfo)
// }
// if input.KeyClicked(sdl.K_BACKSPACE) {
// if input.KeyClickedCaptured(sdl.K_BACKSPACE) {
// e.Delete(&posInfo, 1)
// }
@ -496,9 +496,9 @@ func roundF32(x float32) float32 {
return float32(math.Round(float64(x)))
}
func NewScratchEditor() *Editor {
func NewScratchEditor() Editor {
e := &Editor{
e := Editor{
FileName: "**scratch**",
LinesHead: NewLineNode(),
}
@ -506,14 +506,14 @@ func NewScratchEditor() *Editor {
return e
}
func NewEditor(fPath string) *Editor {
func NewEditor(fPath string) Editor {
b, err := os.ReadFile(fPath)
if err != nil {
panic(err)
}
e := &Editor{
e := Editor{
FileName: filepath.Base(fPath),
FilePath: fPath,
FileContents: string(b),

8
go.mod
View File

@ -1,11 +1,11 @@
module github.com/bloeys/gopad
go 1.18
go 1.22
require (
github.com/bloeys/nmage v0.16.2
github.com/inkyblackness/imgui-go/v4 v4.6.0
github.com/veandco/go-sdl2 v0.4.25
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2
github.com/bloeys/nmage v0.23.1
github.com/veandco/go-sdl2 v0.4.35
)
require (

19
go.sum
View File

@ -1,19 +1,12 @@
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2 h1:3HA/5qD8Rimxz/y1sLyVaM7ws1dzjXzMt4hOBiwHggo=
github.com/AllenDang/cimgui-go v0.0.0-20230720025235-f2ff398a66b2/go.mod h1:iNfbIyOBN8k3XScMxULbrwYbPsXEAUD0Jb6UwrspQb8=
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/bloeys/nmage v0.23.1 h1:+DxcvM1KcDqiij6B50wchHa2h9XHkfIrIjEk87wj5zw=
github.com/bloeys/nmage v0.23.1/go.mod h1:0hQAs1tCB/EOVwoac0zl+vsANkqGP9EOKc8cM/+3Now=
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.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.25 h1:J5ac3KKOccp/0xGJA1PaNYKPUcZm19IxhDGs8lJofPI=
github.com/veandco/go-sdl2 v0.4.25/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=
github.com/veandco/go-sdl2 v0.4.35 h1:NohzsfageDWGtCd9nf7Pc3sokMK/MOK+UA2QMJARWzQ=
github.com/veandco/go-sdl2 v0.4.35/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=

42
main.go
View File

@ -6,13 +6,13 @@ import (
"os"
"path/filepath"
imgui "github.com/AllenDang/cimgui-go"
"github.com/bloeys/gopad/settings"
"github.com/bloeys/nmage/engine"
"github.com/bloeys/nmage/input"
"github.com/bloeys/nmage/logging"
"github.com/bloeys/nmage/renderer/rend3dgl"
nmageimgui "github.com/bloeys/nmage/ui/imgui"
"github.com/inkyblackness/imgui-go/v4"
"github.com/veandco/go-sdl2/sdl"
)
@ -68,11 +68,15 @@ func main() {
}
g := Gopad{
Win: window,
ImGUIInfo: nmageimgui.NewImGUI(),
CurrDir: dir,
editors: []Editor{*NewScratchEditor()},
editorToClose: -1,
Win: window,
ImGUIInfo: nmageimgui.NewImGui(""),
CurrDir: dir,
editors: []Editor{NewScratchEditor()},
editorToClose: -1,
// This is to force a focus on the scratch editr on startup
lastActiveEditor: -1,
sidebarWidthFactor: 0.15,
newRunes: []rune{},
}
@ -93,7 +97,7 @@ func (g *Gopad) LoadFonts() {
g.mainFont = g.ImGUIInfo.AddFontTTF("./res/fonts/courier-prime.regular.ttf", settings.FontSize, &fConfig, nil)
fConfig.Delete()
fConfig.Destroy()
}
func (g *Gopad) Init() {
@ -112,7 +116,7 @@ func (g *Gopad) Init() {
//Read os.Args
for i := 1; i < len(os.Args); i++ {
e := *NewEditor(os.Args[i])
e := NewEditor(os.Args[i])
g.editors = append(g.editors, e)
g.activeEditor = len(g.editors) - 1
}
@ -167,17 +171,17 @@ func (g *Gopad) Update() {
g.showErrorPopup()
}
if input.MouseClicked(sdl.BUTTON_LEFT) {
if input.MouseClickedCaptued(sdl.BUTTON_LEFT) {
x, y := input.GetMousePos()
g.getActiveEditor().SetCursorPos(int(x), int(y))
}
if yMove := input.GetMouseWheelYNorm(); yMove != 0 {
if yMove := input.GetMouseWheelYNormCaptured(); yMove != 0 {
g.getActiveEditor().SetStartPos(yMove)
}
//Close editor if needed
if input.KeyDown(sdl.K_LCTRL) && input.KeyClicked(sdl.K_w) {
if input.KeyDownCaptured(sdl.K_LCTRL) && input.KeyClickedCaptured(sdl.K_w) {
g.closeEditor(g.activeEditor)
g.editorToClose = -1
}
@ -189,7 +193,7 @@ func (g *Gopad) Update() {
return
}
if !input.KeyDown(sdl.K_LCTRL) || !input.KeyClicked(sdl.K_s) {
if !input.KeyDownCaptured(sdl.K_LCTRL) || !input.KeyClickedCaptured(sdl.K_s) {
return
}
@ -213,7 +217,7 @@ func (g *Gopad) saveEditor(e *Editor) {
}
func (g *Gopad) triggerError(errMsg string) {
imgui.OpenPopup("err")
imgui.OpenPopupStr("err")
g.haveErr = true
g.errMsg = errMsg
}
@ -256,7 +260,7 @@ func (g *Gopad) drawMenubar() {
if imgui.BeginMenu("File") {
if imgui.MenuItem("Save") {
if imgui.MenuItemBool("Save") {
g.saveEditor(g.getActiveEditor())
}
@ -275,7 +279,7 @@ func (g *Gopad) drawSidebar() {
imgui.SetNextWindowSize(imgui.Vec2{X: g.sidebarWidthPx, Y: g.winHeight - g.mainMenuBarHeight})
imgui.BeginV("sidebar", nil, imgui.WindowFlagsNoCollapse|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoMove)
imgui.PushStyleColor(imgui.StyleColorButton, imgui.Vec4{W: 0})
imgui.PushStyleColorVec4(imgui.ColButton, imgui.Vec4{W: 0})
for i := 0; i < len(g.CurrDirContents); i++ {
c := g.CurrDirContents[i]
@ -306,7 +310,7 @@ func (g *Gopad) drawEditors() {
e := &g.editors[i]
flags := imgui.TabItemFlagsNone
var flags imgui.TabItemFlags = imgui.TabItemFlagsNone
if shouldForceSwitch && g.activeEditor == i {
flags = imgui.TabItemFlagsSetSelected
}
@ -366,7 +370,7 @@ func (g *Gopad) getActiveEditor() *Editor {
func (g *Gopad) getEditor(index int) *Editor {
if len(g.editors) == 0 {
e := *NewScratchEditor()
e := NewScratchEditor()
e.RefreshFontSettings()
g.editors = append(g.editors, e)
g.activeEditor = 0
@ -382,7 +386,7 @@ func (g *Gopad) getEditor(index int) *Editor {
func (g *Gopad) drawDir(dir fs.DirEntry, path string) {
isEnabled := imgui.TreeNodeV(dir.Name(), imgui.TreeNodeFlagsSpanAvailWidth)
isEnabled := imgui.TreeNodeExStrV(dir.Name(), imgui.TreeNodeFlagsSpanAvailWidth)
if !isEnabled {
return
}
@ -426,7 +430,7 @@ func (g *Gopad) handleFileClick(fPath string) {
}
//Read new file and switch to it
e := *NewEditor(fPath)
e := NewEditor(fPath)
e.RefreshFontSettings()
g.editors = append(g.editors, e)
g.activeEditor = len(g.editors) - 1

View File

@ -4,7 +4,7 @@ import (
"os"
"strings"
"github.com/inkyblackness/imgui-go/v4"
imgui "github.com/AllenDang/cimgui-go"
)
func selectFolder(startDir string, winWidth float32, winHeight float32) (path string, done bool) {
@ -17,7 +17,7 @@ func selectFolder(startDir string, winWidth float32, winHeight float32) (path st
}
}
imgui.OpenPopup("selectFolder")
imgui.OpenPopupStr("selectFolder")
imgui.SetNextWindowPos(imgui.Vec2{X: float32(winWidth) * 0.5, Y: float32(winHeight) * 0.5})
shouldEnd := imgui.BeginPopupModalV("selectFolder", nil, imgui.WindowFlagsNoCollapse)

View File

@ -1,6 +1,6 @@
package settings
import "github.com/inkyblackness/imgui-go/v4"
import imgui "github.com/AllenDang/cimgui-go"
var (
FontSize float32 = 16