PtReParentWidget

Gamma/Photon: Using Gamma™ with the Photon microGUIŽ, Version 4.0
Prev |  | Next

# `PtReParentWidget`

`PtReParentWidget` -- changes parents of widgets.

## Syntax

    PtReParentWidget (widget, parent_widget)

## Arguments

`widget`

  The widget to re-parent.

`parent_widget`

  The new parent of the `widget`.

## Returns

t when successful, otherwise an error message.

## Description

This function takes the `widget` from its current parent and associates it with the specified `parent_widget`.

## Example

In this example a `PtWindow` instance is created, which is a container. Once this container is created, it is the default parent until anther container is created. A label is created, then another container (a `PtPane`), and then another label. The first label (`a`) is a child of of the `PtWindow`. The second label (`b`) is a child of the `PtPane`, since it is created while the pane is the default container.

The `PtGetParent` call shows that the second `PtLabel` (`b`) has both pane and win for parents. The second label is then re-parented to the `PtWindow` container. The `PtGetParent` call now shows that the second `PtLabel` (`b`) has only `win` as a parent.

        Gamma> PtInit(nil);
        t
        Gamma> win = new(PtWindow);
        window definition
        Gamma> a = new(PtLabel);
        label definition
        Gamma> pane = new(PtPane);
        pane definition
        Gamma> b = new(PtLabel);
        label definition
        Gamma> PtGetParent(b,PtPane) == pane;
        t
        Gamma> PtGetParent(b,PtWindow) == win;
        t
        Gamma> PtReParentWidget(b,win);
        t
        Gamma> PtGetParent(b,PtPane) == pane;
        nil
        Gamma> PtGetParent(b,PtWindow) == win;
        t
        Gamma>

This example, `ex_PtSet-ReParentWidget.g`, is included in the `gamma_ph_`#`_examples_1_QNX4.tgz` file available on the Cogent Web Site.

    #!/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

PtGetParent, PtSetParentWidget

and in Photon documentation: PtReParentWidget.

Prev | Home | Next
`PtRawSetPos` | Up | `PtRealizeWidget`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.