2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/ui/view.hpp>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <imgui.h>
|
2020-12-22 18:10:01 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2024-01-08 21:51:48 +01:00
|
|
|
View::View(UnlocalizedString unlocalizedName, const char *icon) : m_unlocalizedViewName(std::move(unlocalizedName)), m_icon(icon) { }
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
bool View::shouldDraw() const {
|
2021-09-21 02:29:54 +02:00
|
|
|
return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable();
|
2021-02-03 00:56:33 +01:00
|
|
|
}
|
|
|
|
|
2023-11-21 14:38:01 +01:00
|
|
|
bool View::shouldProcess() const {
|
|
|
|
return this->shouldDraw() && this->getWindowOpenState();
|
|
|
|
}
|
|
|
|
|
2022-01-10 21:05:37 +01:00
|
|
|
bool View::hasViewMenuItemEntry() const {
|
2020-12-22 18:10:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-10 21:05:37 +01:00
|
|
|
ImVec2 View::getMinSize() const {
|
2023-11-21 13:47:50 +01:00
|
|
|
return scaled({ 300, 400 });
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2022-01-10 21:05:37 +01:00
|
|
|
ImVec2 View::getMaxSize() const {
|
2021-09-22 17:56:06 +02:00
|
|
|
return { FLT_MAX, FLT_MAX };
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2023-11-21 13:47:50 +01:00
|
|
|
ImGuiWindowFlags View::getWindowFlags() const {
|
|
|
|
return ImGuiWindowFlags_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
bool &View::getWindowOpenState() {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_windowOpen;
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
const bool &View::getWindowOpenState() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_windowOpen;
|
2022-01-10 21:05:37 +01:00
|
|
|
}
|
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
const UnlocalizedString &View::getUnlocalizedName() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_unlocalizedViewName;
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
std::string View::getName() const {
|
2023-12-19 13:10:25 +01:00
|
|
|
return View::toWindowName(m_unlocalizedViewName);
|
2022-01-18 00:10:10 +01:00
|
|
|
}
|
|
|
|
|
2023-10-30 21:53:44 +01:00
|
|
|
bool View::didWindowJustOpen() {
|
2023-12-19 13:10:25 +01:00
|
|
|
return std::exchange(m_windowJustOpened, false);
|
2023-10-30 21:53:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::setWindowJustOpened(bool state) {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_windowJustOpened = state;
|
2023-10-30 21:53:44 +01:00
|
|
|
}
|
|
|
|
|
2023-12-13 23:03:39 +01:00
|
|
|
void View::trackViewOpenState() {
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_windowOpen && !m_prevWindowOpen)
|
2023-12-13 23:03:39 +01:00
|
|
|
this->setWindowJustOpened(true);
|
2023-12-19 13:10:25 +01:00
|
|
|
m_prevWindowOpen = m_windowOpen;
|
2023-12-13 23:03:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-28 13:23:50 +01:00
|
|
|
void View::discardNavigationRequests() {
|
|
|
|
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
|
|
|
|
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
}
|
|
|
|
|
2023-12-19 12:22:28 +01:00
|
|
|
std::string View::toWindowName(const UnlocalizedString &unlocalizedName) {
|
2024-06-25 13:54:46 +02:00
|
|
|
return fmt::format("{}###{}", Lang(unlocalizedName), unlocalizedName.get());
|
2020-12-22 18:10:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|