Notifications
Clear all

[Closed] So what is going on here?

 PEN

Run the code below and press the button. It will load in rollout into the sub rollout and size the sub rollout to the width of the rollout. Now press it again and again. The sub keeps getting smaller because the width returned from the rollout keeps getting smaller. The rollout is recreated each time so how is this possible?


clearListener()

fn sub1Fn = 
(
	rollout sub1 "Sub 1" width:100
	(
		
	)
	print sub1.width
	sub1
)

rollout mainR "Main" width:300 height:220
(
	button addSub1Bt "Add Sub 1" align:#left across:2
	subRollout subRoll "" width:200 height:200 offset:[-60,-25]
	
	on addSub1Bt pressed do
	(
		s=sub1Fn()
		removeSubRollout subRoll s
		mainR.subRoll.width=s.width
		addSubRollout subRoll s
		print s.width
	)
)

createDialog mainR

13 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0
	on addSub1Bt pressed do
  	(
  		s=sub1Fn()
  		removeSubRollout subRoll s
  		mainR.subRoll.width=s.width
  		addSubRollout subRoll s
  		print s.width
  	)
  

check what happens here… you create new rollout, try to remove it from sub rollout, it doesn’t work because it doesn’t exist, you try to add new rollout, and it doesn’t work because the system thinks it’s still there… i don’t have max to check by try these two things:

removeSubRollout subRoll subRoll.rollouts[1]

fn sub1Fn = 
  (
      rollout sub1 "Sub 1" width:100
      (
          label lb (timestamp() as string)
      )
      print sub1.width
      sub1
  )

does it change anything?

Just add thirteen!

mainR.subRoll.width=s.width + 13

Just kidding. I wonder what’s causing it to shrink by 13 each time? Is there any significance to that number, other than being horribly unlucky?

 PEN

I found that magic number but I don’t understand why the rollout returns a changing value when I would have thought it was being recreated each time. The 13 I think is shrinkage from being put in the sub I guess so that it fits.

 lo1

I don’t understand what’s unexpected about this. You need to fit the rollout control into the subRollout container. Naturally there is some padding on the subRollout container, which results in shrinkage when you try to assign the width of the rollout to the width of the container.

3 Replies
 PEN
(@pen)
Joined: 11 months ago

Posts: 0

The rollout is being recreated each time. Why is it getting smaller? I can see what you are saying if I was adding and removing the same instance of the rollout but I’m not, or at least I think that I’m not. Shouldn’t calling the function create a new instance of the rollout?

 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

I see what you’re saying. It is puzzling. I can only verify that it is a direct result of a rollout being created inside a function. The following code, for example, works as expected:


try(destroyDialog mainRol)catch()

rollout sub1 "Sub 1" width:100
(
	
)

rollout mainRol "roll" width:200
(
	subRollout subRoll "" width:100 height:200 offset:[-60,-25]
	
	on mainRol open do
	(
		addSubRollout subRoll sub1
	)
)
createDialog mainRol

print sub1.width --87

rollout sub1 "Sub 1" width:100
(
	
)
print sub1.width --100
(@davewortley)
Joined: 11 months ago

Posts: 0

The SubRollout is not getting recreated each time, the Rollout inside loses 13 pixels of width when put in the SubRollout, then you’re assigning the SubRollout’s width to the Rollout’s width, thus 13pixels smaller each time you press the button.

I think it’s to do with the scroll bar border that the subrollout control has to have to allow subrollouts to scroll up and down. When a Rollout gets added to a subrollout it becomes the width of the subrollout -13 pixels due to the edge and scrollbar. So each time you assign it it’s not taking into account the requirements for the border and scrollbar and thus shrinking each time.

Makes sense to me, the line

mainR.subRoll.width=s.width + 13

Should all that need be added.

Hmm, so ok I see why it’s confusing though, the redefining of the rollout should override that but it doesn’t… is it because Rollouts are global? And are reference-able even when they are close?

Rollout RL_test "Test"
(
	button btn_close "Close"
	
	on btn_close pressed do	
	(
		destroydialog RL_test
	)
)
Createdialog RL_test

then put this in the listener…

RL_test.width
 lo1

removeSubRollout subRoll subRoll.rollouts[1] <– doesn’t change anything

label lb (timestamp() as string) <– illegal maxscript declaration, text must be a literal

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

try to change label to:

edittext tx text:(timestamp() as string)

i want to check that every time new or old rollout adds…

It does replace the dialog, you you put a spinner on the rollout and change the value it gets reset when the button is pressed, but it appears the Rollout value ‘sub2’ doesn’t get replaced until after the addSubRollout is called.

clearListener()
(
	fn sub1Fn = 
	(
		rollout sub2 "Sub 1" width:150
		(
			spinner spn_A "A"
		)
		sub2.width = 100
		print sub2.width
		sub2
	)

	rollout mainR "Main" width:300 height:220
	(
		button addSub1Bt "Add Sub 1" align:#left across:2
		subRollout subRoll "" width:200 height:200 offset:[-60,-25]
		
		on addSub1Bt pressed do
		(
			print "button pressed"
			for o in subRoll.rollouts do removeSubRollout subRoll o
			gc()
			print s.spn_A.value
			s=sub1Fn()
			print s.spn_A.value
			print s.width
			
			
			addSubRollout subRoll s
			print s.spn_A.value
			mainR.subRoll.width=s.width
			
			
			print s.width
		)
	)

	createDialog mainR
)

I’m guessing (trying to understand this), that a rollout definition is much like a struct, and it’s not until AddSubRollout/CreateDialog is called that this definition becomes an actual object.

Try this as well…

Rollout RL_test2 "Test"
(
	button btn_close "Close"
	spinner spn_A range:[0,10,5]
	
	on btn_close pressed do	
	(
		destroydialog RL_test
	)
)

and type into the listener…

RL_test2.spn_A.value

 PEN

Perplexing, isn’t it.