Easiest way to get vertical text


#1

Hi - I’m trying to render some vertically aligned characters like this:

W
O
R
D

And without the character rotation of an affine transform. Is there an easy way to do this?


#2

I would say the most flexible method would be to make your own, perhaps based on Label. E.g., start with something like this:

[code]class VertLabel : public Label
{
public:
VertLabel(String text)
: Label(text, text)
{
}

void paint(Graphics& g)
{
	if(isBeingEdited()) return;
		
	String text = getText();
	
	const Font& font = getFont();
	const float height = font.getHeight();
	
	g.setFont(font);
	
	float y = 0;
	
	for(int i = 0; i < text.length(); ++i)
	{
		g.drawText(text.substring(i, i+1), 0, y, getWidth(), height, Justification::left, false);
		y += height;
	}
}

};
[/code]

Then you get all the behaviour of Label. Making the editibility work elegantly might be tricky but you could override setEditable() to prevent that. Positioning the text in the above example could be more like label (in that perhaps it should be vertically centred or better still based on the Justification of the Label). You could add methods to control the vertical line spacing here too.