This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

  • Resolved

Widget hierarchy not working as expected...

Hello, 

Could someone please point out if I am doing this wrong, I am trying to use one call to WidgetAdd and WidgetPaint, and yes I have WidgetMessageQueueProcess accessible in a primary task that always get access.

here is the call I make:

void canvasPaint(tCanvasWidget *psWidget) {

    WidgetAdd(WIDGET_ROOT, (tCanvasWidget *)&psWidget->sBase);
    WidgetPaint(WIDGET_ROOT);

}

I think the problem is in the way I am assigning the psParent and psNext... I have tried multiple way of doing this but I am having trouble understanding the correct syntax to use in this instance. Firstly, to initialize I use a function because I want to keep the same persistent style for 10 orso buttons, see below:

void init_RectBtnGr(tPushButtonWidget *psWidget) {

	int32_t rectBtni32Width  = 120;
	int32_t rectBtni32Height = 40;
	int32_t rectBtni32X      = 160-rectBtni32Width/2;
	int32_t rectBtni32Y 	 = 120+rectBtni32Height/2;

	RectangularButtonInit(psWidget, &g_sKentec320x240x16_SSD2119, rectBtni32X, rectBtni32Y, rectBtni32Width, rectBtni32Height);
	PushButtonFillOn(psWidget);
	PushButtonFillColorPressedSet(psWidget, ClrYellow);
	PushButtonFillColorSet(psWidget, ClrWhiteSmoke);
	PushButtonOutlineOn(psWidget);
	PushButtonOutlineColorSet(psWidget, ClrBlack);
	PushButtonTextOn(psWidget);
	PushButtonFontSet(psWidget, g_psFontCm16);
	PushButtonTextColorSet(psWidget, ClrBlack);
	PushButtonTextOpaqueOn(psWidget);
	PushButtonAutoRepeatOn(psWidget);
	PushButtonImageOff(psWidget);
}

Then I call this function to initialize all my widgets, AND (here's where I go wrong ;)) then I use the struct of the Rectangular buttons to make further unique modifications, see below:

void init_AllGr(void) {

	GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
	GrContextFontSet( &sContext, g_psFontCm14);
	GrContextForegroundSet( &sContext, ClrBlack);
	GrContextBackgroundSet( &sContext, ClrGainsboro);
	FrameDraw(&sContext, "Hex Platform");

	init_CanvasGr(&g_IntroScreen);
	init_CanvasGr(&g_ModeScreen);
	init_CanvasGr(&g_LobbyScreen);
	init_CanvasGr(&g_GameScreen);

	init_RectBtnGr(&g_startBtn);
	g_startBtn.sBase.sPosition.i16YMax = (int16_t*)190;
	g_startBtn.sBase.psParent = (tCanvasWidget*)&g_IntroScreen;
	g_startBtn.sBase.psNext = &g_ModeScreen.sBase;
	g_startBtn.pcText="START";
	g_startBtn.pfnOnClick= &onbtnPress;

	init_RectBtnGr(&g_mode1Btn);
	g_mode1Btn.sBase.sPosition.i16YMin = 50;
	g_mode1Btn.sBase.psParent = &g_ModeScreen.sBase;
	g_mode1Btn.sBase.psNext = &g_LobbyScreen.sBase;
	g_mode1Btn.pcText="VS. HUMAN";
	g_mode1Btn.pfnOnClick= &onbtnPress;

	init_RectBtnGr(&g_mode2Btn);
	g_mode2Btn.sBase.sPosition.i16YMin = 120;
	g_mode2Btn.sBase.psParent = &g_ModeScreen.sBase;
	g_mode2Btn.sBase.psNext = &g_LobbyScreen.sBase;
	g_mode2Btn.pcText="VS. CPU1";
	g_mode2Btn.pfnOnClick= &onbtnPress;

	init_RectBtnGr(&g_mode3Btn);
	g_mode3Btn.sBase.sPosition.i16YMin = 190;
	g_mode3Btn.sBase.psParent = &g_ModeScreen.sBase;
	g_mode3Btn.sBase.psNext = &g_LobbyScreen.sBase;
	g_mode3Btn.pcText="VS. CPU2";
	g_mode3Btn.pfnOnClick= &onbtnPress;

	init_RectBtnGr(&g_connectBtn);
	g_connectBtn.sBase.sPosition.i16YMin = 190;
	g_connectBtn.sBase.psParent = &g_LobbyScreen.sBase;
	g_connectBtn.sBase.psNext = &g_GameScreen.sBase;
	g_connectBtn.pcText="CONNECT";
	g_connectBtn.pfnOnClick= &onbtnPress;

	init_HexBtnGr();
}

So do I only need to make one call to draw the parent/child hierarchy since parent is widget root? Maybe I can but I think i'm doing it wrong with the way I assign the parent/child relationship in the struct.. please halp :)

Also, to add on line 15 of the bottom code segment i cast to uint16_t, I comment out the other variables I assign through the struct for g_startBtn. The button does move from the initial position when I forcebly put it in by adding another widget add specifically for that variable.

  • Wow I just figured it out.. for I need to assign g_IntroScreen.sBase.psNext = (tPushButtonWidget*)&g_startBtn;

    okay, so to paint all from one call widget > psNext > widget

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.