TreeGadget scroll position

Mac OSX specific forum
wombats
Enthusiast
Enthusiast
Posts: 717
Joined: Thu Dec 29, 2011 5:03 pm

TreeGadget scroll position

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: TreeGadget scroll position

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: TreeGadget scroll position

Post 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.
wombats
Enthusiast
Enthusiast
Posts: 717
Joined: Thu Dec 29, 2011 5:03 pm

Re: TreeGadget scroll position

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: TreeGadget scroll position

Post by mk-soft »

Overlapping gadgets are not supported
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply