trivial-gamekit icon indicating copy to clipboard operation
trivial-gamekit copied to clipboard

Maybe autowrap text

Open borodust opened this issue 5 years ago • 1 comments

And recognize newlines

borodust avatar Jan 29 '20 18:01 borodust

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.

defaultxr avatar May 13 '20 23:05 defaultxr