Add Text.AlignedTo()
This commit is contained in:
parent
7a106fa572
commit
a8b7779fbe
11
text/text.go
11
text/text.go
|
@ -101,6 +101,7 @@ type Text struct {
|
||||||
trans pixel.TrianglesData
|
trans pixel.TrianglesData
|
||||||
transD pixel.Drawer
|
transD pixel.Drawer
|
||||||
dirty bool
|
dirty bool
|
||||||
|
anchor pixel.Anchor
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Text capable of drawing runes contained in the provided Atlas. Orig and Dot
|
// New creates a new Text capable of drawing runes contained in the provided Atlas. Orig and Dot
|
||||||
|
@ -182,6 +183,12 @@ func (txt *Text) BoundsOf(s string) pixel.Rect {
|
||||||
return bounds
|
return bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AlignedTo returns the text moved by the given anchor.
|
||||||
|
func (txt *Text) AlignedTo(anchor pixel.Anchor) *Text {
|
||||||
|
txt.anchor = anchor
|
||||||
|
return txt
|
||||||
|
}
|
||||||
|
|
||||||
// Clear removes all written text from the Text. The Dot field is reset to Orig.
|
// Clear removes all written text from the Text. The Dot field is reset to Orig.
|
||||||
func (txt *Text) Clear() {
|
func (txt *Text) Clear() {
|
||||||
txt.prevR = -1
|
txt.prevR = -1
|
||||||
|
@ -244,6 +251,10 @@ func (txt *Text) DrawColorMask(t pixel.Target, matrix pixel.Matrix, mask color.C
|
||||||
txt.mat = matrix
|
txt.mat = matrix
|
||||||
txt.dirty = true
|
txt.dirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset := txt.Bounds().AnchorPos(txt.anchor)
|
||||||
|
txt.mat = pixel.IM.Moved(offset).Chained(txt.mat)
|
||||||
|
|
||||||
if mask == nil {
|
if mask == nil {
|
||||||
mask = pixel.Alpha(1)
|
mask = pixel.Alpha(1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue