Photon anchor problem

Marek Peca <[email protected]> Tue, 15 Oct 2002 09:42:50 +0000 ( )
Newsgroups gmane.os.qnx.openqnx.devel
Message-ID <[email protected]>
Dear colleagues,

whole week I'm experimenting with anchoring of PtGroup's, but now I'm
exhausted. I want in my app to put some value inputs, consisting of a
PtText on the left, which has to be stretched to fill the area, and a
PtLabel on the right:

[PtText...........] [PtLabel]

I partially succeeded using a PtGroup on each widget (I'm using old
Photon, where anchor properties are defined only for PtContainers), left
anchored left->left, right->right and right one anchored left->right,
right->right, with appropriate absolute offset, determinating width of
PtLabel. OK, this worked in the simplest case, but when I put this to a
PtGroup, which is relative-anchored, things will go wrong -- the width of
a PtLabel is set to some strange constant and cannot be changed.

When I set up same thing in PhAB, it works well. I imported that .wgtw to
my app and examined anchor values, but they are the same. So, what am I
doing wrong? Is there a need of special widget creation alchemy to get
these things work well?

I'm attaching my source, when input widget structure (created by
create_input_field) is child of main app widget, it's ok and when it is
created as child of a PtGroup inside main, it faults.

Thank you,
Marek P.


/** ---cut-here--- **/
#include <Pt.h>


void set_anchors(PtWidget_t *c, unsigned long flags, short x1, short y1, short x2, short y2) {
	PtArg_t arg[2];
	PhRect_t offs;
	offs.ul.x = x1; offs.ul.y = y1; offs.lr.x = x2; offs.lr.y = y2;
	PtSetArg(&arg[0], Pt_ARG_ANCHOR_FLAGS, flags, flags);
	PtSetArg(&arg[1], Pt_ARG_ANCHOR_OFFSETS, &offs, 0);
	PtSetResources(c, 2, arg);
}

void set_label(PtWidget_t *w, char *text) {
	PtArg_t arg[1];
	PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, text, 0);
	PtSetResources(w, 1, arg);
}

PtWidget_t *create_label(PtWidget_t *parent, char *text) {
	PtWidget_t *lbl = PtCreateWidget(PtLabel, parent, 0, NULL);
	set_label(lbl, text);
	return(lbl);
}

PtWidget_t *create_input(PtWidgetClassRef_t *class, PtWidget_t *parent,
						 unsigned long cbtype, PtCallbackF_t *cb, void *data) {
	PtWidget_t *w = PtCreateWidget(class, parent, 0, NULL);	
	PtAddCallback(w, cbtype, cb, data);
	return(w);
}

PtWidget_t *create_input_field(PtWidget_t *parent, char *label, short offset) {
	static const PtArg_t arg[] = {
		{Pt_ARG_GROUP_ORIENTATION, Pt_GROUP_HORIZONTAL, Pt_GROUP_HORIZONTAL},
		{Pt_ARG_GROUP_FLAGS, Pt_GROUP_STRETCH_HORIZONTAL, Pt_GROUP_STRETCH_HORIZONTAL},
	};
	PtWidget_t *left = PtCreateWidget(PtGroup, parent, 2, arg),
		*right = PtCreateWidget(PtGroup, parent, 2, arg);
	create_label(right, label);
	set_anchors(left, Pt_LEFT_ANCHORED_LEFT | Pt_RIGHT_ANCHORED_RIGHT, 0, 0, offset, 0);
	set_anchors(right, Pt_LEFT_ANCHORED_RIGHT | Pt_RIGHT_ANCHORED_RIGHT, offset, 0, 0, 0);
	return(create_input(PtText, left, Pt_CB_MODIFY_NOTIFY, NULL, NULL));
}

#define BAD

int main(int argc, char *argv[]) {
	static const PtArg_t p_arg[] = {
		{Pt_ARG_GROUP_ORIENTATION, Pt_GROUP_HORIZONTAL, Pt_GROUP_HORIZONTAL}
	};
	
	PtWidget_t *main = PtAppInit(NULL, &argc, argv, 0, NULL), *p1;
#ifdef BAD
	p1 = PtCreateWidget(PtGroup, main, 1, p_arg);
	set_anchors(p1, Pt_LEFT_ANCHORED_LEFT | Pt_RIGHT_ANCHORED_RIGHT |
		Pt_RIGHT_ANCHORED_RELATIVE | Pt_LEFT_ANCHORED_RELATIVE, 0, 0, 5000, 0);
	create_input_field(p1, "megawatt", 70);
#else
	create_input_field(main, "megawatt", 70);
#endif
	PtRealizeWidget(main);
	PtMainLoop();
	return(EXIT_SUCCESS);
}

/*********
 ** EOF **
 *********/
anchors.c.gz (application/octet-stream, 809 B) - not displayed