Page 1 of 1

autoscroll and no horiz scrollbar for Listbox

Posted: Mon Nov 12, 2007 17:25
by rogerdv
I need to remove the horizontal scroll for a listbox, and scroll the text whenever I add a new text line. How can I do this?

Posted: Tue Nov 13, 2007 00:13
by Pompei2
Is this for a chat ?

Code: Select all

    try {
        LB->addItem(this);

        // Care to not overfill the listbox.
        while(LB->getItemCount() > D_MAX_CHAT_ENTRIES) {
            LB->removeItem(LB->getListboxItemFromIndex(0));
        }

        LB->ensureItemIsVisible(this);
    } catch(CEGUI::Exception & e) {
        FTS18N("CEGUI", FTS_ERROR, e.getMessage().c_str());
    }


This is a code snippet from my chat handling listbox. It does add a new item to the listbox (the new item being "this"), scroll the listbox down so the new item can be seen (ensureItemIsVisible) and also cares to not over-fill the listbox, else CEGUI gets very slow !! 100 is a good value for D_MAX_CHAT_ENTRIES.


In the default TaharezLook listbox, there seems to be no way to suppress the horizontal scrollbar, you will need to create your own look'n'feel file for the listbox. It's not too hard ;)

Posted: Thu Nov 15, 2007 19:53
by rogerdv
No, it is an RPG. I need a continuous flow of ingame messages on that listbox, and the only solution I see to avoid scrolling horizontally is to expand the width.

Posted: Fri Nov 16, 2007 09:53
by CrazyEddie
The 'right' way that you should be able to get it to work is by writing a customised item for the list box that has a fixed width (and that wraps the content as needed), this would ensure that there is never any need to scroll horizontally.

The 'hacky' way is to pre-process the item lines to be added, splitting them into multiple items (lines) before adding them.