internal/ui: refactoring: remove sizeChanged

It is safe to call Layout every frame.
This commit is contained in:
Hajime Hoshi 2022-02-14 02:17:45 +09:00
parent fcd4453e4f
commit e2f0878a4c

View File

@ -58,7 +58,6 @@ var (
// Give a default outside size so that the game can start without initializing them.
outsideWidth: 640,
outsideHeight: 480,
sizeChanged: true,
}
)
@ -99,7 +98,6 @@ type UserInterface struct {
outsideWidth float64
outsideHeight float64
sizeChanged bool
foreground int32
errCh chan error
@ -273,10 +271,6 @@ func (u *UserInterface) run(game Game, mainloop bool) (err error) {
}
}()
u.m.Lock()
u.sizeChanged = true
u.m.Unlock()
u.context = newContextImpl(game)
if mainloop {
@ -306,8 +300,6 @@ func (u *UserInterface) layoutIfNeeded() {
var outsideWidth, outsideHeight float64
u.m.RLock()
sizeChanged := u.sizeChanged
if sizeChanged {
if u.gbuildWidthPx == 0 || u.gbuildHeightPx == 0 {
outsideWidth = u.outsideWidth
outsideHeight = u.outsideHeight
@ -317,13 +309,9 @@ func (u *UserInterface) layoutIfNeeded() {
outsideWidth = float64(u.gbuildWidthPx) / d
outsideHeight = float64(u.gbuildHeightPx) / d
}
}
u.sizeChanged = false
u.m.RUnlock()
if sizeChanged {
u.context.layout(outsideWidth, outsideHeight)
}
}
func (u *UserInterface) update() error {
@ -353,7 +341,6 @@ func (u *UserInterface) SetOutsideSize(outsideWidth, outsideHeight float64) {
if u.outsideWidth != outsideWidth || u.outsideHeight != outsideHeight {
u.outsideWidth = outsideWidth
u.outsideHeight = outsideHeight
u.sizeChanged = true
}
u.m.Unlock()
}
@ -362,7 +349,6 @@ func (u *UserInterface) setGBuildSize(widthPx, heightPx int) {
u.m.Lock()
u.gbuildWidthPx = widthPx
u.gbuildHeightPx = heightPx
u.sizeChanged = true
u.m.Unlock()
u.once.Do(func() {