2022-02-01 17:09:40 +00:00
|
|
|
#include <hex/ui/view.hpp>
|
2020-12-22 17:10:01 +00:00
|
|
|
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <imgui.h>
|
2020-12-22 17:10:01 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2023-07-26 11:50:51 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
ImFontAtlas *s_fontAtlas;
|
|
|
|
ImFontConfig s_fontConfig;
|
|
|
|
|
|
|
|
}
|
2022-02-01 17:09:40 +00:00
|
|
|
|
2022-03-04 19:52:39 +00:00
|
|
|
View::View(std::string unlocalizedName) : m_unlocalizedViewName(std::move(unlocalizedName)) { }
|
2020-12-22 17:10:01 +00:00
|
|
|
|
2022-01-10 20:05:37 +00:00
|
|
|
bool View::isAvailable() const {
|
2021-09-21 00:29:54 +00:00
|
|
|
return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable();
|
2021-02-02 23:56:33 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 20:05:37 +00:00
|
|
|
bool View::hasViewMenuItemEntry() const {
|
2020-12-22 17:10:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-10 20:05:37 +00:00
|
|
|
ImVec2 View::getMinSize() const {
|
2023-01-19 15:59:09 +00:00
|
|
|
return scaled(ImVec2(300, 400));
|
2020-12-22 17:10:01 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 20:05:37 +00:00
|
|
|
ImVec2 View::getMaxSize() const {
|
2021-09-22 15:56:06 +00:00
|
|
|
return { FLT_MAX, FLT_MAX };
|
2020-12-22 17:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
bool &View::getWindowOpenState() {
|
2020-12-22 17:10:01 +00:00
|
|
|
return this->m_windowOpen;
|
|
|
|
}
|
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
const bool &View::getWindowOpenState() const {
|
2022-01-10 20:05:37 +00:00
|
|
|
return this->m_windowOpen;
|
|
|
|
}
|
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
const std::string &View::getUnlocalizedName() const {
|
2021-03-03 21:26:17 +00:00
|
|
|
return this->m_unlocalizedViewName;
|
2020-12-22 17:10:01 +00:00
|
|
|
}
|
|
|
|
|
2022-01-17 23:10:10 +00:00
|
|
|
std::string View::getName() const {
|
|
|
|
return View::toWindowName(this->m_unlocalizedViewName);
|
|
|
|
}
|
|
|
|
|
2023-10-30 20:53:44 +00:00
|
|
|
bool View::didWindowJustOpen() {
|
|
|
|
bool result = this->m_windowJustOpened;
|
|
|
|
|
|
|
|
this->m_windowJustOpened = false;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::setWindowJustOpened(bool state) {
|
|
|
|
this->m_windowJustOpened = state;
|
|
|
|
}
|
|
|
|
|
2021-01-28 12:23:50 +00:00
|
|
|
void View::discardNavigationRequests() {
|
|
|
|
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
|
|
|
|
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
}
|
|
|
|
|
2021-09-08 13:18:24 +00:00
|
|
|
void View::confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn) {
|
2020-12-22 17:10:01 +00:00
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
2021-09-08 13:18:24 +00:00
|
|
|
if (ImGui::Button(textLeft.c_str(), ImVec2(width / 3, 0)))
|
2020-12-22 17:10:01 +00:00
|
|
|
leftButtonFn();
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX(width / 9 * 5);
|
2021-09-08 13:18:24 +00:00
|
|
|
if (ImGui::Button(textRight.c_str(), ImVec2(width / 3, 0)))
|
2020-12-22 17:10:01 +00:00
|
|
|
rightButtonFn();
|
|
|
|
}
|
|
|
|
|
2023-07-26 11:50:51 +00:00
|
|
|
ImFontAtlas *View::getFontAtlas() { return s_fontAtlas; }
|
|
|
|
void View::setFontAtlas(ImFontAtlas *atlas) { s_fontAtlas = atlas; }
|
|
|
|
|
|
|
|
ImFontConfig View::getFontConfig() { return s_fontConfig; }
|
|
|
|
void View::setFontConfig(ImFontConfig config) { s_fontConfig = config; }
|
|
|
|
|
2020-12-22 17:10:01 +00:00
|
|
|
}
|