mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +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) {
|
func Layout(viewWidth, viewHeight int, viewRectSetter ViewRectSetter) {
|
||||||
theState.m.Lock()
|
theState.m.Lock()
|
||||||
defer theState.m.Unlock()
|
defer theState.m.Unlock()
|
||||||
|
layout(viewWidth, viewHeight, viewRectSetter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func layout(viewWidth, viewHeight int, viewRectSetter ViewRectSetter) {
|
||||||
if theState.game == nil {
|
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))
|
w, h := theState.game.Layout(int(viewWidth), int(viewHeight))
|
||||||
|
@ -34,6 +34,8 @@ type state struct {
|
|||||||
|
|
||||||
running bool
|
running bool
|
||||||
|
|
||||||
|
delayedLayout func()
|
||||||
|
|
||||||
// m is a mutex required for each function.
|
// m is a mutex required for each function.
|
||||||
// For example, on Android, Update can be called from a different thread:
|
// For example, on Android, Update can be called from a different thread:
|
||||||
// https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer
|
// https://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer
|
||||||
@ -45,4 +47,9 @@ func SetGame(game game) {
|
|||||||
defer theState.m.Unlock()
|
defer theState.m.Unlock()
|
||||||
|
|
||||||
theState.game = game
|
theState.game = game
|
||||||
|
|
||||||
|
if theState.delayedLayout != nil {
|
||||||
|
theState.delayedLayout()
|
||||||
|
theState.delayedLayout = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user