Syntax
Success = WidgetResize(Widget, x.d, y.d, Width.d, Height.d)
Description
Sets the initial/layout position (x, y) and ideal size (Width, Height) for the specified widget. These values are hints used by the parent layout engine.
Parameters
Widget
The handle of the ProGUI widget to modify.
x, y
The new layout-defined position (in DIPs) relative to the parent layout. Use
#PG_Ignore to keep the current value. Primarily affects Basic layouts.
Width, Height
The new ideal size (in DIPs) for the widget. Use
#PG_Ignore to keep the current value. Use #PG_Widget_FitContent to size
based on content.
Return Value
Returns #True if the properties were successfully updated, or #False if the
widget handle was invalid.
Remarks
This function updates the widget's stored `x`, `y` values and sets the `idealWidth` and `idealHeight` properties of its associated layout item. It then triggers a layout update. The final rendered position and size depend on the parent layout type and constraints. This is the primary way to programmatically suggest a new size or position for a widget after creation.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
; Event handler to resize the widget
Procedure ButtonResizeHandler(Widget, EventType, *EventData, WidgetToResize)
If EventType = #PG_Event_MouseLeftButtonUp
NewWidth.d = WidgetGetWidth(WidgetToResize) * 1.2 ; Increase width by 20%
NewHeight.d = WidgetGetHeight(WidgetToResize) * 0.8 ; Decrease height by 20%
Debug "Resizing widget to W: " + StrD(NewWidth) + ", H: " + StrD(NewHeight)
WidgetResize(WidgetToResize, #PG_Ignore, #PG_Ignore, NewWidth, NewHeight)
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 400, 300, "WidgetResize Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Column)
LayoutSetPadding(RootLayout, 10)
If MyWindow
; The widget to be resized
TargetWidget = CreateWidget(0, 0, 150, 80)
WidgetSetClass(TargetWidget, "target")
WidgetSetMargin(TargetWidget, 5)
; Add drawing handler if needed
; Button to trigger the resize
ResizeButton = CreateWidget(0, 0, 100, 30)
WidgetSetClass(ResizeButton, "button")
WidgetSetMargin(ResizeButton, 5)
AddEventHandler(ResizeButton, #PG_Event_MouseLeftButtonUp, @ButtonResizeHandler(), TargetWidget)
; Add drawing/text handler for button
WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()
See Also
WidgetSetWidth, WidgetSetHeight, WidgetGetWidth, WidgetGetHeight, WidgetGetX, WidgetGetY, CreateWidget
Supported OS
Windows, Linux