dandiemer [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=13102 Centering Text <p>I just submitted this to the Wiki, but figured it might be more visible here.</p> <p>Here is how I handled text centering in some recent code. Any improvements are welcome.</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> textlabel=&quot;this is some cool text!!!&quot; function hcenter(s) -- string length times the -- pixels in a char's width -- cut in half and rounded down return 64-flr((#s*4)/2) end function vcenter(s) -- string char's height -- cut in half and rounded down return 64-flr(5/2) end function _draw() rectfill(0,0,128,128,0) print(textlabel,hcenter(textlabel),vcenter(textlabel),8) end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=3513 https://www.lexaloffle.com/bbs/?tid=3513 Tue, 31 May 2016 14:50:08 UTC