Syntax
Height.d = WidgetGetHeight(Widget, ReturnLayoutDefined.b=#False)Description
Retrieves the current actual rendered height of the specified widget in device-independent pixels (DIPs). Optionally, it can return the ideal height defined in the layout.
Parameters
Widget
The handle of the ProGUI widget whose height is to be retrieved.
ReturnLayoutDefined.b (optional)
If set to #True, the function returns the ideal height set
for the widget in the layout (using WidgetSetHeight() or CreateWidget()), potentially returning
#PG_Widget_FitContent (-1) if that was set. If
#False (default), returns the actual calculated height
after layout adjustments.
Return Value
Returns the requested widget height as a floating-point number
(Double) in DIPs. Returns 0.0 or #False if the
widget handle is invalid. If ReturnLayoutDefined is
#True, it might return #PG_Widget_FitContent
(-1).
Remarks
The actual rendered height (`ReturnLayoutDefined = #False`) can differ from the ideal height due to layout constraints (e.g., Flexbox stretching/shrinking, Grid row sizing). Getting the layout-defined height is useful for checking the intended size versus the rendered size.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 200, "Widget Height Example", #PG_Window_Default | #PG_Window_LayoutFlex) ; Use flex layout
LayoutSetPadding(#Null, 10) ; Set the current layout padding
If MyWindow
; Widget with a fixed ideal height
Widget1 = CreateWidget(0, 0, 100, 50)
WidgetSetClass(Widget1, "widget1")
WidgetSetMargin(Widget1, 5)
; Widget set to stretch (auto height in this layout)
Widget2 = CreateWidget(0, 0, 100, 0) ; Initial ideal height 0
WidgetSetClass(Widget2, "widget2")
WidgetSetMargin(Widget2, 5)
WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
; Get heights after layout calculation
Height1_Actual.d = WidgetGetHeight(Widget1)
Height1_Ideal.d = WidgetGetHeight(Widget1, #True)
Height2_Actual.d = WidgetGetHeight(Widget2)
Height2_Ideal.d = WidgetGetHeight(Widget2, #True) ; Will likely be 0 as set initially
Debug "Widget 1 - Ideal Height: " + StrD(Height1_Ideal) + ", Actual Height: " + StrD(Height1_Actual)
Debug "Widget 2 - Ideal Height: " + StrD(Height2_Ideal) + ", Actual Height: " + StrD(Height2_Actual)
Repeat
Event = WaitWindowEvent()
Height2_Actual.d = WidgetGetHeight(Widget2)
Height2_Ideal.d = WidgetGetHeight(Widget2, #True) ; Will likely be 0 as set initially
Debug "Widget 2 - Ideal Height: " + StrD(Height2_Ideal) + ", Actual Height: " + StrD(Height2_Actual)
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()See Also
WidgetSetHeight, WidgetGetWidth, WidgetGetX, WidgetGetY, WidgetSetMinHeight
Supported OS
Windows, Linux