| 628 | } |
| 629 | |
| 630 | bool GuiImpl::addDropdown(const char label[], const Gui::DropdownList& values, uint32_t& var, bool sameLine) |
| 631 | { |
| 632 | if (values.size() == 0) |
| 633 | return false; |
| 634 | |
| 635 | if (sameLine) |
| 636 | ImGui::SameLine(); |
| 637 | // Check if we need to update the currentItem |
| 638 | const auto& iter = mDropDownValues.find(label); |
| 639 | int curItem = -1; |
| 640 | if ((iter == mDropDownValues.end()) || (iter->second.lastVal != var)) |
| 641 | { |
| 642 | // Search the current val |
| 643 | for (uint32_t i = 0; i < values.size(); i++) |
| 644 | { |
| 645 | if (values[i].value == var) |
| 646 | { |
| 647 | curItem = i; |
| 648 | mDropDownValues[label].currentItem = i; |
| 649 | break; |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | else |
| 654 | { |
| 655 | curItem = mDropDownValues[label].currentItem; |
| 656 | } |
| 657 | |
| 658 | std::string comboStr; |
| 659 | for (const auto& v : values) |
| 660 | { |
| 661 | comboStr += v.label + '\0'; |
| 662 | } |
| 663 | comboStr += '\0'; |
| 664 | auto prevItem = curItem; |
| 665 | // This returns true if the combo is interacted with at all |
| 666 | bool b = ImGui::Combo(label, &curItem, comboStr.c_str()); |
| 667 | mDropDownValues[label].currentItem = curItem; |
| 668 | mDropDownValues[label].lastVal = values[curItem].value; |
| 669 | var = values[curItem].value; |
| 670 | // Only return true if value is changed |
| 671 | return b && prevItem != curItem; |
| 672 | } |
| 673 | |
| 674 | bool GuiImpl::addButton(const char label[], bool sameLine) |
| 675 | { |