| 13 | } |
| 14 | |
| 15 | bool MenuItemWithCheckbox(const std::string &label, const std::string &shortcut, bool &selected, bool enabled) { |
| 16 | ImGuiStyle &style = ImGui::GetStyle(); |
| 17 | |
| 18 | // MenuItem is never "selected", value is toggled at the end and Checkbox is used instead to display a checkmark |
| 19 | bool ret = ImGui::MenuItem(label.c_str(), shortcut.c_str(), false, enabled); |
| 20 | bool hovered = ImGui::IsItemHovered(); |
| 21 | |
| 22 | |
| 23 | ImGui::SameLine(); |
| 24 | |
| 25 | // Checkbox will be colored when MenuItem is hovered |
| 26 | if (hovered) { |
| 27 | ImGui::PushStyleColor(ImGuiCol_FrameBg, style.Colors[ImGuiCol_FrameBgHovered]); |
| 28 | } |
| 29 | |
| 30 | // No padding for checkbox to fit in MenuItem height |
| 31 | ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); |
| 32 | |
| 33 | std::string id = "##C" + label; |
| 34 | ImGui::Checkbox(id.c_str(), &selected); |
| 35 | |
| 36 | if (hovered) { |
| 37 | ImGui::PopStyleColor(); |
| 38 | } |
| 39 | |
| 40 | ImGui::PopStyleVar(); |
| 41 | |
| 42 | if (ret) { |
| 43 | selected = !selected; |
| 44 | } |
| 45 | |
| 46 | return ret; |
| 47 | } |