add Text.BoundsOf

This commit is contained in:
faiface 2017-05-07 21:00:19 +02:00
parent c9eea2639e
commit 883bdc32c7
1 changed files with 21 additions and 0 deletions

View File

@ -109,6 +109,27 @@ func (txt *Text) Bounds() pixel.Rect {
return txt.bounds 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) { func (txt *Text) Color(c color.Color) {
rgba := pixel.ToRGBA(c) rgba := pixel.ToRGBA(c)
for i := range txt.glyph { for i := range txt.glyph {