uidriver/mobile: Refactoring

This commit is contained in:
Hajime Hoshi 2020-08-29 02:43:04 +09:00
parent b76c34336d
commit 12878571f6

View File

@ -309,7 +309,7 @@ func (u *UserInterface) run(context driver.UIContext, mainloop bool) (err error)
} }
// Force to set the screen size // Force to set the screen size
u.updateSize() u.layoutIfNeeded()
for { for {
if err := u.update(); err != nil { if err := u.update(); err != nil {
return err return err
@ -317,7 +317,8 @@ func (u *UserInterface) run(context driver.UIContext, mainloop bool) (err error)
} }
} }
func (u *UserInterface) updateSize() { // layoutIfNeeded must be called on the same goroutine as update().
func (u *UserInterface) layoutIfNeeded() {
var outsideWidth, outsideHeight float64 var outsideWidth, outsideHeight float64
u.m.Lock() u.m.Lock()
@ -380,10 +381,11 @@ func (u *UserInterface) setGBuildSize(widthPx, heightPx int) {
u.gbuildWidthPx = widthPx u.gbuildWidthPx = widthPx
u.gbuildHeightPx = heightPx u.gbuildHeightPx = heightPx
u.sizeChanged = true u.sizeChanged = true
u.m.Unlock()
u.once.Do(func() { u.once.Do(func() {
close(u.setGBuildSizeCh) close(u.setGBuildSizeCh)
}) })
u.m.Unlock()
} }
func (u *UserInterface) adjustPosition(x, y int) (int, int) { func (u *UserInterface) adjustPosition(x, y int) (int, int) {
@ -440,7 +442,7 @@ func (u *UserInterface) IsScreenTransparent() bool {
} }
func (u *UserInterface) ResetForFrame() { func (u *UserInterface) ResetForFrame() {
u.updateSize() u.layoutIfNeeded()
u.input.resetForFrame() u.input.resetForFrame()
} }