ui: Panic on MaximizeWindow when the window is not resizable

On Windows, the window could be maximized even when the window was
not resizable. This behavior is confusing. Forbid it so that the
behavior will be clearer.
This commit is contained in:
Hajime Hoshi 2020-03-28 22:00:40 +09:00
parent 3e244d7a7c
commit 4fe5acd711
3 changed files with 10 additions and 3 deletions

View File

@ -251,7 +251,7 @@ func (g *game) Update(screen *ebiten.Image) error {
ebiten.SetWindowDecorated(decorated)
ebiten.SetWindowPosition(positionX, positionY)
ebiten.SetWindowFloating(floating)
if maximize {
if maximize && ebiten.IsWindowResizable() {
ebiten.MaximizeWindow()
}
if minimize {
@ -294,7 +294,7 @@ func (g *game) Draw(screen *ebiten.Image) {
}
var lines []string
if !ebiten.IsWindowMaximized() {
if !ebiten.IsWindowMaximized() && ebiten.IsWindowResizable() {
lines = append(lines, "[M] Maximize the window")
}
if !ebiten.IsWindowMinimized() {
@ -403,6 +403,7 @@ func main() {
ebiten.SetWindowFloating(true)
}
if *flagMaximize {
ebiten.SetWindowResizable(true)
ebiten.MaximizeWindow()
}
if *flagAutoAdjusting {

View File

@ -129,6 +129,9 @@ func (w *window) IsMaximized() bool {
}
func (w *window) Maximize() {
if !w.IsResizable() {
panic("glfw: a window to maximize must be resizable")
}
if !w.ui.isRunning() {
w.ui.setInitWindowMaximized(true)
return

View File

@ -262,12 +262,15 @@ func SetWindowFloating(float bool) {
// MaximizeWindow maximizes the window.
//
// On some environments like macOS, MaximizeWindow requres that the window is resizable.
// MaximizeWindow panics when the window is not resizable.
//
// MaximizeWindow does nothing on browsers or mobiles.
//
// MaximizeWindow is concurrent-safe.
func MaximizeWindow() {
if !IsWindowResizable() {
panic("ebiten: a window to maximize must be resizable")
}
if w := uiDriver().Window(); w != nil {
w.Maximize()
}