diff --git a/pkg/app/app.go b/pkg/app/app.go index 533608c7..e96dc064 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -95,7 +95,8 @@ type App struct { TextureLoader common.TextureLoader - showUsage bool + showUsage bool + justStarted bool } // Create creates new app instance @@ -106,6 +107,7 @@ func Create() (*App, error) { editorConstructors: make(map[hsfiletypes.FileType]editorConstructor), TextureLoader: common.NewTextureLoader(), abyssWrapper: abysswrapper.Create(), + justStarted: true, } if shouldTerminate := result.parseArgs(); shouldTerminate { @@ -146,19 +148,21 @@ func (a *App) Run() (err error) { return err } - if a.config.OpenMostRecentOnStartup && len(a.config.RecentProjects) > 0 { - err = a.loadProjectFromFile(a.config.RecentProjects[0]) - if err != nil { - return err - } - } - a.masterWindow.Run(a.render) return nil } func (a *App) render() { + // unfortunately can't do that in Run as this requires imgui.MainViewport + if a.justStarted && a.config.OpenMostRecentOnStartup && len(a.config.RecentProjects) > 0 { + err := a.loadProjectFromFile(a.config.RecentProjects[0]) + a.justStarted = false + if err != nil { + logErr("could not load most recent project on startup: %v", err) + } + } + a.TextureLoader.StopLoadingTextures() a.renderMainMenuBar() diff --git a/pkg/window/window.go b/pkg/window/window.go index 0a32212d..7f31b974 100644 --- a/pkg/window/window.go +++ b/pkg/window/window.go @@ -1,6 +1,7 @@ package window import ( + "github.com/AllenDang/cimgui-go/imgui" "github.com/AllenDang/giu" "github.com/gucio321/HellSpawner/pkg/app/state" ) @@ -71,3 +72,9 @@ func (t *Window) SetVisible(visible bool) { func (t *Window) Cleanup() { t.Visible = false } + +func (t *Window) Pos(x, y float32) *giu.WindowWidget { + // normalize this by main viewports pos + pos0 := imgui.MainViewport().Pos() + return t.WindowWidget.Pos(x+pos0.X, y+pos0.Y) +}