Syntax
Success = WidgetSetWidth(Widget, Width.d)Description
Sets the ideal width 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 width.
Parameters
Widget
The handle of the ProGUI widget.
Width.d
The desired ideal width in DIPs. Use #PG_Widget_FitContent
(-1) to indicate that the width should be determined by the widget's
content (e.g., the overflow width of a child layout). Set to 0 to allow
the layout engine (e.g., Flexbox stretch) to determine the width fully,
subject to minimum width constraints.
Return Value
Returns #True if the width was successfully set, or
#False if the widget handle was invalid.
Remarks
This function updates the `idealWidth` property of the widget's associated layout item. The actual rendered width might differ based on the layout type (Flex, Grid, Basic), available space, and the widget's minimum/maximum width settings (WidgetSetMinWidth()). Setting the width triggers a layout update. Setting width to 0 removes the explicit ideal width, often allowing flex items to stretch.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
MyWindow = CreateWindow(0, 0, 400, 200, "WidgetSetWidth Example", #PG_Window_Default | #PG_Window_LayoutFlex) ; Use a flex layout
LayoutSetPadding(#Null, 10) ; Set the current layout padding
If MyWindow
Widget1 = CreateWidget(0, 0, 100, 50) ; Initial width 100
WidgetSetMargin(Widget1, 5)
Widget2 = CreateWidget(0, 0, 100, 50)
WidgetSetMargin(Widget2, 5)
WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_LeftClick
Debug "Setting Widget2 width to 150 DIPs"
WidgetSetWidth(Widget2, 150) ; Make Widget2 wider
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()See Also
WidgetGetWidth, WidgetSetHeight, WidgetSetMinWidth, WidgetSetMinHeight, CreateWidget
Supported OS
Windows, Linux