Syntax
Success = WidgetSetOpacity(Widget, Opacity.f)
Description
Sets the overall opacity level for the specified widget.
Parameters
Widget
The handle of the ProGUI widget.
Opacity.f
The opacity level as a Float between 0.0 (fully transparent) and 1.0 (fully opaque). Values outside this range will be clamped.
Return Value
Returns #True if the opacity was successfully set, or #False if the widget handle was invalid.
Remarks
This opacity value modulates the opacity of everything drawn by the widget, including its background, border, and any content drawn in its #PG_Event_Draw handler. It acts as a multiplier for other opacity values. Setting the opacity triggers a redraw of the widget.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
Procedure DrawFadingWidget(Widget, EventType, *EventData.PG_EventDraw, *UserData)
DrawBox(0, 0, *EventData\width, *EventData\height, RGB(80, 120, 200))
EndProcedure
Procedure FadeInHandler(Widget, EventType, *EventData.PG_EventAnimate, *UserData)
If EventType = #PG_Event_Animate And *EventData\state = #PG_Event_Animate_Update
; Calculate opacity from 0.0 to 1.0 over the animation duration
CurrentOpacity.f = *EventData\currentTime / *EventData\duration
WidgetSetOpacity(Widget, CurrentOpacity)
Debug "Opacity: " + StrF(CurrentOpacity, 2)
ElseIf EventType = #PG_Event_Animate And *EventData\state = #PG_Event_Animate_End
WidgetSetOpacity(Widget, 1.0) ; Ensure it's fully opaque at the end
Debug "Fade-in complete."
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 300, 200, "Widget Opacity Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetPadding(RootLayout, 10)
If MyWindow
FadingWidget = CreateWidget(0, 0, 150, 80)
WidgetSetClass(FadingWidget, "fader")
WidgetSetMargin(FadingWidget, 5)
WidgetSetOpacity(FadingWidget, 0.0) ; Start fully transparent
AddEventHandler(FadingWidget, #PG_Event_Draw, @DrawFadingWidget())
AddEventHandler(FadingWidget, #PG_Event_Animate, @FadeInHandler())
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
; Start a 3-second animation to fade the widget in
StartAnimation(FadingWidget, 1, 3000)
Debug "Starting fade-in animation..."
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WidgetGetOpacity, StartAnimation, AddEventHandler
Supported OS
Windows, Linux