15 if (ImGui::IsKeyPressed(ImGuiKey_Space)) {
16 ImGui::OpenPopup(
"WhichKey");
19 ImGui::SetNextWindowPos(ImVec2(0, ImGui::GetIO().DisplaySize.y - 100),
21 ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x, 100),
23 if (ImGui::BeginPopup(
"WhichKey")) {
25 if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
26 ImGui::CloseCurrentPopup();
29 const ImVec4 colors[] = {
30 ImVec4(0.8f, 0.2f, 0.2f, 1.0f),
31 ImVec4(0.2f, 0.8f, 0.2f, 1.0f),
32 ImVec4(0.2f, 0.2f, 0.8f, 1.0f),
33 ImVec4(0.8f, 0.8f, 0.2f, 1.0f),
34 ImVec4(0.8f, 0.2f, 0.8f, 1.0f),
35 ImVec4(0.2f, 0.8f, 0.8f, 1.0f)
37 const int numColors =
sizeof(colors) /
sizeof(colors[0]);
40 if (ImGui::BeginTable(
"CommandsTable",
commands_.size(),
41 ImGuiTableFlags_SizingStretchProp)) {
42 for (
const auto& [shortcut, group] :
commands_) {
43 ImGui::TableNextColumn();
44 ImGui::TextColored(colors[colorIndex],
"%c: %s",
45 group.main_command.mnemonic,
46 group.main_command.name.c_str());
47 colorIndex = (colorIndex + 1) % numColors;
85 ImGui::OpenPopup(
"WhichKeyHierarchical");
89 if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
94 ImGui::CloseCurrentPopup();
99 ImGui::SetNextWindowPos(ImVec2(0, ImGui::GetIO().DisplaySize.y - 150),
101 ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x, 150),
104 if (ImGui::BeginPopup(
"WhichKeyHierarchical")) {
112 ImGui::CloseCurrentPopup();
128 const ImVec4 colors[] = {
129 ImVec4(0.8f, 0.2f, 0.2f, 1.0f),
130 ImVec4(0.2f, 0.8f, 0.2f, 1.0f),
131 ImVec4(0.2f, 0.2f, 0.8f, 1.0f),
132 ImVec4(0.8f, 0.8f, 0.2f, 1.0f),
133 ImVec4(0.8f, 0.2f, 0.8f, 1.0f),
134 ImVec4(0.2f, 0.8f, 0.8f, 1.0f)
140 if (ImGui::BeginTable(
"RootCommands", 6,
141 ImGuiTableFlags_SizingStretchProp)) {
143 for (
const auto& [shortcut, group] :
commands_) {
144 ImGui::TableNextColumn();
145 ImGui::TextColored(colors[colorIndex % 6],
"%c: %s",
146 group.main_command.mnemonic,
147 group.main_command.name.c_str());
156 const auto& group = it->second;
157 if (!group.subcommands.empty()) {
158 if (ImGui::BeginTable(
"Subcommands",
159 std::min(6, (
int)group.subcommands.size()),
160 ImGuiTableFlags_SizingStretchProp)) {
162 for (
const auto& [key, cmd] : group.subcommands) {
163 ImGui::TableNextColumn();
164 ImGui::TextColored(colors[colorIndex % 6],
"%c: %s", cmd.mnemonic,
171 ImGui::TextDisabled(
"No subcommands available");