WidgetShow

Syntax

Success = WidgetShow(Widget, Visibility=#Null)

Description

Controls the visibility and layout participation of the specified widget.

Parameters

Widget
The handle of the ProGUI widget.

Visibility (optional)
Specifies the new visibility state. Default is #Null (which means show the widget normally).

#PG_Layout_Item_Show   (or #Null or 0) : Makes the widget visible and participate in layout.
#PG_Layout_Item_Hide                : Hides the widget completely. It will not be drawn and will not take up space in the layout.
#PG_Layout_Item_NoDraw              : The widget participates in layout calculations (takes up space) but is not drawn.

Return Value

Returns #True if the visibility state was successfully updated, or #False if the widget handle was invalid.

Remarks

This function modifies the flags of the widget's associated layout item. Changing the visibility state triggers a layout update of the parent layout. Hiding a widget (`#PG_Layout_Item_Hide`) removes it from the layout flow entirely. Using `#PG_Layout_Item_NoDraw` reserves space for the widget but prevents it (and its children, if any) from rendering. OS Widgets are hidden using OS calls when set to `#PG_Layout_Item_Hide`.

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

Procedure ToggleWidget(Widget, EventType, *EventData, WidgetToToggle)
  If EventType = #PG_Event_MouseLeftButtonUp
    Static HiddenState = #False
    HiddenState = 1 - HiddenState ; Toggle state
    If HiddenState
        WidgetShow(WidgetToToggle, #PG_Layout_Item_Hide)
        Debug "Widget Hidden"
    Else
        WidgetShow(WidgetToToggle, #PG_Layout_Item_Show)
        Debug "Widget Shown"
    EndIf
  EndIf
EndProcedure

MyWindow = CreateWindow(0, 0, 300, 200, "WidgetShow Example")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Column)
LayoutSetPadding(RootLayout, 10)

If MyWindow
  ; Widget to be toggled
  ToggleWidget = CreateWidget(0, 0, 150, 50)
  WidgetSetClass(ToggleWidget, "toggle-me")
  WidgetSetMargin(ToggleWidget, 5)
  ; Add drawing handler

  ; Button to toggle the widget
  ToggleButton = CreateWidget(0, 0, 100, 30)
  WidgetSetClass(ToggleButton, "button")
  WidgetSetMargin(ToggleButton, 5)
  AddEventHandler(ToggleButton, #PG_Event_MouseLeftButtonUp, @ToggleWidget(), ToggleWidget)
  ; Add drawing handler for button

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

CreateWidget (with visibility flags)

Supported OS

Windows, Linux