trivial-gamekit
trivial-gamekit copied to clipboard
Maybe autowrap text
And recognize newlines
For the newlines part, here's a function I wrote to draw text and handle them properly. The 0.75 near the bottom can be changed to adjust line spacing (and may need to be changed depending on the font).
(defun draw-text+ (string origin &key (fill-color (gamekit:vec4 0 0 0 1)) (font gamekit::*font*))
"Draw text like `ge.vg:draw-text', but with each newline opening a new line."
(when (plusp (length string))
(ge.vg:with-font (font)
(let* ((pos (position #\newline string))
(cstring (if pos (subseq string 0 pos) string))
(bounds (ge.vg:canvas-text-bounds cstring)))
(ge.vg:draw-text origin cstring fill-color)
(when pos
(draw-text+ (subseq string (1+ pos)) (ge:vec2 (ge:x origin) (+ (ge:y origin) (* (ge:y bounds) 0.75)))
:fill-color fill-color
:font font))))))
This is more of a hacky workaround though and probably not the ideal solution.