Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [AGK] Wrap text to box

Author
Message
Phaelax
DBPro Master
14
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Agartha
Posted: 11th Jan 2016 20:03
AGK leaves a lot to be desired when it comes to displaying text. If you want 10 lines of text to display a paragraph, you need 10 text objects. And what if you change your mind about how wide you want the paragraph displayed? This function is designed to simplify that problem.

You do need to estimate how many lines of text you expect to use, so that an array of an appropriate size can be made. When you call wrapDescription(string, integer) it will take the given string and break it up among the lines to keep each line within the defined width as best it can. It's not 100% perfect, as you may sometimes have the last letter occasionally stick partially beyond the limit. I find this happens infrequently but it is something you should account for. The length of the text on each line is estimated but I feel the outcome is accurate enough for my use. It also wraps based on whole words, so it does not cut a word in half when wrapping.



+ Code Snippet

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
BatVink
Moderator
14
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Feb 2016 08:51
You could simplify this to one text object.
AGK Text recognises CHR(10) as a line break

(Took me months to realise this)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2017-07-22 03:53:28
Your offset time is: 2017-07-22 03:53:28