uidriver/js: Force to update the screen when resizing

Updates #1204
This commit is contained in:
Hajime Hoshi 2021-01-18 01:17:55 +09:00
parent 34695dc845
commit a0a8d41ff6
3 changed files with 33 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import (
type UIContext interface { type UIContext interface {
Update() error Update() error
ForceUpdate() error
Layout(outsideWidth, outsideHeight float64) Layout(outsideWidth, outsideHeight float64)
// AdjustPosition can be called from a different goroutine from Update's or Layout's. // AdjustPosition can be called from a different goroutine from Update's or Layout's.

View File

@ -184,12 +184,21 @@ func (u *UserInterface) update() error {
return nil return nil
} }
hooks.ResumeAudio() hooks.ResumeAudio()
return u.updateImpl(false)
}
func (u *UserInterface) updateImpl(force bool) error {
u.input.updateGamepads() u.input.updateGamepads()
u.input.updateForGo2Cpp() u.input.updateForGo2Cpp()
u.updateSize() u.updateSize()
if err := u.context.Update(); err != nil { if force {
return err if err := u.context.ForceUpdate(); err != nil {
return err
}
} else {
if err := u.context.Update(); err != nil {
return err
}
} }
return nil return nil
} }
@ -327,6 +336,9 @@ func init() {
func setWindowEventHandlers(v js.Value) { func setWindowEventHandlers(v js.Value) {
v.Call("addEventListener", "resize", js.FuncOf(func(this js.Value, args []js.Value) interface{} { v.Call("addEventListener", "resize", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
theUI.updateScreenSize() theUI.updateScreenSize()
if err := theUI.updateImpl(true); err != nil {
panic(err)
}
return nil return nil
})) }))

View File

@ -145,7 +145,7 @@ func (c *uiContext) Update() error {
if err := buffered.BeginFrame(); err != nil { if err := buffered.BeginFrame(); err != nil {
return err return err
} }
if err := c.update(); err != nil { if err := c.update(clock.Update(MaxTPS())); err != nil {
return err return err
} }
if err := buffered.EndFrame(); err != nil { if err := buffered.EndFrame(); err != nil {
@ -154,10 +154,24 @@ func (c *uiContext) Update() error {
return nil return nil
} }
func (c *uiContext) update() error { func (c *uiContext) ForceUpdate() error {
c.updateOffscreen() if err, ok := c.err.Load().(error); ok && err != nil {
return err
}
if err := buffered.BeginFrame(); err != nil {
return err
}
if err := c.update(1); err != nil {
return err
}
if err := buffered.EndFrame(); err != nil {
return err
}
return nil
}
updateCount := clock.Update(MaxTPS()) func (c *uiContext) update(updateCount int) error {
c.updateOffscreen()
// Ensure that Update is called once before Draw so that Update can be used for initialization. // Ensure that Update is called once before Draw so that Update can be used for initialization.
if !c.updateCalled && updateCount == 0 { if !c.updateCalled && updateCount == 0 {