diff options
| author | untodesu <kirill@untode.su> | 2025-12-26 14:50:33 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-12-26 14:50:33 +0500 |
| commit | 6c2abde5c99a236453b795abaa6d7d70105e31f7 (patch) | |
| tree | f085049b9615a7d03cca5de40adb6529d6c13e11 /src/game/client/gui/imutils_popup.cc | |
| parent | f40d09cb8f712e87691af4912f3630d92d692779 (diff) | |
| download | voxelius-6c2abde5c99a236453b795abaa6d7d70105e31f7.tar.bz2 voxelius-6c2abde5c99a236453b795abaa6d7d70105e31f7.zip | |
Just a big Ctrl+H refactoring
Diffstat (limited to 'src/game/client/gui/imutils_popup.cc')
| -rw-r--r-- | src/game/client/gui/imutils_popup.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/game/client/gui/imutils_popup.cc b/src/game/client/gui/imutils_popup.cc new file mode 100644 index 0000000..f97facb --- /dev/null +++ b/src/game/client/gui/imutils_popup.cc @@ -0,0 +1,56 @@ +#include "client/pch.hh" + +#include "client/gui/imutils_popup.hh" + +#include "client/globals.hh" + +int imutils::popup(const std::string& title, const std::string& question, const std::string* choices, std::size_t num_choices, + float font_scale) +{ + assert(choices); + assert(num_choices); + + int result = POPUP_WAIT; + + ImGui::PushFont(globals::font_unscii16, globals::font_unscii16->LegacySize); + + if(ImGui::BeginPopupModal(title.c_str(), nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize)) { + const auto viewport = ImGui::GetMainViewport(); + const auto& viewport_size = viewport->Size; + + ImVec2 popup_size(ImGui::GetWindowSize()); + ImVec2 popup_pos(viewport_size.x * 0.5f - popup_size.x * 0.5f, viewport_size.y * 0.5f - popup_size.y * 0.5f); + + ImGui::PushTextWrapPos(popup_size.x); + ImGui::TextUnformatted(question.c_str()); + ImGui::PopTextWrapPos(); + + ImGui::NewLine(); + + auto& style = ImGui::GetStyle(); + auto& spacing = style.ItemSpacing; + ImVec2 button_size(0.5f * (ImGui::CalcItemWidth() - spacing.x), 0.0f); + + for(std::size_t i = 0; i < num_choices; ++i) { + if(ImGui::Button(choices[i].c_str(), button_size)) { + result = static_cast<int>(i); + ImGui::CloseCurrentPopup(); + } + + if((i + 1) % 2 == 1) { + ImGui::SameLine(); + } + else if(i + 1 < num_choices) { + ImGui::Dummy(ImVec2(0.0, spacing.y)); + } + } + + ImGui::SetWindowPos(popup_pos, ImGuiCond_Always); + + ImGui::EndPopup(); + } + + ImGui::PopFont(); + + return result; +} |
