Notifications
Clear all

[Closed] how to access numbered rollout elements?

Hi all,
how can I access a rollout element whose name needs to be composed with the value of a variable, like in this case:

global testRollout

rollout testRollout "a test" (
   button btn1 "buton1" 
   button btn2 "buton2" 
   button btn3 "buton3" 
)

fn changeButtonCaption ind = (
   --how can i change here the caption of the correct button (in this case, it would be btn2 as ind=2...)
   testRollout.btn+i.caption = "it worked"     --of course this does not work...
)

testFloater = newrolloutfloater "Exportador de assets" 300 500
addrollout testRollout testFloater

changeButtonCaption 2

5 Replies

Use this as a reference:


global testRollout

rollout testRollout "a test" (
   button btn1 "buton1" 
   button btn2 "buton2" 
   button btn3 "buton3" 
)

fn changeButtonCaption ind = (
   --how can i change here the caption of the correct button (in this case, it would be btn2 as ind=2...)
	for c in testrollout.controls do
	(
		if classof c == buttonControl do
		(
			if c.name == "btn2" do c.text = "New Name"
		)
	)
)

testFloater = newrolloutfloater "Exportador de assets" 300 500
addrollout testRollout testFloater

changeButtonCaption 2

that worked great, thanks!

I didn’t remember the ‘controls’ property. Thanks @miauu.

Here’s a code that allows changing nearly everything of the rollout, all in a single global. Perhaps it can help someone.



	global testRollout
	(
		struct testRolloutST
		(
			testFloater,
			floaterTitle = "Exportador de assets",
			floaterSize = [300, 500],
			floaterPos = [200,200],
			rolloutTitle = "a test",
			UINames = #("button1", "button2", "button3", "Axis"),

			testRollout1 = rollout testRollout1 rolloutTitle
			(
				button btn1 UINames[1] 
				button btn2 UINames[2]
				button btn3 UINames[3]
				radiobuttons rdb_test  UINames[4] labels:#("X", "Y", "Z")
			),

			fn changeUICaption ind newCaption =
			(
				testRollout1.UINames[ind] = newCaption
				testrollout1.controls[ind].text = newCaption
			),
			
			fn destroyFloater = 
			(
				try
				(
					floaterSize = ::testRollout.testFloater.size
					floaterPos = ::testRollout.testFloater.pos
					closeRolloutFloater testFloater
				)
				Catch()
			),

			fn createFloater =
			(
				destroyFloater()
				testFloater = newrolloutfloater floaterTitle floaterSize.X floaterSize.Y
				testFloater.pos = floaterPos
				addrollout testRollout1 testFloater
			),
			
			on create do 
			(
			)
		)
		
		testRollout = testRolloutST()
	)
	
	--	UINames initial values
	format "testRollout UINames= %
" testRollout.UINames
	
	--	Change UINames before creating FloaterRollout if needed
	testRollout.changeUICaption 2 "New Button2"
	format "testRollout UINames= %
" testRollout.UINames
	
	testRollout.createFloater()
	
	--	Change UINames after creating FloaterRollout
	testRollout.changeUICaption 2 "Re-New Button2"
	testRollout.changeUICaption 4 "New Axis"
	format "testRollout UINames= %
" testRollout.UINames
	
	--	Resize, move and Close FloaterRollout
	testRollout.testFloater.size = [300,300]
	testRollout.testFloater.pos = [800,200]
	testRollout.destroyFloater()
	
	-- 	Create FloaterRollout again. UINames, position and size are the same than the last time
	-- 	Change FloaterRollout and Rollout Titles
	testRollout.floaterTitle = "Exportador de assets 2"
	testRollout.rolloutTitle = "a test 2"
	testRollout.createFloater()


2 Replies
(@miauu)
Joined: 11 months ago

Posts: 0

I use the controls property all the time. Especially when I have to save and load settings of an rolout.


(
	--	load settings
	on rol_MyRollout open do
	(
		for c in rol_MyRollout.controls do
		(
			case classof c of
			(						
				CheckBoxControl: c.state = (readValue ((getIniSetting iniFile "Settings" c.name) as stringStream))
				EditTextControl: c.text = ((getIniSetting iniFile "Settings" c.name) as string)
				ColorPickerControl: c.color =  (readValue ((getIniSetting iniFile "Settings" c.name) as stringStream))
				SpinnerControl: c.value = (readValue ((getIniSetting iniFile "Settings" c.name) as stringStream))
			)	
		)
	)
	--	save settings
	on rol_MyRollout close do
	(
		for c in rol_MyRollout.controls do
		(
			case classOf c of
			(
				CheckBoxControl: (setIniSetting iniFile "Settings" c.name (c.state as string))
				EditTextControl: (setIniSetting iniFile "Settings" c.name (c.text))
				ColorPickerControl: (setIniSetting iniFile "Settings" c.name (c.color as string))
				SpinnerControl: (setIniSetting iniFile "Settings" c.name (c.value as string)) 
			)
		)
	)
)

(@aaandres)
Joined: 11 months ago

Posts: 0

That’s magic! Not only the use of ‘controls’ for saving and loading (I use to saving every parameter one by one), but the use of ‘readValue — as stringStream’ to convert string to value.
Thanks again, @miauu. I allways learn from you.