Listbox auto scrolling

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Listbox auto scrolling

Post by monkeycracks »

CGUIListBox.cpp

In both the addItem();'s right before it return's do this :

Code: Select all

if(AutoScroll == true){
	ScrollBar->setPos(ScrollBar->getPos()+Font->getDimension(L"A").Height + 4);}
Add this somewhere :

Code: Select all

bool CGUIListBox::setAutoScrolling(bool autoScroll)
{
AutoScroll = autoScroll;
}
CGUIListBox.H

In the public:

Code: Select all

virtual bool setAutoScrolling(bool autoScroll);
In the private:

Code: Select all

bool AutoScroll;
IGUIListBox.H

Code: Select all

virtual bool setAutoScrolling(bool autoScroll) = 0;

Also, in the constructor for CGUIListBox you can set AutoScroll to be false or true by default.

Now you've got autoscrolling listboxes when you add the items.
Last edited by monkeycracks on Sun Mar 04, 2007 8:34 am, edited 1 time in total.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Updated.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

gui is in the process of being rewritten entirly.

there are easier ways without recompiling the engine also.

Code: Select all

	list<gui::IGUIElement*>::Iterator it = Console->getChildren().getLast();
	gui::IGUIScrollBar* scrollbar = static_cast<gui::IGUIScrollBar*>(*it);
	scrollbar->setPos(0x7FFFFFFF);
MickeyKnox
Posts: 58
Joined: Tue Apr 10, 2007 7:49 pm
Location: Karlsruhe

Post by MickeyKnox »

hm.. This thread is a little old, but it seems to be the right one for my question.
I observed, that autoscrolling was added to the new release of the engine.
Unfortunately, it does just nothing.
What am i missing?

I keep just adding items to the listbox, but the scrollbar stays always on top.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Sorry it took so long to respond, I've been shunning the Irrlicht forums lately. Try implementing the older method above, and if it gives you problems I'll look into it more, but that method worked for me.
MickeyKnox
Posts: 58
Joined: Tue Apr 10, 2007 7:49 pm
Location: Karlsruhe

Post by MickeyKnox »

I hacked midnights method in my code rightnow, it works.
I had to use the ConstIterator to avoid compiler errors, thought.

Nevertheless, a look in the API suggests, that autoscrolling was already
added. But calling setAutoScrollEnabled(true) has no effect for me.
hollowi
Posts: 1
Joined: Tue Sep 02, 2008 3:28 am

Post by hollowi »

if( event.GUIEvent.EventType == irr::gui::EGET_EDITBOX_ENTER )
{
switch(event.GUIEvent.Caller->getID()
{
case GUIID_LOBBY_EDT_CHAT:
// something add..
pListbox->addItem(L"ChatMsg");

// get current itemcount.
pListbox->setSelected(pListbox->getItemCount());
}
}

selected last item of the Listbox,
as a result the scrollbar stays on bottom.
Post Reply