Skip to content

Commit

Permalink
app: consider main viewport's position when creating windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Nov 27, 2024
1 parent 1f44106 commit 0f64378
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ type App struct {

TextureLoader common.TextureLoader

showUsage bool
showUsage bool
justStarted bool
}

// Create creates new app instance
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions pkg/window/window.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package window

import (
"github.com/AllenDang/cimgui-go/imgui"
"github.com/AllenDang/giu"
"github.com/gucio321/HellSpawner/pkg/app/state"
)
Expand Down Expand Up @@ -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)
}

0 comments on commit 0f64378

Please sign in to comment.