Page 1 of 1

TreeGadget scroll position

Posted: Tue Mar 12, 2024 5:15 pm
by wombats
I'm trying to retrieve the current scroll position of a TreeGadget so I can position another control appropriately (it needs to be in line with a specific item, for example).

Am I heading in the right direction? This returns values much higher than expected.

Code: Select all

EnableExplicit

Global scrollPos, scrollbar, EnclosingScrollView, ContentView, Bounds.NSRect, Origin

OpenWindow(0, 270, 100, 350, 180, "TreeGadget")
TreeGadget(0, 10, 10, WindowWidth(0) - 20, 95)
TextGadget(1, 10, GadgetY(0) + GadgetHeight(0) + 10, 100, 25, "")

AddGadgetItem (0, -1, "Item 1", 0, 0)

Define i
For i = 1 To 25
  AddGadgetItem (0, -1, "Subitem " + Str(i), 0, 1)
Next i

EnclosingScrollView = CocoaMessage(0, GadgetID(0), "enclosingScrollView")
ContentView = CocoaMessage(0, EnclosingScrollView, "contentView")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
  CocoaMessage(@Bounds, ContentView, "documentVisibleRect")
  SetGadgetText(1, Str(Bounds\origin\y))
ForEver

Re: TreeGadget scroll position

Posted: Tue Mar 12, 2024 7:05 pm
by mk-soft
Not for me. Row height 24.0
It is also a little easier with directly visibleRect on the gadget

Code: Select all


EnableExplicit

Global rowHeight.CGFloat, Rect.NSRect

OpenWindow(0, 270, 100, 350, 180, "TreeGadget")
TreeGadget(0, 10, 10, WindowWidth(0) - 20, 95)
TextGadget(1, 10, GadgetY(0) + GadgetHeight(0) + 10, 100, 25, "")

AddGadgetItem (0, -1, "Item 1", 0, 0)

Define i
For i = 1 To 25
  AddGadgetItem (0, -1, "Subitem " + Str(i), 0, 1)
Next i

CocoaMessage(@rowHeight, GadgetID(0), "rowHeight")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          ;
      EndSelect
      
    Default
      CocoaMessage(@Rect, GadgetID(0), "visibleRect")
      SetGadgetText(1, "Item: " + Str(Rect\origin\y / rowHeight))
      
  EndSelect
  
ForEver

Re: TreeGadget scroll position

Posted: Tue Mar 12, 2024 7:13 pm
by Shardik
You already asked in this thread how to get the y-coordinate of a TreeGadget item and RASHAD and me both posted an example. Did you try my MacOS example in that thread? It displays the text of a clicked item and its y-position. I just tested it to work in PB 6.04.

Re: TreeGadget scroll position

Posted: Tue Mar 12, 2024 10:34 pm
by wombats
Shardik wrote: Tue Mar 12, 2024 7:13 pm You already asked in this thread how to get the y-coordinate of a TreeGadget item and RASHAD and me both posted an example. Did you try my MacOS example in that thread? It displays the text of a clicked item and its y-position. I just tested it to work in PB 6.04.
Oh, my goodness, I apologise. I forgot about that. :cry: Thank you for reminding me.

That does help with the y-position, yes, but I need to position a StringGadget on the control...which hopefully works (It seems to if both are in a container), so I think I need the scroll position, too. I'll try mk-soft's example, too.

Re: TreeGadget scroll position

Posted: Wed Mar 13, 2024 9:46 am
by mk-soft
Overlapping gadgets are not supported