Height returns the height the Text generated from a FontAtlas. This implements the common.Drawable interface.
()
| 385 | |
| 386 | // Height returns the height the Text generated from a FontAtlas. This implements the common.Drawable interface. |
| 387 | func (t Text) Height() float32 { |
| 388 | atlas, ok := atlasCache[*t.Font] |
| 389 | if !ok { |
| 390 | // Generate texture first |
| 391 | atlas = t.Font.generateFontAtlas(200) |
| 392 | atlasCache[*t.Font] = atlas |
| 393 | } |
| 394 | |
| 395 | var currentY float32 |
| 396 | var totalY float32 |
| 397 | var tallest float32 |
| 398 | |
| 399 | for _, char := range t.Text { |
| 400 | // TODO: this might not work for all characters |
| 401 | switch { |
| 402 | case char == '\n': |
| 403 | totalY += tallest |
| 404 | tallest = float32(0) |
| 405 | continue |
| 406 | case char < 32: // all system stuff should be ignored |
| 407 | continue |
| 408 | } |
| 409 | currentY = atlas.Height[char] + t.LineSpacing*atlas.Height[char] |
| 410 | if currentY > tallest { |
| 411 | tallest = currentY |
| 412 | } |
| 413 | } |
| 414 | return totalY + tallest |
| 415 | } |
| 416 | |
| 417 | // View returns 0, 0, 1, 1 because the Text is generated from a FontAtlas. This implements the common.Drawable interface. |
| 418 | func (t Text) View() (float32, float32, float32, float32) { return 0, 0, 1, 1 } |
nothing calls this directly
no test coverage detected