1
0
mirror of synced 2024-11-15 03:27:40 +01:00
ImHex/lib/libimhex/source/ui/view.cpp

77 lines
1.9 KiB
C++
Raw Normal View History

#include <hex/ui/view.hpp>
#include <imgui.h>
#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) { }
bool View::shouldDraw() const {
return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isAvailable();
2021-02-03 00:56:33 +01:00
}
bool View::shouldProcess() const {
return this->shouldDraw() && this->getWindowOpenState();
}
2022-01-10 21:05:37 +01:00
bool View::hasViewMenuItemEntry() const {
return true;
}
2022-01-10 21:05:37 +01:00
ImVec2 View::getMinSize() const {
return scaled({ 300, 400 });
}
2022-01-10 21:05:37 +01:00
ImVec2 View::getMaxSize() const {
return { FLT_MAX, FLT_MAX };
}
ImGuiWindowFlags View::getWindowFlags() const {
return ImGuiWindowFlags_None;
}
bool &View::getWindowOpenState() {
2023-12-19 13:10:25 +01:00
return m_windowOpen;
}
const bool &View::getWindowOpenState() const {
2023-12-19 13:10:25 +01:00
return m_windowOpen;
2022-01-10 21:05:37 +01:00
}
const UnlocalizedString &View::getUnlocalizedName() const {
2023-12-19 13:10:25 +01:00
return m_unlocalizedViewName;
}
std::string View::getName() const {
2023-12-19 13:10:25 +01:00
return View::toWindowName(m_unlocalizedViewName);
}
bool View::didWindowJustOpen() {
2023-12-19 13:10:25 +01:00
return std::exchange(m_windowJustOpened, false);
}
void View::setWindowJustOpened(bool state) {
2023-12-19 13:10:25 +01:00
m_windowJustOpened = state;
}
void View::trackViewOpenState() {
2023-12-19 13:10:25 +01:00
if (m_windowOpen && !m_prevWindowOpen)
this->setWindowJustOpened(true);
2023-12-19 13:10:25 +01:00
m_prevWindowOpen = m_windowOpen;
}
void View::discardNavigationRequests() {
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
}
std::string View::toWindowName(const UnlocalizedString &unlocalizedName) {
2024-06-25 13:54:46 +02:00
return fmt::format("{}###{}", Lang(unlocalizedName), unlocalizedName.get());
}
}