lib/tileset: intro `TileSetFont::text_width`
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 17 Nov 2014 17:59:49 +0000 (12:59 -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 41d8a47..285ee55 100644 (file)
@@ -88,6 +88,18 @@ 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 beginning and the end of the longest line of `text`
+       fun text_width(text: String): Numeric
+       do
+               var lines = text.split('\n')
+               if lines.is_empty then return 0
+
+               var longest = 0
+               for line in lines do longest = longest.max(line.length)
+
+               return longest.mul(advance)
+       end
+
        # Distance between the top of the first line to the bottom of the last line in `text`
        fun text_height(text: Text): Numeric
        do