How to make EditorGadget scroll

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

How to make EditorGadget scroll

Post by WilliamL »

If I use AddGadgetItem to add lines to the EditorGadget the window does not scroll. Since SetGadgetItemState() does not work I'm wondering how to get the gadget to scroll down to the added item?

Code: Select all

;run and you will see the items are listed but the last items are not visible
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    EditorGadget(0, 8, 8, 306, 133)
    For a = 0 To 15
      AddGadgetItem(0, a, "Line "+Str(a))
    Next
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How to make EditorGadget scroll

Post by wilbert »

Code: Select all

;run and you will see the items are listed and the last items are visible
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    EditorGadget(0, 8, 8, 306, 133)
    For a = 0 To 15
      AddGadgetItem(0, a, "Line "+Str(a))
    Next
    
    Range.NSRange\location = Len(GetGadgetText(0))
    CocoaMessage(0, GadgetID(0), "scrollRangeToVisible:@", @Range)
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: How to make EditorGadget scroll

Post by WilliamL »

Thanks wilbert!

That works perfectly! :)

I had to add this definition to my procedure (since I am using 'EnableExplicit').

Code: Select all

Define Range.NSRange
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How to make EditorGadget scroll

Post by wilbert »

I'm glad it works for you.
And you are right about Define .
I usually don't use EnableExplicit (a bit lazy :wink: )
Post Reply