Page 1 of 1

ListIconGadget display corruption

Posted: Wed Jan 06, 2021 2:15 pm
by BarryG
I've got a ListIconGadget in Large Icons mode where I added icons on-the-fly, but after adding a few, the display gets "corrupted" until I force a refresh by changing the mode from Large to List and then back to Large again.

To see what I mean, run this code. Then press the "A" key at least 8 times, and then scroll down the list and you'll see that the icons aren't in order (it has gaps, see screenshot below). Then press the "F" key to fix the display, and then "A" works normally.

I'm hoping there's a way to fix the display without changing the mode? Any ideas?

Image

Code: Select all

If OpenWindow(0, 200, 200, 320, 185, "ListIconGadget", #PB_Window_SystemMenu)
  ListIconGadget(1, 10, 10, 305, 165, "", 250, #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection)
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
    SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    text$ = "Notepad"
    id = ImageID(0)
    For i = 1 To 3
      AddGadgetItem(1, 1, text$, id)
    Next
  EndIf
  Repeat
    Event = WaitWindowEvent()
    If Event = #WM_KEYUP
      Select EventwParam()
        Case #VK_A
          AddGadgetItem(1, -1, text$, id)
        Case #VK_F ; Hack "fix". How to do this without changing the DisplayMode?
          SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_List)
          SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf

Re: ListIconGadget display corruption

Posted: Wed Jan 06, 2021 4:21 pm
by RASHAD
Hi BarryG

Code: Select all

If OpenWindow(0, 200, 200, 350, 185, "ListIconGadget", #PB_Window_SystemMenu)
  ListIconGadget(1, 10, 10, 330, 165, "", 200, #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection)
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
    SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    text$ = "Notepad"
    id = ImageID(0)
    For i = 1 To 3
      AddGadgetItem(1, 1, text$, id)
    Next
  EndIf
 Repeat
    Event = WaitWindowEvent()
    If Event = #WM_KEYUP
      Select EventwParam()
        Case #VK_A
          AddGadgetItem(1, -1, text$, id)
          SendMessage_(GadgetID(1),#LVM_ARRANGE,#LVA_DEFAULT,0)
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf

Re: ListIconGadget display corruption

Posted: Wed Jan 06, 2021 11:36 pm
by BarryG
Thanks Rashad. Is that basically doing the same thing as changing the list mode, though?

Re: ListIconGadget display corruption

Posted: Thu Jan 07, 2021 4:38 am
by breeze4me
Use #LVS_AUTOARRANGE flag.

Code: Select all

If OpenWindow(0, 200, 200, 320, 185, "ListIconGadget", #PB_Window_SystemMenu)
  ListIconGadget(1, 10, 10, 305, 165, "", 250, #PB_ListIcon_MultiSelect | #PB_ListIcon_AlwaysShowSelection | #LVS_AUTOARRANGE)
  If LoadImage(0, #PB_Compiler_Home+"Examples\Sources\Data\File.bmp")
    SetGadgetAttribute(1, #PB_ListIcon_DisplayMode, #PB_ListIcon_LargeIcon)
    text$ = "Notepad"
    id = ImageID(0)
    For i = 1 To 3
      AddGadgetItem(1, 1, text$, id)
    Next
  EndIf
  Repeat
    Event = WaitWindowEvent()
    If Event = #WM_KEYUP
      Select EventwParam()
        Case #VK_A
          AddGadgetItem(1, -1, text$, id)
          
      EndSelect
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf

Re: ListIconGadget display corruption

Posted: Thu Jan 07, 2021 8:21 am
by BarryG
breeze4me wrote:Use #LVS_AUTOARRANGE flag
That's even better, because I don't need to use SendMessage on the gadget every time my app's window resizes. Thank you!

See, this is exactly why I rarely mark a question as "Solved", because breeze4me might not have come into this thread if he saw it.