[fixed]IGUIEditBox scrolling bug

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
Mloren
Posts: 114
Joined: Mon Aug 07, 2006 2:30 am
Location: Australia
Contact:

[fixed]IGUIEditBox scrolling bug

Post by Mloren »

When a multiline edit box has enough text in it to go off the bottom of the edit box and then you use the arrow keys to scroll down, the scrolling behaves strangely.

When moving the cursor down line by line, the text doesn't scroll until you move the cursor down below the last visible line, at which point it scrolls down to keep the cursor in view. But when you then start scrolling up, it scrolls up immediately when you move up a line rather than the proper behavior which would be to not scroll until the cursor is moved above the top most visible line.

I found a fix for this so here it is :)

(This code is based on the 1.7 branch)
In CGUIEditBox, in the calculateScrollPos() function, this is the incorrect code:

Code: Select all

 
if (FrameRect.LowerRightCorner.Y < CurrentTextRect.LowerRightCorner.Y + VScrollPos)
        VScrollPos = CurrentTextRect.LowerRightCorner.Y - FrameRect.LowerRightCorner.Y + VScrollPos;
 
else if (FrameRect.UpperLeftCorner.Y > CurrentTextRect.UpperLeftCorner.Y + VScrollPos)
        VScrollPos = CurrentTextRect.UpperLeftCorner.Y - FrameRect.UpperLeftCorner.Y + VScrollPos;
else
        VScrollPos = 0;
 
Should be:

Code: Select all

 
if (CurrentTextRect.LowerRightCorner.Y > FrameRect.LowerRightCorner.Y)
        VScrollPos = CurrentTextRect.LowerRightCorner.Y + VScrollPos - FrameRect.LowerRightCorner.Y;
else if (CurrentTextRect.UpperLeftCorner.Y < FrameRect.UpperLeftCorner.Y)
        VScrollPos = CurrentTextRect.UpperLeftCorner.Y + VScrollPos - FrameRect.UpperLeftCorner.Y;
 
Might need a similar fix on the horizontal scrolling as well but I don't have a test case for that so I haven't looked at fixing it.
Mloren
Posts: 114
Joined: Mon Aug 07, 2006 2:30 am
Location: Australia
Contact:

Post by Mloren »

The fixed code is included in this patch:
http://irrlicht.sourceforge.net/phpBB2/ ... 534#240534

Also I discovered a bug that made the text juggle up and down as you typed, its fixed in the patch.

To fix it in the above code, it should be:

Code: Select all

if (!WordWrap)
{
	//horizontal scrolling code is here
}
else if (WordWrap || MultiLine)
{
	// vertical scroll position
	if (CurrentTextRect.LowerRightCorner.Y > FrameRect.LowerRightCorner.Y)
		VScrollPos = CurrentTextRect.LowerRightCorner.Y + VScrollPos - FrameRect.LowerRightCorner.Y;
	else if (CurrentTextRect.UpperLeftCorner.Y < FrameRect.UpperLeftCorner.Y)
		VScrollPos = CurrentTextRect.UpperLeftCorner.Y + VScrollPos - FrameRect.UpperLeftCorner.Y;
}
Basically if Word Wrap or Multiline is not enabled, you don't want to do that code.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IGUIEditBox scrolling bug

Post by CuteAlien »

*sigh* ... that looked so simple. But I've spend now last 6 hours on this - getting all cases correct including deleting lines and it working with small rectangles etc. is not so trivial. I found several solutions which _nearly_ worked, but always something was off.

Have to give up for today, but at least got some testcase, although it still doesn't test everything (differnt alignment still missing - which also affects this):

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, 600));
        if (device == 0)
                return 1; // could not create selected driver.
 
        video::IVideoDriver* driver = device->getVideoDriver();
        IGUIEnvironment* env = device->getGUIEnvironment();
        IGUIFont * font = env->getSkin()->getFont();
 
        s32 height = font->getDimension(L"A").Height + font->getKerningHeight();
 
        core::rect< s32 > rectEditBox(10, 20, 80, 20+height);
        IGUIEditBox * edit1 = env->addEditBox (L"", rectEditBox, true, 0, -1);
        edit1->setMultiLine(true);
        edit1->setWordWrap(true);
 
        rectEditBox += position2di(0, 100);
        rectEditBox.LowerRightCorner.Y = rectEditBox.UpperLeftCorner.Y + height+6;
        IGUIEditBox * edit2 = env->addEditBox (L"", rectEditBox, true, 0, -1);
        edit2->setMultiLine(true);
        edit2->setWordWrap(true);
 
        rectEditBox += position2di(0, 100);
        rectEditBox.LowerRightCorner.Y = rectEditBox.UpperLeftCorner.Y + height-1;
        IGUIEditBox * edit3 = env->addEditBox (L"", rectEditBox, true, 0, -1);
        edit3->setMultiLine(true);
        edit3->setWordWrap(true);
        edit3->setAutoScroll(true);
 
        rectEditBox += position2di(0, 100);
        rectEditBox.LowerRightCorner.Y = rectEditBox.UpperLeftCorner.Y + 3*height;
        IGUIEditBox * edit4 = env->addEditBox (L"", rectEditBox, true, 0, -1);
        edit4->setMultiLine(true);
        edit4->setWordWrap(true);
        edit4->setAutoScroll(true);
 
        rectEditBox += position2di(0, 100);
        rectEditBox.LowerRightCorner.Y = rectEditBox.UpperLeftCorner.Y + 6*height;
        IGUIEditBox * edit5 = env->addEditBox (L"", rectEditBox, true, 0, -1);
        edit5->setMultiLine(true);
        edit5->setWordWrap(true);
        edit5->setAutoScroll(true);
 
 
        while(device->run() && driver)
        {
                if (device->isWindowActive())
                {
                        driver->beginScene(true, true, SColor(0,50,100,200));
 
                        env->drawAll();
 
                        driver->endScene();
                }
        }
 
        device->drop();
 
        return 0;
}
 
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:

Re: IGUIEditBox scrolling bug

Post by CuteAlien »

A fix which at least makes autoscrolling behave somewhat sane is now in svn releases/1.7 branch and svn trunk will follow soon as usual. There's still a bunch of things which should be improved (like scrolling to the left should show more text for example), but I think it needs to be rewritten in large parts anyway and that is stuff that needs to be done in trunk. And you don't even want to know how many hours fixing that stuff needed ... *sigh* ... sorry for taking that long.
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
Post Reply