[no bug]GUI Alignments Failure

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
brferreira
Posts: 5
Joined: Wed Mar 03, 2010 5:45 pm

[no bug]GUI Alignments Failure

Post by brferreira »

Whenever using IGUIElement::setAlignment(), the alignment changes aren't updated. Also, EGUIA_CENTER and EGUIA_LOWERRIGHT doesn't seem to work.

Patch file can be found here: http://sourceforge.net/tracker/index.ph ... tid=540676

A chunk of code that should show the bug:

Code: Select all

// Display a hello world message on the screen's center
IGUIElement *e = device->getGuiEnvironment()->addStaticText( L"Hello world!", irr::core::rect<s32>(-50,-25,50,25) );
e->setAlignment( irr::gui::EGUIA_CENTER,irr::gui::EGUIA_CENTER,irr::gui::EGUIA_CENTER,irr::gui::EGUIA_CENTER);
with the new behavior, the position relative to the center or lower right corner is correctly calculated.

This bug has been tested and confirmed on both 1.7.1 release and trunk SVN.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Wow, the problems with center and lowerright look rather bad. I try to look into it asap. The additional updateAbsolutePosition() looks fine to me - the other changes, well, I have to investigate first what went wrong there. I'm using center and lowerright a lot in my own projects, which use an Irrlicht not too old, but before the 1.7 release. I want to find out first why that is going wrong suddenly.

Thanks a lot for reporting and proposing the patches. I've seen it already on the tracker, but simply found no time the last weeks as I was hard working on finishing some project (still some work left there, but this is important enough that I try to find some time this week).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ok, not a bug, although I also got confused for a moment. But this is just a misunderstanding on what the alignment is meant to do. Alignment is not a way to change the position of an element, but to define the behavior when the parent is resized.

And it does that already correctly:

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif


int main()
{
	video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
	IrrlichtDevice * device = createDevice(driverType, core::dimension2d<u32>(640, 480));
	if (device == 0)
		return 1; // could not create selected driver.

	video::IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

    IGUIElement *p = env->addStaticText( L"", irr::core::rect<s32>(0,0,50,50), true );
    IGUIElement *e = env->addStaticText( L"Hello world!", irr::core::rect<s32>(0,0,50,50), true, true, p );
    e->setAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);    
    p->setRelativePosition( irr::core::rect<s32>(0,0,400,400) );

	while(device->run() && driver)
	{
		if (device->isWindowActive())
		{
			driver->beginScene(true, true, SColor(0,200,200,200));
	
			env->drawAll();
		
			driver->endScene();
		}
	}

	device->drop();

	return 0;
}
That's also why updateAbsolutePosition is not needed there. Because just setting a new alignment won't affect the current positions and also should not do so.

edit: But I just noticed it has no documentation whatsoever. Which is certainly something which must be changed.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
brferreira
Posts: 5
Joined: Wed Mar 03, 2010 5:45 pm

Post by brferreira »

Let me explain better the problem:

I am making a GUI that is loaded dynamically (I'm using the irr::gui::IGUIEnvironment::loadGUI()) and it *must* work for every single available resolution and aspect ratios. If the GUI is directly loaded from the file (I did not test any other case actually), no matter what, the buttons will have a position relative to the upper-left corner. After applying that patch, that problem is solved, that means, the positions specified are relative to where the user wants (center, lower right or upper left). In my opinion, it is more useful to be this way than just resizing/repositioning the IGUIElement whenever the window resizes.

So, the current "alignment" should be instead called "anchoring" or something like that.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Yes, but when your user resizes your window you will get in trouble. But the current solution works in both cases - you just have to do some minor change. Use one element as root which has a fixed resolution. And then resize that element to the size of the screen resolution once after loading. Actually I use one such root element per gui-dialog.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
brferreira
Posts: 5
Joined: Wed Mar 03, 2010 5:45 pm

Post by brferreira »

I just noticed how this change broke most of GUI elements.

I shall try making that GUI in other way
Post Reply