Syntax
ScrollBarWidget = CreateScrollBar(x, y, Width, Height, Minimum, Maximum, PageSize, Flags=#Null)
Description
Creates a ProGUI scroll bar widget. This is a standard ProGUI widget (not an OS control wrapper) rendered using ProGUI's drawing and skinning system. It's typically used internally by layouts when content overflows but can be created manually.
Parameters
x, y, Width, Height
Initial position and ideal size hints (in DIPs), similar to
CreateWidget(). The layout engine will determine the final size and
position.
Minimum
The minimum scroll position value (Integer).
Maximum
The maximum scroll position value (Integer). The actual scrollable range
is `Maximum - PageSize`.
PageSize
The amount the scroll position changes during a page up/down operation
(e.g., clicking the track background). Also affects the size of the scroll thumb.
Flags (optional)
Flags to control the scroll bar's orientation and behavior.
Default is 0 (horizontal).
#PG_ScrollBar_Vertical : Creates a vertical scroll bar instead of the default horizontal one.
; Plus standard widget flags like #PG_Widget_Hide, etc.
Return Value
Returns a handle to the newly created scroll bar widget object if successful, or #Null if
creation failed.
Remarks
The scroll bar widget generates #PG_Event_Action events when its position changes. The
event data (`*EventData`) will contain the new scroll position (as an integer). Use ScrollBarSetValues() to programmatically change the scroll bar's
position, range, or page size after creation. The appearance is controlled by the skin assigned via WidgetSetClass() (typically class "scrollbar") and its various
components ("thumb1", "thumb2", "trackbar").
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 ; EventData directly holds the new position for scrollbar action
Debug "Scroll Bar Position: " + Str(NewPosition)
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 400, 400, "Scroll Bar Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetPadding(RootLayout, 20)
If MyWindow
; Create a horizontal scroll bar
HScrollBar = CreateScrollBar(0, 0, 200, 0, 0, 100, 20) ; 0 = Auto width/height via layout
WidgetSetHeight(HScrollBar, 20) ; Set specific height
AddEventHandler(HScrollBar, #PG_Event_Action, @ScrollBarHandler())
Debug "Horizontal ScrollBar created."
; Create a vertical scroll bar
VScrollBar = CreateScrollBar(0, 20, 0, 0, 0, 200, 50, #PG_ScrollBar_Vertical)
WidgetSetWidth(VScrollBar, 20) ; Set specific width
WidgetSetHeight(VScrollBar, 200) ; Set specific height
AddEventHandler(VScrollBar, #PG_Event_Action, @ScrollBarHandler())
Debug "Vertical ScrollBar created."
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
ScrollBarSetValues, CreateWidget, AddEventHandler, #PG_Event_Action
Supported OS
Windows, Linux