Custom TreeGadget with column support, cross-platform

Share your advanced PureBasic knowledge/code with the community.
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

Re: Custom TreeGadget with column support, cross-platform

Post by nicoh »

Bug: When items are collapsed in the tree, some of the items that follow are no longer clickable.

This is because the methode _cust_tree_getItem()does not check whether an item is actually visible or not (when it's parent is collapsed, x and y should be -1 but they aren't). So it can happen that the method returns a wrong item which results in the following behavior:

I click a visible item but an invisible item which parent is collapsed will be selected and highlighted.

Edit: This should fix the error:

Code: Select all

  Procedure.i _cust_tree_getItem(*tree.ct_main, List tree.ct_entry(), x.i, y.i)
    Protected *Res.ct_entry
    ForEach tree()
      If y.i >= tree()\y And y.i <= tree()\y + *tree\lineHeight And tree()\y <> -1 And tree()\x <> -1
        ProcedureReturn tree()
      EndIf
      If ListSize(tree()\childs()) > 0 And tree()\status <> #collapsed ; <- FIX
        *Res = _cust_tree_getItem(*tree, tree()\childs(), x.i, y.i)
        If *Res <> 0: Break: EndIf
      EndIf
    Next
    ProcedureReturn *Res
  EndProcedure
I added And tree()\status <> #collapsed as a condition.
Post Reply