Why doesn't this appear as 2 rows? GUI issues

I have this code

(
 w=Window.new();
 o=3.collect{|i| StaticText().string_(i)}!2;
g=GridLayout.rows(o[0],o[1]);
w.layout=g;
w.front;
)

I was expecting 2 rows of numbers, but only one row appears.

Your !2 just duplicates the existing StaticText controls rather than creating new ones. So, you end up with two arrays of the same 3 controls (rather than 6 total). Probably what you’re seeing is the three controls being inserted into row 1, and then inserted again into row 2 (removing them from row 1?) - I think this is somewhat undefined behavior, but in any case I think you definitely intend to have 6 text controls and not three.

The clump method is useful for making rows:

(
w = Window().layout_(
	GridLayout.rows(
		*(
			6.collect({
				|i|
				StaticText().string_(i)
			}).clump(3)
		)
	)
);

w.front;
)

You’re probably right. I was wondering whether the GridLayout would traverse through each array, process through each type and display it. But I think supercollider creates views, or whatever intermediate object it calls them, attaches them into some display pipeline, then when gridlayout runs through each widget element, it uses those views to calculate where to paint the output. With !2, the views for each element are duplicated.

That wasn’t quite the issue.

// something to generate a new number on each call
p = Pseries(0, 1, inf).asStream;

// your way
o = 3.collect { p.next } ! 2;

-> [ [ 0, 1, 2 ], [ 0, 1, 2 ] ]  // only 3 views can be displayed

// what you wanted -- note 2 layers of braces
o = { 3.collect { p.next } } ! 2;

-> [ [ 3, 4, 5 ], [ 6, 7, 8 ] ]

// my personal preference to write it.
// it's more verbose, but it reduces getting lost in funny symbols
o = Array.fill(2, { // rows
	Array.fill(3, { // columns
		p.next
	})
});

-> [ [ 9, 10, 11 ], [ 12, 13, 14 ] ]

hjh

That makes sense. Within my quick scanning of the documentation, the sample code doesn’t quite point out this caveat, so I would assume that, there’s maybe some kind of tree of renderable objects, and the reuse of widgets would at the most tie the behaviour of them together, but not clobber their position. so a [ [ 0,1,2] , [ 0,1,2] ] of buttons would still be parsed by a gridlayout into two rows of buttons but 0 ,1,2 buttons have behaviours that are tied to each other.

You have to have one distinct view object per view that gets displayed. If you create 3 views, you’ll see 3 views, no matter how many times you stick one of them into a layout.

hjh