PtSetParentWidget

PtSetParentWidget — turns a widget into a parent widget.

Syntax

PtSetParentWidget (widget)

		

Arguments

widget

The container-type widget that will become the new parent widget.

Returns

If successful, the new parent widget, otherwise nil.

Example

This example, ex_PtSet-ReParentWidget.g, is included in the product distribution.

#!/usr/cogent/bin/phgamma

/*
This example demonstrates the PtReParentWidget and PtSetParentWidget
functions.  It creates a window with an embedded pane, and puts a label
and a button inside the pane. The default parent of both the label and
the button is the pane.

Toggling the button activates PtReParentWidget for the label, causing
the label to move from the pane to the original window, and back.

Uncommenting the PtSetParentWidget() call sets the window as the parent
widget of the label, so when the program is restarted the label appears
in the upper left corner of the window.
*/

function switch_parents(button, label, p1, p2)
{
  if ((button.flags & Pt_SET) != 0)
	PtReParentWidget (label, p1);
  else
	PtReParentWidget (label, p2);
  PtRealizeWidget(p1);
}

require_lisp("PhotonWidgets");
PtInit(nil);

win = new(PtWindow);

pane = new(PtPane);
pane.fill_color = PgRGB(160,160,160);
pane.SetArea(100,0,100,100);

//PtSetParentWidget (win);

label = new(PtLabel);
label.text_string = "Label";

but = new(PtButton);
but.SetArea(25, 40, 50, 40);
but.text_string = "Switch\nParent";
but.flags = Pt_TOGGLE;
PtAttachCallback(but, Pt_CB_ACTIVATE, `switch_parents(@but, @label, @win, @pane));

PtRealizeWidget(win);
PtMainLoop();

See Also

In Photon documentation: PtSetParentWidget.