TreeGadget SetGadgetState() and other issues

Found an issue in SpiderBasic ? Please report it here !
blz
Posts: 7
Joined: Wed Apr 14, 2021 12:40 pm

TreeGadget SetGadgetState() and other issues

Post by blz »

Hi,

Please find some further issues with TreeGadget below.

- TreeGadget doesn't respond to SetGadgetState(id, -1) <- works OK in PB
- TreeGadget SetGadgetState() doesn't auto-expand selected nodes if selection is under a collapsed node <- works OK in PB
- TreeGadget doesn't scroll to the selected item, even if all nodes are Expanded <- works OK in PB
- TreeGadget is very slow at traversing through its items <- works OK in PB

Thanks for taking a look.

Code: Select all


; TreeGadget SetGadgetState() and other issues
; 
; -TreeGadget doesn't respond to SetGadgetState(id, -1)  <- works OK in PB!  <- works OK in PB
; -TreeGadget SetGadgetState() doesn't auto-expand selected nodes if selection is under a collapsed node  <- works OK in PB
; -TreeGadget doesn't scroll to the selected item, even if all nodes are Expanded  <- works OK in PB
; -TreeGadget is also very slow at traversing its items  <- works OK in PB

#win = 0
Enumeration
  #Tree
  #ListView
  #ListIcon
  #btnUnSelect
  #btnSelect
  #btnExpand
  #btnCollapse
EndEnumeration

Procedure GadgetEvent()
  Select EventGadget()
    Case #btnUnSelect
      Debug "  #btnUnSelect clicked"
      SetGadgetState(#ListIcon, -1)
      SetGadgetState(#ListView, -1)
      SetGadgetState(#Tree, -1)
      
    Case #btnSelect
      Debug "  #btnSelect clicked"
      item = Random(CountGadgetItems(#ListIcon)-1)
      Debug "#ListIcon: " + item
      SetGadgetState(#ListIcon, item)
      
      item = Random(CountGadgetItems(#ListView)-1)
      Debug "#ListView: " + item
      SetGadgetState(#ListView, item)
      
      item = Random(CountGadgetItems(#Tree)-1)
      Debug "#Tree: " + item
      SetGadgetState(#Tree, item)
      
    Case #btnExpand
      Debug "  #btnExpand clicked"
      For i = 0 To CountGadgetItems(#Tree)-1
        SetGadgetItemState(#Tree, i, #PB_Tree_Expanded)
      Next
      
    Case #btnCollapse
      Debug "  #btnCollapse clicked"
      For i = 0 To CountGadgetItems(#Tree)-1
        SetGadgetItemState(#Tree, i, #PB_Tree_Collapsed)
      Next
  EndSelect
  
EndProcedure

Procedure SizeWindowEvent()
  ResizeGadget(#ListIcon, #PB_Ignore, #PB_Ignore, #PB_Ignore, WindowHeight(#win)-60)
  ResizeGadget(#ListView, #PB_Ignore, #PB_Ignore, #PB_Ignore, WindowHeight(#win)-60)
  ResizeGadget(#Tree, #PB_Ignore, #PB_Ignore, #PB_Ignore, WindowHeight(#win)-60)
EndProcedure


BindEvent(#PB_Event_Gadget, @GadgetEvent())
BindEvent(#PB_Event_SizeWindow, @SizeWindowEvent())

If OpenWindow(#win, 0, 0, 610, 400, "TreeGadget Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  WindowBounds(#win, 610, 400, 610, 800)
  
  ButtonGadget(#btnUnSelect,  10, 10, 190, 25, "SetGadgetState(-1)")
  ButtonGadget(#btnSelect,  210, 10, 190, 25, "SetGadgetState(Random())")
  ButtonGadget(#btnExpand,  410, 10, 90, 25, "Expand All")
  ButtonGadget(#btnCollapse,  510, 10, 90, 25, "Collapse All")
  
  ListIconGadget(#ListIcon, 10, 50, 190, 340, "Column", 100, #PB_ListIcon_AlwaysShowSelection)
  For i = 0 To 100
    AddGadgetItem (#ListIcon, -1, "Normal ListIcon Item "+Str(i))
  Next
  
  ListViewGadget(#ListView, 210, 50, 190, 340)
  For i = 0 To 100
    AddGadgetItem (#ListView, -1, "Normal ListView Item "+Str(i))
  Next
  
  TreeGadget(#Tree, 410, 50, 190, 340)
  For i = 0 To 100
    AddGadgetItem(ID, -1, "Normal TreeItem "+Str(i), 0, 0)
    AddGadgetItem(ID, -1, "Node "+Str(i), 0, 0)
    AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
    AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
    AddGadgetItem (ID, -1, "File "+Str(i), 0, 0)
  Next
  
  SetGadgetState(#ListIcon, 1)  ; select the 2nd item
  SetGadgetState(#ListView, 1)  ; select the 2nd item
  SetGadgetState(#Tree, 1)      ; select the 2nd item
  
  CompilerIf #PB_Compiler_OS <> #PB_OS_Web
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  CompilerEndIf
EndIf