Calculate Y coordinate of TreeGadget item
Posted: Wed Mar 01, 2023 9:12 pm
How would I calculate the Y position of a tree item by iterating over the items? Or is there a simple formula I could use? I think there are API functions to do this on Windows, but I'm trying to program my own with drag and drop since the Drag & Drop library doesn't allow that on macOS, so I need to know how to determine which item the user clicked on. This code only has the PB TreeGadget for simplicity's sake.
Code: Select all
EnableExplicit
OpenWindow(0, 100, 100, 400, 300, "", #PB_Window_SystemMenu)
TreeGadget(0, 0, 0, 400, 300)
AddGadgetItem(0, -1, "Item 1")
AddGadgetItem(0, -1, "Item 2")
AddGadgetItem(0, -1, "Item 2.1", 0, 1)
AddGadgetItem(0, -1, "Item 2.2", 0, 1)
AddGadgetItem(0, -1, "Item 2.2.1", 0, 2)
AddGadgetItem(0, -1, "Item 3")
AddGadgetItem(0, -1, "Item 4")
SetGadgetItemState(0, 1, #PB_Tree_Expanded)
Define y, item, i, itemHeight
itemHeight = 25
item = 5
y = 0
For i = 0 To CountGadgetItems(0) - 1
If GetGadgetItemState(0, i) & #PB_Tree_Collapsed
; skip children?
EndIf
If i = item
Break
EndIf
y + itemHeight
Next
Debug y
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow