mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
mobile/ebitenmobileview: Allow Layout without SetGame
This commit is contained in:
parent
dfb89e13e3
commit
c24b43099b
@ -30,9 +30,16 @@ type ViewRectSetter interface {
|
||||
func Layout(viewWidth, viewHeight int, viewRectSetter ViewRectSetter) {
|
||||
theState.m.Lock()
|
||||
defer theState.m.Unlock()
|
||||
layout(viewWidth, viewHeight, viewRectSetter)
|
||||
}
|
||||
|
||||
func layout(viewWidth, viewHeight int, viewRectSetter ViewRectSetter) {
|
||||
if theState.game == nil {
|
||||
panic("ebitenmobileview: SetGame must be called before Layout")
|
||||
// It is fine to override the existing function since only the last layout result matters.
|
||||
theState.delayedLayout = func() {
|
||||
layout(viewWidth, viewHeight, viewRectSetter)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
w, h := theState.game.Layout(int(viewWidth), int(viewHeight))
|
||||
|
@ -34,6 +34,8 @@ type state struct {
|
||||
|
||||
running bool
|
||||
|
||||
delayedLayout func()
|
||||
|
||||
// m is a mutex required for each function.
|
||||
// For example, on Android, Update can be called from a different thread:
|
||||
// https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer
|
||||
@ -45,4 +47,9 @@ func SetGame(game game) {
|
||||
defer theState.m.Unlock()
|
||||
|
||||
theState.game = game
|
||||
|
||||
if theState.delayedLayout != nil {
|
||||
theState.delayedLayout()
|
||||
theState.delayedLayout = nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user