[Closed] Best setup for complex dynamic rollout
Thanks for your help.
How would you re-write your sample code if instead of creating a messagebox as button function, pressing the button would lead to change the button text itself or a lable within the rollout?
Well if all you want to do is change a label or button’s text, then you don’t need to rebuild the rollout at all…
rollout test "test" (
button btn_doit "press me!"
on btn_doit pressed do (
btn_doit.text = "press me again! (" + timeStamp() as string + ")"
)
)
createDialog test
I would like to have the code of your first example combined with the second one. Means if you press e.g. Button 4, which you created through the “do it” button of the first sample code, the text of button 4, and only of button 4, is changed.
something like this, perhaps…
globCounter = 1
globUILabels = #()
fn buildRollout = (
s = stringStream ""
format "rollout test \"test\" (
" to:s
format "button btn_doit \"do it\"
" to:s
for i = 1 to globCounter do (
local caption = globUILabels[i]
if (caption == undefined) then ( caption = "button " + i as string )
format "button btn_% \"%\"
" i caption to:s
format "on btn_% pressed do (
" i to:s
format " btn_%.caption = \"button % - \" + localtime
" i i to:s
format " globUILabels[%] = btn_%.caption
" i i to:s
format ")
" to:s
)
format "on btn_doit pressed do (
" to:s
format " globCounter += 1
" to:s
format " destroyDialog test
" to:s
format " buildRollout()
" to:s
format " CreateDialog test
" to:s
format ")
" to:s
format ")
" to:s
execute (s as string)
)
buildRollout()
createDialog test
Which stores the current UI item labels/etc. when they get changed. An alternative would be to loop over all the UI items when the rollout is closed (on rollout close ( do something with rollout.controls )) and grab the bits and pieces you’d want to retain when re-building the rollout then.
Things get more complex quickly, though, and abstract pieces of code may lead you down the wrong path… if you’re trying to do something specific, you may wish to ask specific questions
Hi,
as far as I see it, this is the approach I chose myself in the current version of my script. It is fine, everything is working, but like you said, it became really complex and I was wondering whether there are some obvious steps, which I might have missed to improve the script. But now I think I will just leave at it is.
Another question I have though, if you don’t mind. Now, I am working on another rollout, nothing fancy or dynamic but I am trying to built the code as elegant and efficiently as possible to imporve my scripting skills. I thought I would make a struct that contains all the functionality then create an instance of that struct and then create the rollout. But that is not working as some of the functions need to be defined before the rollout definition in order to be available for the rollout, and some function need to be declared AFTER the rollout as the functions use the rollout properties. Do I have to do it this way, with function on two places in my script or is there a better way? Here some sample of what I mean.
(
struct testManager
(
myObjs = #(),
fn fnInit = (
myObjs = for o in objects /*where ( (classof o == PointHelperObj) and (custAttributes.getDefs o != undefined) ) */ collect o.name
)
)
local stTestManager=(testManager())
stTestManager.fnInit()
rollout rl_testManager "Object Manager" width:400 height:232 (
listBox lbx_objlist "" pos:[8,32] width:140 height:14 items:stTestManager.myObjs
label lbl_display "Status:" pos:[10,10] width:35 height:15
label lbl_model "" pos:[50,10] width:200 height:15
struct testProcess (
fn fnSetStatus str = (
lbl_display.text = str
)
)
on objectManager open do (
local stTestProcess=(testProcess())
testProcess.fnSetStatus "test"
)
on lbx_objlist selected nameIndex do (
lbl_model.text = toUpper ( lbx_objlist.items[nameIndex] )
)
)
createDialog rl_testManager
)
This sample is simplified and I do need both the functionality to initialize values for the rollout and then functions that work with the rollout’s properties.
Does this mean I have to defined the functions in two different places?