MCPcopy
hub / github.com/g3n/engine / SetText

Method SetText

gui/label.go:74–102  ·  view source on GitHub ↗

SetText sets and draws the label text using the font.

(text string)

Source from the content-addressed store, hash-verified

72
73// SetText sets and draws the label text using the font.
74func (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.
105func (l *Label) Text() string {

Callers 9

initializeMethod · 0.95
SetColorMethod · 0.95
SetColor4Method · 0.95
SetBgColorMethod · 0.95
SetBgColor4Method · 0.95
SetFontMethod · 0.95
SetFontSizeMethod · 0.95
SetFontDPIMethod · 0.95
SetLineSpacingMethod · 0.95

Calls 10

NewTexture2DFromRGBAFunction · 0.92
SetAttributesMethod · 0.80
SetMagFilterMethod · 0.80
SetMinFilterMethod · 0.80
AddTextureMethod · 0.80
SetFromRGBAMethod · 0.80
SetContentSizeMethod · 0.80
SetColorMethod · 0.45
DrawTextMethod · 0.45
MaterialMethod · 0.45

Tested by

no test coverage detected