2023-11-10 20:47:08 +01:00
|
|
|
#pragma once
|
|
|
|
|
2023-05-11 18:44:50 +02:00
|
|
|
#include <hex/ui/popup.hpp>
|
|
|
|
|
2023-11-18 14:34:33 +01:00
|
|
|
#include <hex/api/imhex_api.hpp>
|
2023-11-21 14:38:01 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2023-05-11 18:44:50 +02:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
|
2023-08-06 21:33:15 +02:00
|
|
|
#include <fonts/codicons_font.h>
|
|
|
|
|
2023-05-11 18:44:50 +02:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
class PopupTextInput : public Popup<PopupTextInput> {
|
|
|
|
public:
|
2023-12-19 12:22:28 +01:00
|
|
|
PopupTextInput(UnlocalizedString unlocalizedName, UnlocalizedString message, std::function<void(std::string)> function)
|
2023-05-11 18:44:50 +02:00
|
|
|
: hex::Popup<PopupTextInput>(std::move(unlocalizedName), false),
|
|
|
|
m_message(std::move(message)), m_function(std::move(function)) { }
|
|
|
|
|
|
|
|
void drawContent() override {
|
2023-12-19 12:22:28 +01:00
|
|
|
ImGuiExt::TextFormattedWrapped("{}", Lang(this->m_message));
|
2023-05-11 18:44:50 +02:00
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
ImGui::PushItemWidth(-1);
|
2023-05-21 10:43:35 +02:00
|
|
|
|
|
|
|
if (this->m_justOpened) {
|
|
|
|
ImGui::SetKeyboardFocusHere();
|
|
|
|
this->m_justOpened = false;
|
|
|
|
}
|
|
|
|
|
2023-11-16 22:24:06 +01:00
|
|
|
ImGuiExt::InputTextIcon("##input", ICON_VS_SYMBOL_KEY, this->m_input);
|
2023-05-11 18:44:50 +02:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
|
|
|
if (ImGui::Button("hex.builtin.common.okay"_lang, ImVec2(width / 3, 0)) || ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter))) {
|
|
|
|
this->m_function(this->m_input);
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX(width / 9 * 5);
|
|
|
|
if (ImGui::Button("hex.builtin.common.cancel"_lang, ImVec2(width / 3, 0)) || ImGui::IsKeyPressed(ImGui::GetKeyIndex(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;
|
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
UnlocalizedString m_message;
|
2023-05-11 18:44:50 +02:00
|
|
|
std::function<void(std::string)> m_function;
|
2023-05-21 10:43:35 +02:00
|
|
|
bool m_justOpened = true;
|
2023-05-11 18:44:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|