Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 7:41 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun Apr 01, 2012 8:33 pm 
Offline

Joined: Sun Apr 01, 2012 8:25 pm
Posts: 1
When drawing text with "\n" characters in, text draws correctly with more than one line.
However, when getting the width of the text, the code only gets the width of the topmost line in the text.

What this means:
If you have a String like this: "Hello\nMy name is Paul", the code will return the width of "hello", meaning your width value will be wrong.

Work Around:
Code:
String text = ...;
String[] parts = text.split("\n");
int width = 0;
for(int dofor = 0; dofor < parts.length; dofor++){
    width = Math.max(UnicodeFont.getWidth(parts[dofor], width);
}

Replace "..." with your text!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group