PtClearWidget()

Destroy all widgets within a container

Synopsis:

int PtClearWidget(PtWidget_t *widget);

Arguments:

widget
A pointer to the container widget that you want to clear.

Library:

ph

Description:

This function destroys all the nonprocreated widgets within the specified container-class widget.

Procreated widgets are widgets that are created as part of a compound widget, as opposed to those that your application creates. For example, a PtScrollContainer can have:

If the specified widget isn't a container, no action is taken.

Returns:

0
Successful completion.
-1
An error occurred (the widget wasn't a container).

Examples:

#include <stdlib.h>
#include <Pt.h>

int main()
{
    PtWidget_t *group, *window;
    PtArg_t argt;
    PtArg_t argts[3];
    PhPoint_t pos ={ 10,10 };

    if (PtInit(NULL) == -1)
       exit(EXIT_FAILURE);

    PtSetArg( &argt, Pt_ARG_POS, &pos, 0 );
    window = PtCreateWidget( PtWindow, Pt_NO_PARENT, 1, &argt );

    PtSetArg( &argts[0], Pt_ARG_POS, &pos, 0 );
    PtSetArg( &argts[1], Pt_ARG_GROUP_ORIENTATION, 
              Pt_GROUP_VERTICAL, 0 );
    group = PtCreateWidget( PtGroup, window, 1, &argt );

    PtSetArg( &argt, Pt_ARG_TEXT_STRING, "Button", 0 );
    PtCreateWidget( PtButton, group, 1, &argt );

    //using same string as previous button...
    PtCreateWidget( PtButton, group, 1, &argt );

    PtCreateWidget( PtButton, group, 1, &argt );

    PtRealizeWidget( window );

    PtContainerHold( group );
    PtClearWidget( group );
    //destroys all widgets within the group, 
    //clearing it...

    //add new children to the group
    PtSetArg( &argt, Pt_ARG_TEXT_STRING,
              "New Button", 0 );
    PtRealizeWidget( PtCreateWidget( PtButton, group, 1,
                                     &argt ) );
    PtSetArg( &argt, Pt_ARG_TEXT_STRING,
              "New Button2", 0 );
    PtRealizeWidget( PtCreateWidget( PtButton, group, 1,
                     &argt ) );
    
    //force the group to re-align its children and resize.
    PtExtentWidget( group );
    
    PtContainerRelease( group );
    PtMainLoop();
    return EXIT_SUCCESS;
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PtContainerHold(), PtContainerRelease(), PtDestroyWidget(), PtExtentWidget(), PtWidgetChildBack()