Created
May 26, 2015 02:32
-
-
Save bluebear94/7d78d7afbeae072e5839 to your computer and use it in GitHub Desktop.
Automatic word wrapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// because mkm was a dumbo at word wrapping | |
// THAT'S IT, FUCK MANUAL WORD WRAPPING | |
function ObjText_SetTextWW(text, string, maxWidth) { | |
let right = 0; | |
let lastSpace = -1; | |
ObjText_SetText(text, "d"); // Great. Now you just barred all chance of supporting proportional fonts. | |
let charWidth = ObjText_GetTotalWidth(text); | |
let maxStrLen = maxWidth / charWidth; | |
WriteLog(maxStrLen); | |
let len = length(string); | |
let prog = ""; | |
let saved = ""; | |
let cw = 0; | |
let prevls = 0; | |
while (right < len) { | |
let c = string[right]; | |
if (c == ' ') {lastSpace = right; prog = prog ~ " "; saved = prog;} | |
else if (c == '&') { | |
while (string[right] != ';') {prog = prog ~ [string[right]]; right++; cw++;} | |
prog = prog ~ ";"; | |
} | |
else if (c == '[') { | |
let tagCons = ""; | |
while (string[right] != ']') { | |
prog = prog ~ [string[right]]; | |
tagCons = tagCons ~ [string[right]]; | |
right++; cw++; | |
} | |
prog = prog ~ "]"; | |
WriteLog(tagCons); | |
if (tagCons == "[r") { | |
lastSpace = right; | |
saved = prog; | |
cw = 0; | |
} | |
} | |
else {prog = prog ~ [c];} | |
ObjText_SetText(text, prog); | |
if (cw > maxStrLen) { | |
if (prevls != lastSpace) { | |
prog = saved ~ "[r]"; | |
right = lastSpace; | |
prevls = lastSpace; | |
} | |
cw = 0; | |
} | |
right++; | |
cw++; | |
} | |
ObjText_SetText(text, prog); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment