Multiline text in a box
BlitzMax Forums/BlitzMax Beginners Area/Multiline text in a box
| ||
Is there an easy way to output multiline text in a box/designated area? Any modules? |
| ||
blitzmax has awesome string functions which makes it easier to do wordwrap: this to put the text in lines in a list: local the_text$=YOURTEXT local width=YOURBOXWIDTH If TextWidth(the_text) > width - 9 Local word_array$[] = the_text.split(" ") Local new_string$ Local long_string$ Local iter = 0 While iter<word_array.length Local a$ = word_array[iter] long_string$ = new_string + A$ If TextWidth(long_string)>width-9 line_list.addlast(new_string) new_string = a+" " long_string="" If iter = word_array.length-1 line_list.addlast(New_String) EndIf Else new_string = new_string + a + " " If iter=word_array.length-1 line_list.addlast(new_string) EndIf EndIf iter = iter + 1 Wend Else line_list.addlast(the_text) EndIf current_line = (line_list.count() - (height /TextHeight("hi")))+2 this is to draw the text: local height=YOURBOXHEIGHT local Local line_position=0 Local iter=0 For Local a$ = EachIn line_list If line_position > current_line - 1 If line_position < (current_line + (height / TextHeight(a)) )-1 DrawText a,x+9,y+(iter*TextHeight(a))+5 iter=iter+1 EndIf EndIf line_position=line_position+1 Next |
| ||
Thanks!! Quick question, does this work with all fonts and sizes or just the default? There are some "magic numbers" (numeric constants with no obvious meaning) what are they for? |
| ||
FonText has a lot of text formatability. |
| ||
I think it works with all because of the textheight command. the capital letters are stuff that you have to fill in yourself. |