add Text.LineHeight and text.TabWidth
This commit is contained in:
parent
e2a16764c4
commit
6a7500959f
23
text/text.go
23
text/text.go
|
@ -40,10 +40,13 @@ type Text struct {
|
|||
Orig pixel.Vec
|
||||
Dot pixel.Vec
|
||||
|
||||
atlas atlas
|
||||
|
||||
color pixel.RGBA
|
||||
lineHeight float64
|
||||
tabWidth float64
|
||||
|
||||
prevR rune
|
||||
atlas atlas
|
||||
glyph pixel.TrianglesData
|
||||
tris pixel.TrianglesData
|
||||
d pixel.Drawer
|
||||
|
@ -55,9 +58,13 @@ func New(face font.Face, runeSets ...[]rune) *Text {
|
|||
runes = append(runes, set...)
|
||||
}
|
||||
|
||||
atlas := makeAtlas(face, runes)
|
||||
|
||||
txt := &Text{
|
||||
atlas: atlas,
|
||||
color: pixel.Alpha(1),
|
||||
atlas: makeAtlas(face, runes),
|
||||
lineHeight: 1,
|
||||
tabWidth: atlas.mapping[' '].advance * 4,
|
||||
}
|
||||
txt.glyph.SetLen(6)
|
||||
txt.d.Picture = txt.atlas.pic
|
||||
|
@ -72,6 +79,14 @@ func (txt *Text) Color(c color.Color) {
|
|||
txt.color = pixel.ToRGBA(c)
|
||||
}
|
||||
|
||||
func (txt *Text) LineHeight(scale float64) {
|
||||
txt.lineHeight = scale
|
||||
}
|
||||
|
||||
func (txt *Text) TabWidth(width float64) {
|
||||
txt.tabWidth = width
|
||||
}
|
||||
|
||||
func (txt *Text) Clear() {
|
||||
txt.prevR = -1
|
||||
txt.tris.SetLen(0)
|
||||
|
@ -96,14 +111,14 @@ func (txt *Text) Write(p []byte) (n int, err error) {
|
|||
|
||||
switch r {
|
||||
case '\n':
|
||||
txt.Dot -= pixel.Y(txt.atlas.lineHeight)
|
||||
txt.Dot -= pixel.Y(txt.atlas.lineHeight * txt.lineHeight)
|
||||
txt.Dot = txt.Dot.WithX(txt.Orig.X())
|
||||
continue
|
||||
case '\r':
|
||||
txt.Dot = txt.Dot.WithX(txt.Orig.X())
|
||||
continue
|
||||
case '\t':
|
||||
//TODO
|
||||
txt.Dot += pixel.X(txt.tabWidth)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue