From 883bdc32c7cd4cff3ddb1408fd89f910941e6b9c Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Sun, 7 May 2017 21:00:19 +0200
Subject: [PATCH] add Text.BoundsOf

---
 text/text.go | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/text/text.go b/text/text.go
index a160da2..a0bf35e 100644
--- a/text/text.go
+++ b/text/text.go
@@ -109,6 +109,27 @@ func (txt *Text) Bounds() pixel.Rect {
 	return txt.bounds
 }
 
+func (txt *Text) BoundsOf(s string) pixel.Rect {
+	dot := txt.Dot
+	prevR := txt.prevR
+	bounds := pixel.Rect{}
+
+	for _, r := range s {
+		var b pixel.Rect
+		_, _, b, dot = txt.Atlas().DrawRune(prevR, r, dot)
+
+		if bounds.W()*bounds.H() == 0 {
+			bounds = b
+		} else {
+			bounds = bounds.Union(b)
+		}
+
+		prevR = r
+	}
+
+	return bounds
+}
+
 func (txt *Text) Color(c color.Color) {
 	rgba := pixel.ToRGBA(c)
 	for i := range txt.glyph {
-- 
GitLab