Notifications
Clear all

[Closed] Accessing dynamic UI objects created with RolloutCreator

I’ve recently started learning about the Rollour Creator for dynamic UIs and have bumped into a little problem with the syntax of how to access the state of UI elements outside of a handler.

I’ve created the following example and the problem lies in the bSelectInvert pressed function where I need to access the state of the checkbox in order to know how to invert it. I am basically looking for a way of determining “CBi.state”. I feel like this is super easy and I’m just missing it but I’ve spent half the day on this and am out of options. I’m a newbie so any help at all is greatly appreciated.

	
global N = 10
global SubRollout1

global rcRollout1 = rolloutCreator  "SubRollout1" "Checkboxes" 
rcRollout1.begin()

for i = 1 to N do
(
	rcRollout1.addcontrol #checkbox ("CB" + i as string) "" paramStr: ("checked:true width:10 pos:[10," + ( (i-1) * 21 + 6) as string +"]")
	rcRollout1.addcontrol #label ("Label" + i as string) "true" paramStr: ("pos:[50," + ( (i-1) * 21 + 6) as string +"]")
	
	rcRollout1.addHandler ("CB" + i as string) #changed paramStr:"arg" codeStr: ("Label" + i as string + ".text = arg as string")
		
)
rcRollout1.end()
return (SubRollout1)
	
rollout roll ("Main Window")
(
	subrollout sro1 "SubRollout1" height:300
	button bSelectAll "Select All" 
	button bSelectNone "Deselect All"
	button bSelectInvert "Invert Selection"
		
	on bSelectAll pressed do
	(
		for i = 1 to N do
		( 
			execute ("SubRollout1.CB" + i as string +".checked = true")
		)
	)
		
	on bSelectNone pressed do
	(
		for i = 1 to N do
		( 
			execute ("SubRollout1.CB" + i as string +".checked = false")
		)
	)
			
	on bSelectInvert pressed do
	(
		for i = 1 to N do
		( 
			--these don't work
			if ("SubRollout1.CB" + i as string +".checked") == true 	then (execute ("SubRollout1.CB" + i as string +".checked = false"))
			if ("SubRollout1.CB" + i as string +".checked") == false	then (execute ("SubRollout1.CB" + i as string +".checked = true"))
					
		)
	)
)

CreateDialog roll width:200 height:400 
addSubrollout roll.sro1 SubRollout1
2 Replies

You missed execute (and the second line should be an else branch, otherwise it won’t switch them, rather switch them all on). On the other hand, you don’t need execute at all:

	fn getCheckBoxes pattern =
 		for ctrl in SubRollout1.controls
 			where isKindOf ctrl CheckBoxControl and matchPattern ctrl.name pattern:pattern
 				collect ctrl
 		
 	on bSelectAll pressed do
 		(getCheckBoxes "CB*").checked = true
 		
 	on bSelectNone pressed do
 		(getCheckBoxes "CB*").checked = false
 			
 	on bSelectInvert pressed do
 		for chx in (getCheckBoxes "CB*") do chx.checked = not chx.checked

Thank you Swordslayer! This is similar to what I came up with last night before falling asleep where I just create an array that holds the state of the checkbox and the handler updates the array when it is toggled and any function that needs the state of the CB just pulls it from the array rather than the actual cb. It is sort of obvious but I was just attacking it from the wrong direction. Your solution is much more elegant though – THANKS!