Jump to content
Kirill

Bug in example

Recommended Posts

Hi, I figured out some strange behaviour 

I tried to do example from here https://wiki.ugfx.io/index.php/List

In example:

static void createWidgets(void) {
	GWidgetInit	wi;
 
	// Apply some default values for GWIN
	wi.customDraw = 0;
	wi.customParam = 0;
	wi.customStyle = 0;
	wi.g.show = FALSE;
 
	// Apply the list parameters
	wi.g.width = 200;
	wi.g.height = 100;
	wi.g.y = 10;
	wi.g.x = 10;
	wi.text = "List Name";
 
	// Create the actual list
	ghList1 = gwinListCreate(NULL, &wi, FALSE);
}

There are no wi.g.parent set.

So during initialisation we add widget to windowManager using this function:

bool_t _gwinWMAdd(GHandle gh, const GWindowInit *pInit) {
	#if GWIN_NEED_CONTAINERS
		// Save the parent
		gh->parent = pInit->parent;

		// Ensure the display is consistent with any parents
		if (gh->parent && (!(gh->parent->flags & GWIN_FLG_CONTAINER) || gh->display != gh->parent->display))
			return FALSE;
	#endif

	// Add to the window manager
	if (!_GWINwm->vmt->Add(gh, pInit))
		return FALSE;

	#if GWIN_NEED_CONTAINERS
		// Notify the parent it has been added
		if (gh->parent && ((gcontainerVMT *)gh->parent->vmt)->NotifyAdd)
			((gcontainerVMT *)gh->parent->vmt)->NotifyAdd(gh->parent, gh);
	#endif

	return TRUE;
}

Look at this condition:

if (gh->parent && (!(gh->parent->flags & GWIN_FLG_CONTAINER) || gh->display != gh->parent->display))
			return FALSE

If parent not NULL it started to check display and display not equal (actually it is just a trash)

To fix that behaviour need to clean parent (wi.g.parent = NULL;)

I think we should have function to clean Widget structure before initialise.

Share this post


Link to post
Share on other sites

I think example should be like this:

static void createWidgets(void) {
	GWidgetInit	wi;
        gwinWidgetClearInit(&wi);

	// Apply the list parameters
	wi.g.width = 200;
	wi.g.height = 100;
	wi.g.y = 10;
	wi.g.x = 10;
	wi.text = "List Name";
 
	// Create the actual list
	ghList1 = gwinListCreate(NULL, &wi, FALSE);
}

Share this post


Link to post
Share on other sites

Thank you for bringing this to our attention!

As you mentioned yourself there is the need to clean the widget initialization structure prior to using it. 
We have updated the example code in the wiki.

Share this post


Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...