Game Development Community

dev|Pro Game Development Curriculum

guiScrollCtrl auto-scrollToBottom

by Fyodor -bank- Osokin · 08/17/2006 (12:09 pm) · 3 comments

Have you ever used guiMLTextCtrl with guiScrollCtrl, but after adding text, it always just to top? Here is a fix.
This is based on guiMLTextCtrl qustion thread. Using Owen's fix, I've just added an option to tell the engine - do I need or not the "auto-scrolling to bottom". I'm using this for chat in game - works perfectly.

Here is a code:
in guiSCrollCtrl.h after:
bool mWillFirstRespond;     // for automatically handling arrow keys
add:
bool mAutoBottom;     // do we need to scroll to bottom automatically?
in guiSCrollCtrl.h in function GuiScrollCtrl::GuiScrollCtrl() after:
mWillFirstRespond = true;
add:
mAutoBottom = false;
in guiSCrollCtrl.h in function void GuiScrollCtrl::initPersistFields() after:
addField("willFirstRespond",     TypeBool,    Offset(mWillFirstRespond, GuiScrollCtrl));
add:
addField("autoBottom",           TypeBool,    Offset(mAutoBottom, GuiScrollCtrl));
then, make your void GuiScrollCtrl::childResized(GuiControl *child) function to look like:
void GuiScrollCtrl::childResized(GuiControl *child)
{
   Parent::childResized(child);
   computeSizes();
   if (mAutoBottom) scrollTo( 0, 0x7FFFFFFF );
}

Update your guiMLTextCtrl.cc in void GuiMLTextCtrl::reflow() there's a call to ensureCursorOnScreen() - just comment out it.

Clean/rebuild. Then, while you design your GUI, you will have a checkbox where you can enable/disable that parameter. If enabled - it will auto-scroll/jump to bottom.

#1
09/30/2007 (3:07 pm)
There are some slight problems with this resouces. First, the directions say to edit "guiSCrollCtrl.h" but it should be guiSCrollCtrl.c for everything other than the header declaration at the top (bool mAutoBottom).

Second, when used with an GuiMLTextCtrl, you will need to force a reflow of the window to get your results. Thus, if your control is called zippy, you will need to use:

zippy.forceReflow();

That being said, I rated it very high because using this gets rid of having to use a messageVector for chatting and command line intertfaces. The messageVector is limited to colors and linking -- this edit allows unlimited color customization as well as the stepping stone to allow people to click on certain thing to pop up a window (great for stats, encyclopedia, etc).
#2
08/30/2008 (1:01 pm)
Thanks for this--works great!
#3
11/13/2015 (9:55 pm)
Works beautifully! Thank you for this.