Calculate the position of a widget based on a position and another widget
int PtCalcAbsPosition( PtWidget_t *reference, PhPoint_t const *pos, PhDim_t const *dim, PhPoint_t *new_pos );
ph
This function calculates the position of a new widget with dimensions dim, according to the reference widget and pos values passed.
The reference argument is a pointer to a widget you wish to position the new widget relative to. The pos argument is an offset from the reference widget or from the top left corner of the screen. The dim argument gives the dimensions of the new widget to be positioned and must not be NULL. The new_pos argument must be a pointer to a PhPoint_t structure. The calculated position is stored in it.
The position is calculated as follows:
Reference | Position | Position returned |
---|---|---|
NULL | NULL | center of the screen |
NULL | non-NULL | offset pos from the top left corner of the screen |
non-NULL | NULL | center of reference widget |
non-NULL | non-NULL | offset pos from the reference widget's top left corner |
If you have a main application window and want to center a dialog on it, you could do the following:
PtWidget_t *window; // The main window PhDim_t dim = { 100, 100 }; // The size the dialog // is going to be PhPoint_t pos; // The position of the dialog, // to be determined int err; ... // make a main window window = PtCreateWidget(PtWindow, Pt_NO_PARENT, n_args, args); ... err = PtCalcAbsPosition(window, NULL, &dim, &pos); ... // Create the dialog and position it at 'pos' -- // it will be centered on the window.
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |