recalc recalculates the positions of this menu internal items and the content width and height of the menu
()
| 466 | // recalc recalculates the positions of this menu internal items |
| 467 | // and the content width and height of the menu |
| 468 | func (m *Menu) recalc() { |
| 469 | |
| 470 | if m.bar { |
| 471 | m.recalcBar(true) |
| 472 | return |
| 473 | } |
| 474 | |
| 475 | // Find the maximum icon and label widths |
| 476 | minWidth := float32(0) |
| 477 | iconWidth := float32(0) |
| 478 | labelWidth := float32(0) |
| 479 | shortcutWidth := float32(0) |
| 480 | riconWidth := float32(0) |
| 481 | for i := 0; i < len(m.items); i++ { |
| 482 | mi := m.items[i] |
| 483 | minWidth = mi.MinWidth() |
| 484 | // Separator |
| 485 | if mi.label == nil { |
| 486 | continue |
| 487 | } |
| 488 | // Left icon width |
| 489 | if mi.licon != nil && mi.licon.width > iconWidth { |
| 490 | iconWidth = mi.licon.width |
| 491 | } |
| 492 | // Option label width |
| 493 | if mi.label.width > labelWidth { |
| 494 | labelWidth = mi.label.width |
| 495 | } |
| 496 | // Shortcut label width |
| 497 | if mi.shortcut != nil && mi.shortcut.width > shortcutWidth { |
| 498 | shortcutWidth = mi.shortcut.width |
| 499 | } |
| 500 | // Right icon (submenu indicator) width |
| 501 | if mi.ricon != nil && mi.ricon.width > riconWidth { |
| 502 | riconWidth = mi.ricon.width |
| 503 | } |
| 504 | } |
| 505 | width := minWidth + iconWidth + labelWidth + shortcutWidth + riconWidth |
| 506 | |
| 507 | // Sets the position and width of the menu items |
| 508 | // The height is defined by the menu item itself |
| 509 | px := float32(0) |
| 510 | py := float32(0) |
| 511 | for i := 0; i < len(m.items); i++ { |
| 512 | mi := m.items[i] |
| 513 | mi.SetPosition(px, py) |
| 514 | mh := mi.minHeight() |
| 515 | py += mh |
| 516 | mi.SetSize(width, mh) |
| 517 | mi.recalc(iconWidth, labelWidth, shortcutWidth) |
| 518 | } |
| 519 | m.SetContentSize(width, py) |
| 520 | } |
| 521 | |
| 522 | // recalcBar recalculates the positions of this MenuBar internal items |
| 523 | // If setSize is true it also sets the size of the menu bar |
no test coverage detected