1
0
mirror of synced 2024-12-25 05:54:50 +01:00
ImHex/plugins/ui/include/popups/popup_text_input.hpp

73 lines
2.2 KiB
C++
Raw Normal View History

2023-11-10 20:47:08 +01:00
#pragma once
#include <hex/ui/popup.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/localization_manager.hpp>
#include <functional>
#include <string>
#include <fonts/codicons_font.h>
namespace hex::ui {
class PopupTextInput : public Popup<PopupTextInput> {
public:
PopupTextInput(UnlocalizedString unlocalizedName, UnlocalizedString message, std::function<void(std::string)> function)
: hex::Popup<PopupTextInput>(std::move(unlocalizedName), false),
m_message(std::move(message)), m_function(std::move(function)) { }
void drawContent() override {
2023-12-19 13:10:25 +01:00
ImGuiExt::TextFormattedWrapped("{}", Lang(m_message));
ImGui::NewLine();
ImGui::PushItemWidth(-1);
2023-12-19 13:10:25 +01:00
if (m_justOpened) {
ImGui::SetKeyboardFocusHere();
2023-12-19 13:10:25 +01:00
m_justOpened = false;
}
2023-12-19 13:10:25 +01:00
ImGuiExt::InputTextIcon("##input", ICON_VS_SYMBOL_KEY, m_input);
ImGui::PopItemWidth();
ImGui::NewLine();
ImGui::Separator();
auto width = ImGui::GetWindowWidth();
ImGui::SetCursorPosX(width / 9);
2024-04-12 22:56:10 +02:00
if (ImGui::Button("hex.ui.common.okay"_lang, ImVec2(width / 3, 0)) || ImGui::IsKeyPressed(ImGuiKey_Enter)) {
2023-12-19 13:10:25 +01:00
m_function(m_input);
this->close();
}
ImGui::SameLine();
ImGui::SetCursorPosX(width / 9 * 5);
2024-04-12 22:56:10 +02:00
if (ImGui::Button("hex.ui.common.cancel"_lang, ImVec2(width / 3, 0)) || ImGui::IsKeyPressed(ImGuiKey_Escape)) {
this->close();
}
ImGui::SetWindowPos((ImHexApi::System::getMainWindowSize() - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
}
[[nodiscard]] ImGuiWindowFlags getFlags() const override {
return ImGuiWindowFlags_AlwaysAutoResize;
}
[[nodiscard]] ImVec2 getMinSize() const override {
return scaled({ 400, 100 });
}
[[nodiscard]] ImVec2 getMaxSize() const override {
return scaled({ 600, 300 });
}
private:
std::string m_input;
UnlocalizedString m_message;
std::function<void(std::string)> m_function;
bool m_justOpened = true;
};
}