PtSetParentWidget (widget)
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();
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.