
mainGroup = WidgetContainer:new();
mainGroup:setMinWidth(512);
mainGroup:setMinHeight(512);
mainGroup:setBackgroundImage("np_ff1.ninepatch");
mainGroup:setStretchableRow(1);
mainGroup:setStretchableCol(0);
widgetSetRoot(mainGroup);

mainGroup:setNumRows(2);

radioGroup = WidgetRadioGroup:new();
mainGroup:addChild(radioGroup);

tabGroup = WidgetContainer:new();
tabGroup:setMinHeight(32);
radioGroup:setChild(tabGroup);

selectChild = WidgetSelectChild:new();
mainGroup:addChild(selectChild);

numTabs = 0;

function addTab(label, text)

	buttonWidget = WidgetButton:new();
	
	-- We need to do this early so the setToggleValue() hits the radio
	-- group.
	tabGroup:addChild(buttonWidget);
	
	buttonWidget:setBackgroundImage("test_np.ninepatch");
	buttonWidget:setBackgroundDefault("test_np.ninepatch");
	buttonWidget:setBackgroundActive("np_ff1.ninepatch");
	buttonWidget:setLabel(label);
	buttonWidget:setMinWidth(64);
	buttonWidget:setMinHeight(64);
	buttonWidget:setToggleable(true);
	if (numTabs == 0) then
		buttonWidget:setToggleValue(true);
		radioGroup:setSelectedOption(buttonWidget);
	end
	buttonWidget:setIsRadio(true);
	
	tabGroup:setNumCols(numTabs + 1);
	tabGroup:setStretchableCol(numTabs + 1);
	numTabs = numTabs + 1;
	
	container = WidgetContainer:new();
	container:setNumRows(2);
	--container:setNumCols(2);
	container:setStretchableRow(1);
	container:setStretchableCol(0);

	textWidget = WidgetText:new();
	textWidget:setText(text);
	textWidget:setEditable(true);
	textWidget:setBackgroundImage("np_ff1.ninepatch");
	textWidget:setMinWidth(64);
	textWidget:setMinHeight(64);

	selectChild:addChild(container);
	selectChild:mapRadioToChild(buttonWidget, container);




	radioJunkBox = WidgetPaddedBox:new();
	radioJunkBox:setBackgroundImage("np_ff1.ninepatch");
	
	radioJunk1 = WidgetRadioGroup:new();
	radioJunk2 = WidgetContainer:new();
	radioJunk1:setChild(radioJunk2);
	radioJunkBox:setChild(radioJunk1);
	
	radioJunk2:setNumCols(2);
	radioJunk2:setStretchableCol(1);
	radioJunk2:setStretchableRow(0);

	local numSecondChildren = 0;

	function makeRadioThing(label)

		local alignedBox = WidgetAlignedBox:new();
		alignedBox:setHAlign(0);
		alignedBox:setVAlign(0);
		radioJunk2:addChild(alignedBox);
		
		local button = WidgetButton:new();
		alignedBox:setChild(button);
		button:setBackgroundImage("radio_inactive.tga");
		button:setBackgroundDefault("radio_inactive.tga");
		button:setBackgroundActive("radio_active.tga");
		button:setLabel("");
		button:setIsRadio(true);
		button:setToggleable(true);
		button:setMinWidth(16);
		button:setMinHeight(16);

		local text = WidgetText:new();
		text:setText(label);
		
		radioJunk2:addChild(text);

		numSecondChildren = numSecondChildren + 1;
		radioJunk2:setNumRows(numSecondChildren);

	end

	makeRadioThing("radiothing1");
	makeRadioThing("radiot\n\nhing2");
	makeRadioThing("radiothing3");
	makeRadioThing("radiothing4");

	--testText = WidgetText:new();
	--testText:setText("jjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
	--container:addChild(testText);

	container:addChild(radioJunkBox);
	container:addChild(textWidget);

end

addTab("test1", "arghblargh");
addTab("test2", "moof");
addTab("test3", "foobar");
