Width returns the width of the Text generated from a FontAtlas. This implements the common.Drawable interface.
()
| 352 | |
| 353 | // Width returns the width of the Text generated from a FontAtlas. This implements the common.Drawable interface. |
| 354 | func (t Text) Width() float32 { |
| 355 | atlas, ok := atlasCache[*t.Font] |
| 356 | if !ok { |
| 357 | // Generate texture first |
| 358 | atlas = t.Font.generateFontAtlas(200) |
| 359 | atlasCache[*t.Font] = atlas |
| 360 | } |
| 361 | |
| 362 | var currentX float32 |
| 363 | var greatestX float32 |
| 364 | |
| 365 | for _, char := range t.Text { |
| 366 | // TODO: this might not work for all characters |
| 367 | switch { |
| 368 | case char == '\n': |
| 369 | if currentX > greatestX { |
| 370 | greatestX = currentX |
| 371 | } |
| 372 | currentX = 0 |
| 373 | continue |
| 374 | case char < 32: // all system stuff should be ignored |
| 375 | continue |
| 376 | } |
| 377 | |
| 378 | currentX += atlas.Width[char] + float32(t.Font.Size)*t.LetterSpacing |
| 379 | } |
| 380 | if currentX > greatestX { |
| 381 | return currentX |
| 382 | } |
| 383 | return greatestX |
| 384 | } |
| 385 | |
| 386 | // Height returns the height the Text generated from a FontAtlas. This implements the common.Drawable interface. |
| 387 | func (t Text) Height() float32 { |
nothing calls this directly
no test coverage detected