internal/ui: bug fix: SetWindowIcon(nil) didn't reset the window icon

Closes #2796
This commit is contained in:
Hajime Hoshi 2023-09-30 02:46:11 +09:00
parent 13dfb28a98
commit dce18d7c23
3 changed files with 15 additions and 2 deletions

View File

@ -307,6 +307,9 @@ func (g *game) Update() error {
if inpututil.IsKeyJustPressed(ebiten.KeyI) {
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
}
if inpututil.IsKeyJustPressed(ebiten.KeyJ) {
ebiten.SetWindowIcon(nil)
}
ebiten.SetWindowMousePassthrough(mousePassthrough)
@ -358,6 +361,7 @@ func (g *game) Draw(screen *ebiten.Image) {
[U] Switch the runnable-on-unfocused state
[C] Switch the cursor mode (visible, hidden, or captured)
[I] Change the window icon (only for desktops)
[J] Reset the window icon (only for desktops)
[V] Switch the vsync
[T] Switch TPS (ticks per second)
[D] Switch the window decoration (only for desktops)

View File

@ -1559,6 +1559,9 @@ func (w *Window) platformSetWindowIcon(images []*Image) error {
if len(images) > 0 {
w.platform.bigIcon = bigIcon
w.platform.smallIcon = smallIcon
} else {
w.platform.bigIcon = 0
w.platform.smallIcon = 0
}
return nil
}

View File

@ -1204,11 +1204,17 @@ func (u *userInterfaceImpl) updateIconIfNeeded() error {
}
imgs := u.getAndResetIconImages()
if len(imgs) == 0 {
// A 0-size slice and nil are distinguished here.
// A 0-size slice means a user indicates to reset the icon.
// On the other hand, nil means a user didn't update the icon state.
if imgs == nil {
return nil
}
newImgs := make([]image.Image, len(imgs))
var newImgs []image.Image
if len(imgs) > 0 {
newImgs = make([]image.Image, len(imgs))
}
for i, img := range imgs {
// TODO: If img is not *ebiten.Image, this converting is not necessary.
// However, this package cannot refer *ebiten.Image due to the package