Syntax
Success = ScrollBarSetValues(ScrollBarWidget, Position=#PG_Ignore, Minimum=#PG_Ignore, Maximum=#PG_Ignore, PageSize=#PG_Ignore)
Description
Sets the current position, minimum value, maximum value, and page size for a ProGUI scroll bar widget created with CreateScrollBar(). Allows updating multiple properties in a single call.
Parameters
ScrollBarWidget
The handle of the ProGUI scroll bar widget to modify.
Position (optional)
The new current scroll position (Integer). Use
#PG_Ignore to keep the current value. If the new position is outside the valid range
(Minimum to Maximum - PageSize), it will be clamped.
Minimum (optional)
The new minimum scroll value (Integer). Use
#PG_Ignore to keep the current value.
Maximum (optional)
The new maximum scroll value (Integer). Use
#PG_Ignore to keep the current value. Must be greater than Minimum.
PageSize (optional)
The new page size (Integer), representing the amount to
scroll when paging (clicking the track) and affecting the thumb size. Use #PG_Ignore to
keep the current value. Must be non-negative and not larger than Maximum.
Return Value
Returns #True if the values were successfully updated (or if no changes were needed), or
#False if the scroll bar handle was invalid.
Remarks
This function provides a convenient way to update the state of a scroll bar, often used when the size or
content of the scrollable area changes. Setting these values may trigger a redraw of the scroll bar if
its appearance changes (e.g., thumb size or position). It will also trigger an
#PG_Event_Action if the `Position` was changed from its previous value. Input values are
validated and clamped to ensure consistency (e.g., Position is within Minimum and Maximum - PageSize).
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
; Event handler for scroll bar action
Procedure ScrollBarHandler(Widget, EventType, *EventData, *UserData)
If EventType = #PG_Event_Action
NewPosition = *EventData
Debug "Scroll Bar Position: " + Str(NewPosition)
EndIf
EndProcedure
; Update values after a delay
Procedure DelayedUpdate(Widget, EventType, *EventData.PG_EventAnimate, *UserData)
If EventType = #PG_Event_Animate And *EventData\state = #PG_Event_Animate_End
Debug "Updating scrollbar values..."
; Set new position, new maximum, keep minimum, new page size
ScrollBarSetValues(Widget, 50, #PG_Ignore, 200, 40)
Debug "Scrollbar updated."
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 400, 100, "ScrollBarSetValues Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetPadding(RootLayout, 20)
If MyWindow
; Create a horizontal scroll bar
HScrollBar = CreateScrollBar(0, 0, 200, 0, 0, 100, 20)
WidgetSetHeight(HScrollBar, 20)
AddEventHandler(HScrollBar, #PG_Event_Action, @ScrollBarHandler())
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
AddEventHandler(HScrollBar, #PG_Event_Animate, @DelayedUpdate())
StartAnimation(HScrollBar, 1, 2000) ; Trigger update after 2 seconds
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
CreateScrollBar, #PG_Event_Action
Supported OS
Windows, Linux