WidgetSetHeight

Syntax

Success = WidgetSetHeight(Widget, Height.d)

Description

Sets the ideal height for the specified widget in device-independent pixels (DIPs). This value is used by the parent layout engine as a suggestion for the widget's height.

Parameters

Widget
The handle of the ProGUI widget.

Height.d
The desired ideal height in DIPs. Use #PG_Widget_FitContent (-1) to indicate that the height should be determined by the widget's content (e.g., the overflow height of a child layout). Use 0 to allow the layout engine (e.g., Flexbox stretch) to determine the height fully, subject to minimum height constraints.

Return Value

Returns #True if the height was successfully set, or #False if the widget handle was invalid.

Remarks

This function updates the `idealHeight` property of the widget's associated layout item. The actual rendered height might differ based on the layout type (Flex, Grid, Basic), available space, and the widget's minimum/maximum height settings (WidgetSetMinHeight()). Setting the height triggers a layout update. Setting height to 0 removes the explicit ideal height, often allowing flex items to stretch.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

MyWindow = CreateWindow(0, 0, 400, 200, "WidgetSetHeight Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Row) ; Horizontal layout
LayoutSetPadding(RootLayout, 10)

If MyWindow
  Widget1 = CreateWidget(0, 0, 100, 50) ; Initial height 50
  WidgetSetClass(Widget1, "widget1")
  WidgetSetMargin(Widget1, 5)

  Widget2 = CreateWidget(0, 0, 100, 50)
  WidgetSetClass(Widget2, "widget2")
  WidgetSetMargin(Widget2, 5)

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
  
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_LeftClick
        Debug "Setting Widget2 height to 80 DIPs"
        WidgetSetHeight(Widget2, 80) ; Make Widget2 taller
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

WidgetGetHeight, WidgetSetWidth, WidgetSetMinHeight, WidgetSetMinWidth, CreateWidget

Supported OS

Windows, Linux