SetText sets and draws the label text using the font.
(text string)
| 72 | |
| 73 | // SetText sets and draws the label text using the font. |
| 74 | func (l *Label) SetText(text string) { |
| 75 | |
| 76 | // Need at least a character to get dimensions |
| 77 | l.text = text |
| 78 | if text == "" { |
| 79 | text = " " |
| 80 | } |
| 81 | |
| 82 | // Set font properties |
| 83 | l.font.SetAttributes(&l.style.FontAttributes) |
| 84 | l.font.SetColor(&l.style.FgColor) |
| 85 | |
| 86 | // Create an image with the text |
| 87 | textImage := l.font.DrawText(text) |
| 88 | |
| 89 | // Create texture if it doesn't exist yet |
| 90 | if l.tex == nil { |
| 91 | l.tex = texture.NewTexture2DFromRGBA(textImage) |
| 92 | l.tex.SetMagFilter(gls.NEAREST) |
| 93 | l.tex.SetMinFilter(gls.NEAREST) |
| 94 | l.Panel.Material().AddTexture(l.tex) |
| 95 | // Otherwise update texture with new image |
| 96 | } else { |
| 97 | l.tex.SetFromRGBA(textImage) |
| 98 | } |
| 99 | |
| 100 | // Update label panel dimensions |
| 101 | l.Panel.SetContentSize(float32(textImage.Rect.Dx()), float32(textImage.Rect.Dy())) |
| 102 | } |
| 103 | |
| 104 | // Text returns the label text. |
| 105 | func (l *Label) Text() string { |
no test coverage detected