Game Development Community

[Beta 5 Bug] guiScrollCtrl messed up child positions on addObject()

by Tim Reinermann · in Torque 3D Professional · 08/13/2009 (7:29 am) · 7 replies

Hi there,

I tried to dynamicly add a list of GuiBitmapButtonTextCtrls into a ScrollCtrl, but the buttons positions get totally messed up. Adding the buttons to the main control works just fine. I guess its a problem with "void GuiScrollCtrl::computeSizes()". I would debug it myself, but I just started working with Torque3D and its GUI architecture, and the function mentioned is missing some comments ...

I uploaded a samplegui with functions to reproduce this bug:

torque.abigholeintheweb.com/public_system/useruploads/Ci_ScrollTest.zip

  • Open Ci_ScrollTest.gui with the GuiEditor
  • Start the gui
  • open console
  • execute Ci_ScrollTest.test(); or Ci_ScrollTest.testTwo();
  • close console to see results

This might be a related topic/problem:

www.garagegames.com/community/forums/viewthread/78170

#1
08/13/2009 (2:04 pm)
I have never used it myself but try taking a look at the GuiArrayCtrl.
#2
08/13/2009 (2:23 pm)
GuiScrollCtrl is never meant to hold more than one control, as it works for one control by looking at it's sizes and the need of actual "scrolling".

I would recommend placing GuiStackCtrl inside GuiScrollCtrl, and move all your objects in that GuiStackCtrl, this way they will line-up correctly.

I'm using it a lot and never met problems.
#3
08/14/2009 (12:26 am)
Quote:GuiScrollCtrl is never meant to hold more than one control, as it works for one control by looking at it's sizes and the need of actual "scrolling".

Sure? guiScrollCtrl.cpp:165ff, seems to try to handle multiple child controls. If its supposed to support only one, this should be asserted.

But thanks for your workaround :)
#4
08/14/2009 (2:07 am)
hmm.. bool GuiScrollCtrl::calcChildExtents() is running through the "list" of control, so looks I was wrong in my previous post. Actually, I never noticed that code until you pointed :) thanks, will try to play around with it and see what's wrong with that...

But anyway, using GuiStackCtrl or GuiArrayCtrl* as a handlers for lots of control is more easy than placing controls "by hand" if you have many of them. Both, GuiStackCtrl and GuiArrayCtrl are for automatic, "easy of use", placement of multiple control, so I don't see a reason of having Scroll to handle those.
You just create your buttons (or bitmaps or whatever...) and push it to the stock: %myStock.add(%myButton);
Put your stock inside scroll, and everything else will be done automatically, no need to calculate sizes/position manually, etc.
Look at
function WorldEditorInspectorPlugin::onWorldEditorStartup( %this )
in tools/worldEditor/scripts/EditorGui.ed.cs:
ToolsToolbarArray.add(%button);
and see how it's done (filling toolbar with buttons).
"ToolsToolbarArray" is "GuiDynamicCtrlArrayControl" (another helper like guiStack).
Everything inside "tools/" is a great example on how to use scripting together with dynamic GUIs. There is a lot of useful code, so, take your tea/coffee/beer and spend a few hours running though those guis and scripts.
#5
08/17/2009 (6:26 pm)
Logged as THREED-669
#6
08/17/2009 (8:59 pm)
my understanding from TGE was the GuiScrollCtrl only wants to have one child as well; but maybe that's changed.

> But anyway, using GuiStackCtrl or GuiArrayCtrl* as a handlers for lots of control is more easy than placing controls "by hand" if you have many of them.

or GuiArray2Ctrl ! ;)
#7
01/25/2010 (2:14 pm)

Fixed for next release.

Still, adding only one child is usually the correct thing. To put compound controls inside a scroller, simply wrap them in a GuiControl container.