MCPcopy Create free account
hub / github.com/ddiakopoulos/polymer / item

Method item

libraries/lib-app-base/src/gl-imgui.cpp:675–728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

673 }
674
675 bool imgui_menu_stack::item(const char * label, int mods, int key, bool enabled)
676 {
677 // Use IsKeyPressed with repeat=false to only trigger once per key press,
678 // not every frame while the key is held down
679 ImGuiKey imgui_key = glfw_key_to_imgui_key(key);
680 bool invoked = (key && mods == current_mods && imgui_key != ImGuiKey_None && ImGui::IsKeyPressed(imgui_key, false));
681 if (open.back())
682 {
683 std::string shortcut;
684 if (key)
685 {
686 if (mods & GLFW_MOD_CONTROL) shortcut += "Ctrl+";
687 if (mods & GLFW_MOD_SHIFT) shortcut += "Shift+";
688 if (mods & GLFW_MOD_ALT) shortcut += "Alt+";
689 if (key >= GLFW_KEY_A && key <= GLFW_KEY_Z) shortcut += static_cast<char>('A' + (key - GLFW_KEY_A));
690 else if (key >= GLFW_KEY_0 && key <= GLFW_KEY_9) shortcut += static_cast<char>('0' + (key - GLFW_KEY_0));
691 else if (key >= GLFW_KEY_F1 && key <= GLFW_KEY_F25) shortcut += 'F' + std::to_string(1 + (key - GLFW_KEY_F1));
692 else if (key == GLFW_KEY_SPACE) shortcut += "Space";
693 else if (key == GLFW_KEY_APOSTROPHE) shortcut += '\'';
694 else if (key == GLFW_KEY_COMMA) shortcut += ',';
695 else if (key == GLFW_KEY_MINUS) shortcut += '-';
696 else if (key == GLFW_KEY_PERIOD) shortcut += '.';
697 else if (key == GLFW_KEY_SLASH) shortcut += '/';
698 else if (key == GLFW_KEY_SEMICOLON) shortcut += ';';
699 else if (key == GLFW_KEY_EQUAL) shortcut += '=';
700 else if (key == GLFW_KEY_LEFT_BRACKET) shortcut += '[';
701 else if (key == GLFW_KEY_BACKSLASH) shortcut += '\\';
702 else if (key == GLFW_KEY_RIGHT_BRACKET) shortcut += ']';
703 else if (key == GLFW_KEY_GRAVE_ACCENT) shortcut += '`';
704 else if (key == GLFW_KEY_ESCAPE) shortcut += "Escape";
705 else if (key == GLFW_KEY_ENTER) shortcut += "Enter";
706 else if (key == GLFW_KEY_TAB) shortcut += "Tab";
707 else if (key == GLFW_KEY_BACKSPACE) shortcut += "Backspace";
708 else if (key == GLFW_KEY_INSERT) shortcut += "Insert";
709 else if (key == GLFW_KEY_DELETE) shortcut += "Delete";
710 else if (key == GLFW_KEY_RIGHT) shortcut += "Right Arrow";
711 else if (key == GLFW_KEY_LEFT) shortcut += "Left Arrow";
712 else if (key == GLFW_KEY_DOWN) shortcut += "Down Arrow";
713 else if (key == GLFW_KEY_UP) shortcut += "Up Arrow";
714 else if (key == GLFW_KEY_PAGE_UP) shortcut += "Page Up";
715 else if (key == GLFW_KEY_PAGE_DOWN) shortcut += "Page Down";
716 else if (key == GLFW_KEY_HOME) shortcut += "Home";
717 else if (key == GLFW_KEY_END) shortcut += "End";
718 else if (key == GLFW_KEY_CAPS_LOCK) shortcut += "Caps Lock";
719 else if (key == GLFW_KEY_SCROLL_LOCK) shortcut += "Scroll Lock";
720 else if (key == GLFW_KEY_NUM_LOCK) shortcut += "Num Lock";
721 else if (key == GLFW_KEY_PRINT_SCREEN) shortcut += "Print Screen";
722 else if (key == GLFW_KEY_PAUSE) shortcut += "Pause";
723 else assert(false && "bad shortcut key");
724 }
725 invoked |= ImGui::MenuItem(label, shortcut.c_str(), false, enabled);
726 }
727 return invoked;
728 }
729
730 void imgui_menu_stack::end()
731 {

Callers 1

on_drawMethod · 0.80

Calls 1

glfw_key_to_imgui_keyFunction · 0.85

Tested by

no test coverage detected