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:
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.
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 keysadd:
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.
About the author
Game developer.

Torque Owner Chris Fitzgerald
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).