Log In  

I think, that it is common to print a text in center of the screen.

With the variable font it become a little bit complicated..
When the text is variable we must do something like this.

str = "text"
len = print(str,0,-0x4000) -- print outside to get the length
print(str, 64-len\2, 128)

it would be nice, when instead of the x-coordinate a string with the position could be added

str = "text"
print(str, "center", 128)

possible "key-words" would be: "left", "center", "right"
for y would be "top", "center", "bottom"

btw. a "printsize" function would be nice, don't draw anything, only return width and height in pixels.

P#117266 2022-09-12 10:30

1

since custom fonts were added, print returns the x coordinates for the end of text (https://www.lexaloffle.com/dl/docs/pico-8_manual.html#PRINT), so we can print with x=0 and y=off-screen to get the string width, then center or align how we want, even with wide glyphs or custom font widths. so I don’t see more being added for this!

P#117270 2022-09-12 13:42

I 2nd this motion, @GPI and @merwok.

It's relatively simple to get the center for a text if all the characters are the same size, for instance the default of 4-pixels across:

function prinx(t,y,c)
  print(t,64-#t*2,y,c)
end

But yeah with each character being an independent size across, while that could be done with could, would be nicer if it were automatic.

You could even have sizes across thus:

print(text,x-coord,y-coord,color,justify)

If justify==256 then center text with x-coord being an adjuster. For instance if x==0 then no adjustment. If x==-4 then it would print the center but over to the LEFT by 4-pixels.

If x==4 then it would print the center but over to the RIGHT by 4-pixels.

You would ultimately have two or three flags for added print function.

+256 = center-x
+512 = right-justify
+1024 = put a space between every character to stand it out
+2048 = intelligently word-wrap accounting for text that has "-" "." "," "!" "?" ";" and ":"

Use 0-127 of this argument for wrap position or right-justify start position, default 128.

P#117302 2022-09-12 19:44

just go and write that function right now!
all the tools for it are there

P#117303 2022-09-12 19:47

[Please log in to post a comment]