Create a widget
PtWidget_t *PtCreateWidget( PtWidgetClassRef_t *class, PtWidget_t *parent, unsigned n_args, PtArg_t const *args );
ph
This function creates a widget in the current widget hierarchy. The class argument points to the desired widget class.
The parent argument specifies the parent widget. It can be a pointer to the parent widget or one of:
The n_args argument contains the number of arguments being passed to the widget library and the args argument points to an array containing n_args PtArg_t entries.
Since this function modifies and allocates only local data structures, it doesn't result in any interaction with the Photon Manager. The user doesn't see the widget until it's realized.
Widgets that belong to the PtContainer class become the current parent widget when created. If you're creating multiple PtContainer-class widgets, make sure each one is placed in the correct container. To do this, either specify the desired parent in parent or call PtSetParentWidget(). |
A pointer to the newly created widget, or NULL if an error occurs.
#include <stdlib.h> #include <Pt.h> int main () { PtWidget_t *window, *group1, *group2; PhPoint_t pos; PtArg_t argt[5]; if (PtInit(NULL) == -1) exit(EXIT_FAILURE); if ((window = PtCreateWidget(PtWindow, Pt_NO_PARENT, 0, NULL)) == NULL) PtExit(EXIT_FAILURE); /* Create a group as the child of the default parent (i.e. the window). */ pos.x = pos.y = 0; PtSetArg( &argt[0], Pt_ARG_POS, &pos, 0 ); group1 = PtCreateWidget( PtGroup, Pt_DEFAULT_PARENT, 1, argt ); /* Create a group, specifying the window as the parent. */ pos.x += 150; group2 = PtCreateWidget( PtGroup, window, 1, argt ); /* Create some buttons as children of the default parent (i.e. the second group). */ PtSetArg( &argt[0], Pt_ARG_TEXT_STRING, "Child2a", 0 ); PtCreateWidget( PtButton, Pt_DEFAULT_PARENT, 1, argt ); PtSetArg( &argt[0], Pt_ARG_TEXT_STRING, "Child2b", 0 ); PtCreateWidget( PtButton, Pt_DEFAULT_PARENT, 1, argt ); /* Set the default parent to be group1 and create some children. */ PtSetParentWidget( group1 ); PtSetArg( &argt[0], Pt_ARG_TEXT_STRING, "Child1a", 0 ); PtCreateWidget( PtButton, Pt_DEFAULT_PARENT, 1, argt ); PtSetArg( &argt[0], Pt_ARG_TEXT_STRING, "Child1b", 0 ); PtCreateWidget( PtButton, Pt_DEFAULT_PARENT, 1, argt ); /* Create a child, specifying the second group as the parent. */ PtSetArg( &argt[0], Pt_ARG_TEXT_STRING, "Child2c", 0 ); PtCreateWidget( PtButton, group2, 1, argt ); PtRealizeWidget (window); PtMainLoop(); return EXIT_SUCCESS; }
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PtArg_t, PtDestroyWidget(), PtGetParentWidget(), PtReparentWidget(), PtSetArg(), PtSetParentWidget(), PtWidgetParent()
“Creating widgets” in the Managing Widgets in Application Code chapter of the Photon Programmer's Guide