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
}
func SetScreenSize(width, height int) (bool, error) {
func SetScreenSize(width, height int) bool {
u := currentUI
if !u.isRunning() {
return false, errors.New("ui: Run is not called yet")
panic("ui: Run is not called yet")
}
r := false
_ = u.runOnMainThread(func() error {
u.setScreenSize(width, height, u.scale)
return nil
})
return r, nil
return r
}
func SetScreenScale(scale float64) (bool, error) {
func SetScreenScale(scale float64) bool {
u := currentUI
if !u.isRunning() {
return false, errors.New("ui: Run is not called yet")
panic("ui: Run is not called yet")
}
r := false
_ = u.runOnMainThread(func() error {
u.setScreenSize(u.width, u.height, scale)
return nil
})
return r, nil
return r
}
func ScreenScale() float64 {

View File

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

View File

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

8
run.go
View File

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