Clojure2D/clojure2d

Allow for setting alignment of text

jedahan opened this issue · 1 comments

A hacky prototype:

(defn text-right
  "Draw text right aligned"
  [canvas ^String s ^long x ^long y]
  (let [width (.stringWidth (.getFontMetrics (.graphics canvas)) s)]
    (clojure2d.core/text canvas s (- x width) y)))

Thank for the code. Added as a optional parameter to text function

  • (text "blah" 100 100) or (text "blah" 100 100 :left) - left aligned
  • (text "blah" 100 100 :right) - right aligned
  • (text "blah" 100 100 :center) - centered