ui: SetScreenSize/Scale no longer returns error

This commit is contained in:
Hajime Hoshi 2017-03-03 10:58:29 +09:00
parent b6b61fc003
commit e11bc62059
4 changed files with 16 additions and 20 deletions

View File

@ -120,30 +120,30 @@ func (u *userInterface) runOnMainThread(f func() error) error {
return err return err
} }
func SetScreenSize(width, height int) (bool, error) { func SetScreenSize(width, height int) bool {
u := currentUI u := currentUI
if !u.isRunning() { if !u.isRunning() {
return false, errors.New("ui: Run is not called yet") panic("ui: Run is not called yet")
} }
r := false r := false
_ = u.runOnMainThread(func() error { _ = u.runOnMainThread(func() error {
u.setScreenSize(width, height, u.scale) u.setScreenSize(width, height, u.scale)
return nil return nil
}) })
return r, nil return r
} }
func SetScreenScale(scale float64) (bool, error) { func SetScreenScale(scale float64) bool {
u := currentUI u := currentUI
if !u.isRunning() { if !u.isRunning() {
return false, errors.New("ui: Run is not called yet") panic("ui: Run is not called yet")
} }
r := false r := false
_ = u.runOnMainThread(func() error { _ = u.runOnMainThread(func() error {
u.setScreenSize(u.width, u.height, scale) u.setScreenSize(u.width, u.height, scale)
return nil return nil
}) })
return r, nil return r
} }
func ScreenScale() float64 { func ScreenScale() float64 {

View File

@ -43,13 +43,13 @@ func shown() bool {
return !js.Global.Get("document").Get("hidden").Bool() return !js.Global.Get("document").Get("hidden").Bool()
} }
func SetScreenSize(width, height int) (bool, error) { func SetScreenSize(width, height int) bool {
return currentUI.setScreenSize(width, height, currentUI.scale), nil return currentUI.setScreenSize(width, height, currentUI.scale)
} }
func SetScreenScale(scale float64) (bool, error) { func SetScreenScale(scale float64) bool {
width, height := currentUI.size() width, height := currentUI.size()
return currentUI.setScreenSize(width, height, scale), nil return currentUI.setScreenSize(width, height, scale)
} }
func ScreenScale() float64 { func ScreenScale() float64 {

View File

@ -98,14 +98,14 @@ func (u *userInterface) update(g GraphicsContext) error {
return nil return nil
} }
func SetScreenSize(width, height int) (bool, error) { func SetScreenSize(width, height int) bool {
// TODO: Implement // TODO: Implement
return false, nil return false
} }
func SetScreenScale(scale float64) (bool, error) { func SetScreenScale(scale float64) bool {
// TODO: Implement // TODO: Implement
return false, nil return false
} }
func ScreenScale() float64 { func ScreenScale() float64 {

8
run.go
View File

@ -119,9 +119,7 @@ func SetScreenSize(width, height int) {
if width <= 0 || height <= 0 { if width <= 0 || height <= 0 {
panic("ebiten: width and height must be positive") panic("ebiten: width and height must be positive")
} }
if _, err := ui.SetScreenSize(width, height); err != nil { ui.SetScreenSize(width, height)
panic(err)
}
} }
// SetScreenScale changes the scale of the screen. // SetScreenScale changes the scale of the screen.
@ -131,9 +129,7 @@ func SetScreenScale(scale float64) {
if scale <= 0 { if scale <= 0 {
panic("ebiten: scale must be positive") panic("ebiten: scale must be positive")
} }
if _, err := ui.SetScreenScale(scale); err != nil { ui.SetScreenScale(scale)
panic(err)
}
} }
// ScreenScale returns the current screen scale. // ScreenScale returns the current screen scale.