lib/tileset: intro `TileSetFont::text_height`
[nit.git] / lib / mnit / tileset.nit
index 5bd5d4d..41d8a47 100644 (file)
@@ -84,6 +84,18 @@ class TileSetFont
                if i == -1 then return null
                return subimages[i]
        end
+
+       # Distance between the beginning of a letter tile and the beginning of the next letter tile
+       fun advance: Numeric do return width.add(hspace)
+
+       # Distance between the top of the first line to the bottom of the last line in `text`
+       fun text_height(text: Text): Numeric
+       do
+               if text.is_empty then return 0
+
+               var n_lines = text.chars.count('\n')
+               return (n_lines+1).mul(height.add(vspace)).sub(vspace)
+       end
 end
 
 redef class Display