View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide

GUI Scrolling

Home   How To   Code Pool   Public Library   Theory   Events


/*

GUI scroll-bar functionality using SCCompositeView
By jeremy_at_mantissa.ca

*/


var win, winWidth, winHeight, v1, v2, v, menu, menuSize, scroll, boxes, drawMenu, scrollFunct;

menuSize = 16;
winWidth = 200;
winHeight = 405;

menu = Array.fill(30, { arg id; id; }); // add your own array here

drawMenu = { arg start=0; var count;

	v1 = SCCompositeView(win, Rect(0, 0, winWidth - 30, winHeight));
	v1.background = Color(1.0, 0, 0, 0.3);
	
	v = SCVLayoutView(v1, Rect(5, 5, winWidth - 40, winHeight));
	v.setProperty(\spacing, 5);
	
	start = start.asInteger;
	count = menuSize.min(menu.size - start); // how many buttons
	
	boxes = Array.newClear(count); // array of buttons
	
	boxes.do({ arg i, id;
	
		i = SCButton(v, Rect(0, 0, winWidth - 30, 20));
		i.states = [[ menu.at(start+id).asString ]];
		i.action = {
		
			(start+id).postln;
		};
	});
};


win = SCWindow.new("scroll", Rect(100, 400, winWidth, winHeight), 1);

drawMenu.value;

v2 = SCCompositeView(win, Rect(winWidth - 30, 0, 30, winHeight));

scroll = SCSlider(v2, Rect(winWidth - 30, 0, 30, winHeight));
scroll.value = 1;
scroll.action = { arg val; var cs, start;

	cs = ControlSpec.new(0, menu.size - menuSize, 'linear');
	start = cs.map(1 - val.value);
	
	scrollFunct.value(start);
	win.refresh;
};

scrollFunct = { arg start;

	v1.remove;
	drawMenu.value(start);
	win.refresh;
	
};

win.front;