Game Development Community

guiScrollCtrl, guiTextListCtrl, and relative sizing

by Lucas Goss · in Torque Game Engine · 02/10/2002 (3:55 pm) · 3 replies

Well if you have a scroll control with a relative sizing and a text list control that is set to fit the parent width the text list control won't render properly (I would show an image but I have no website to put it on...doh). Anyways this was a pain to work through so I figured I should post my findings (I'll try to keep this short but detailed).

Where it goes wrong...
Basically the sizes of the controls are computed when onWake is called, but after that the screen is resized (default is 640x480 to 800x600 but depends on which resolution you have set). When the screen is resized then parentResized is called for the scroll control which then calls resize for the scroll. Resize then calls the parentResized for the text list control which then calls resize. This all returns back to the scroll control parentResized where it then calls computeSizes() which calculates the contentExt, or content extent. The content extent is used to compute the bounds of the text list control when it is set to fitParentWidth, but the text list control is not updated again to reflect the new changed state of the scroll control. If you've followed that at all congratulations...haha.

Fixing the problem...
In guiScrollCtrl.cc add-
void GuiScrollCtrl::resize(const Point2I &newPos, const Point2I &newExt)
{
   Parent::resize(newPos, newExt);
   computeSizes();
   [b]Parent::resize(newPos, newExt);[/b]
}

then in guiTextListCtrl.h add-
class GuiTextListCtrl : public GuiArrayCtrl
{  ...
   [b]void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);[/b]
   ...
}

then in guiTextListCtrl.cc add-
[b]void GuiTextListCtrl::parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent)
{
	GuiControl::parentResized(oldParentExtent, newParentExtent);
	setSize(mSize);
}[/b]

And that should do it. I can now sleep again. Comments, suggestions, questions, criticism, ...all is welcome.

About the author

Recent Threads

  • playAudio Problem

  • #1
    07/06/2003 (6:47 am)
    I have noticed another problem:

    When guiTextListCtrl is resized all columns offsets remain unchanged. I think, each column should be resized as well...

    Regards

    Roman
    #2
    07/06/2003 (10:38 pm)
    Here is my quick solution that solves above problem:

    void GuiTextListCtrl::parentResized( const Point2I &oldParentExtent, const Point2I &newParentExtent )
    {
        Parent::parentResized(oldParentExtent, newParentExtent);
    
        if( oldParentExtent.x && ( oldParentExtent.x != newParentExtent.x ) )
        {
            S32 nColumns = mColumnOffsets.size();
            for( U32 k = 0; k < nColumns; ++k )
            {
                F32 percent = (F32)mColumnOffsets[k] / oldParentExtent.x;
    			    mColumnOffsets[k] = (S32)( percent * newParentExtent.x );
            }
        }
    
        setSize( mSize );
    }

    Roman
    #3
    08/11/2007 (12:57 am)
    Its 2007 and this is still not in the source?

    This really needs to be added. It still works wonderfully with 1.5.2.

    Thanks Roman.