lib/tileset: intro `TileSetFont::text_height`
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 17 Nov 2014 15:33:18 +0000 (10:33 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 11 Mar 2015 15:56:39 +0000 (11:56 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/mnit/tileset.nit

index 41872bd..41d8a47 100644 (file)
@@ -87,6 +87,15 @@ class TileSetFont
 
        # 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