This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LeDark Lua's profile picture

How to draw text/string inside a retangle?

Started by LeDark Lua, 14 June 2015 - 03:51 PM
LeDark Lua #1
Posted 14 June 2015 - 05:51 PM
Hmm is this even posible? well if it is then I dont know how o do it, but mabie someone will help??
Well you get the Idea because of the title ( mabie ) but I will try my best to explain!

For example i have 16x8 rectangle and I draw a text inside it, when I hit the borders of the rectangle one of the texts chars will disapear.
The_Cat #2
Posted 14 June 2015 - 06:05 PM
Could you show us the code?

And maybe you can try drawing the rectangle and then the text?
Edited on 14 June 2015 - 04:06 PM
wieselkatze #3
Posted 14 June 2015 - 06:28 PM
That for the most part is just maths - if you have a rectangle that is 16 pixels in width, your text obviously should be shortened after a length of 16.
If you take a look on this, you'll see some methods for string manipulation.
Example:


local yourString = "Hello"
local boxWidth = 16

yourString = yourString:sub( 1, boxWidth ) --# Same as string.sub( yourString, 1, boxWidth )

This would result in the string being shortened to a maximum length of 16 characters - if the text is shorter than that, it'll just stay the same length.
Edited on 14 June 2015 - 04:30 PM