|
14 | 14 | initItemIcon() |
15 | 15 | initItemTextExtra() |
16 | 16 | m.itemPoster.observeField("loadStatus", "onPosterLoadStatusChanged") |
| 17 | + m.itemIcon.observeField("loadStatus", "onIconLoadStatusChanged") |
17 | 18 | initBackdrop() |
18 | 19 | end sub |
19 | 20 |
|
|
361 | 362 | end if |
362 | 363 | else |
363 | 364 | m.backdrop.visible = true |
364 | | - if m.itemIcon.uri <> "" |
365 | | - m.itemIcon.visible = true |
366 | | - end if |
367 | 365 | backdropText = m.top.findNode("backdropText") |
368 | 366 | if isValid(backdropText) |
369 | | - ' reposition backdroptext and itemIcon so they don't overlap |
370 | | - m.itemIcon.translation = [(m.backdrop.width - m.itemIcon.width) / 2, ((m.backdrop.height - m.itemIcon.height) / 2) / 2] |
371 | | - |
372 | | - backdropText.height = 0 |
373 | | - backdropText.translation = [backdropText.translation[0], ((m.backdrop.height - m.itemIcon.height) / 2) + m.itemIcon.height] |
374 | | - fontSizeConstants = m.global.constants.font_sizes |
375 | | - if len(backdropText.text) > 12 |
376 | | - backdropText.font.size = fontSizeConstants.large |
377 | | - else if len(backdropText.text) > 35 |
378 | | - backdropText.font.size = fontSizeConstants.medium |
379 | | - else if len(backdropText.text) > 65 |
380 | | - backdropText.font.size = fontSizeConstants.small |
381 | | - end if |
382 | 367 | backdropText.visible = true |
| 368 | + ' Reset backdrop text to original position when poster fails to load |
| 369 | + resetBackdropTextPosition() |
| 370 | + end if |
| 371 | + end if |
| 372 | +end sub |
| 373 | + |
| 374 | +'Handle icon image load status changes |
| 375 | +sub onIconLoadStatusChanged() |
| 376 | + if m.itemIcon.loadStatus = "ready" and m.itemIcon.uri <> "" |
| 377 | + ' Icon loaded successfully |
| 378 | + m.itemIcon.visible = true |
| 379 | + ' Only rearrange if backdrop is visible (poster didn't load) |
| 380 | + if m.backdrop.visible |
| 381 | + arrangeIconAndBackdropText() |
| 382 | + end if |
| 383 | + else |
| 384 | + ' Icon failed to load or no URI set |
| 385 | + m.itemIcon.visible = false |
| 386 | + ' Reset backdrop text position if backdrop is visible |
| 387 | + if m.backdrop.visible |
| 388 | + resetBackdropTextPosition() |
| 389 | + end if |
| 390 | + end if |
| 391 | +end sub |
| 392 | + |
| 393 | +'Arrange icon and backdrop text when both are visible |
| 394 | +sub arrangeIconAndBackdropText() |
| 395 | + backdropText = m.top.findNode("backdropText") |
| 396 | + if isValid(backdropText) |
| 397 | + ' reposition backdroptext and itemIcon so they don't overlap |
| 398 | + m.itemIcon.translation = [(m.backdrop.width - m.itemIcon.width) / 2, ((m.backdrop.height - m.itemIcon.height) / 2) / 2] |
| 399 | + |
| 400 | + backdropText.height = 0 |
| 401 | + backdropText.translation = [backdropText.translation[0], ((m.backdrop.height - m.itemIcon.height) / 2) + m.itemIcon.height] |
| 402 | + |
| 403 | + ' Set font size based on text length |
| 404 | + fontSizeConstants = m.global.constants.font_sizes |
| 405 | + if len(backdropText.text) > 12 |
| 406 | + backdropText.font.size = fontSizeConstants.large |
| 407 | + else if len(backdropText.text) > 35 |
| 408 | + backdropText.font.size = fontSizeConstants.medium |
| 409 | + else if len(backdropText.text) > 65 |
| 410 | + backdropText.font.size = fontSizeConstants.small |
| 411 | + end if |
| 412 | + end if |
| 413 | +end sub |
| 414 | + |
| 415 | +'Reset backdrop text to original position |
| 416 | +sub resetBackdropTextPosition() |
| 417 | + backdropText = m.top.findNode("backdropText") |
| 418 | + if isValid(backdropText) |
| 419 | + backdropText.height = 231 |
| 420 | + backdropText.translation = [9, 9] |
| 421 | + ' Reset font size to original |
| 422 | + fontSizeConstants = m.global.constants.font_sizes |
| 423 | + if isValid(fontSizeConstants) |
| 424 | + backdropText.font.size = fontSizeConstants.large ' or whatever the original size should be |
383 | 425 | end if |
384 | 426 | end if |
385 | 427 | end sub |
|
0 commit comments