1
0
mirror of synced 2025-02-17 18:59:21 +01:00

ux: Fixed tips popup and properly apply default layout on first start

This commit is contained in:
WerWolv 2022-02-01 23:33:42 +01:00
parent ce59226909
commit 6977061227
4 changed files with 30 additions and 32 deletions

View File

@ -33,9 +33,6 @@ namespace hex {
void frame();
void frameEnd();
void drawWelcomeScreen();
void resetLayout() const;
void initGLFW();
void initImGui();
void exitGLFW();
@ -47,22 +44,12 @@ namespace hex {
GLFWwindow *m_window = nullptr;
bool m_layoutConfigured = false;
std::string m_windowTitle;
double m_lastFrameTime;
std::string m_availableUpdate;
bool m_showTipOfTheDay;
std::string m_tipOfTheDay;
ImGui::Texture m_bannerTexture = { 0 };
ImGui::Texture m_logoTexture = { 0 };
fs::path m_safetyBackupPath;
std::list<std::string> m_popupsToOpen;
std::vector<int> m_pressedKeys;
};

View File

@ -48,7 +48,8 @@ namespace hex::init {
}
try {
status = task() && status;
if (!task())
status = false;
} catch (std::exception &e) {
log::error("Init task '{}' threw an exception: {}", name, e.what());
status = false;

View File

@ -424,18 +424,6 @@ namespace hex {
this->m_lastFrameTime = glfwGetTime();
}
void Window::drawWelcomeScreen() {
}
void Window::resetLayout() const {
if (auto &layouts = ContentRegistry::Interface::getLayouts(); !layouts.empty()) {
auto &[name, function] = layouts[0];
function(ImHexApi::System::getMainDockSpaceId());
}
}
void Window::initGLFW() {
glfwSetErrorCallback([](int error, const char *desc) {
log::error("GLFW Error [{}] : {}", error, desc);

View File

@ -1,11 +1,12 @@
#include <hex.hpp>
#include <hex/api/event.hpp>
#include <hex/api/content_registry.hpp>
#include <nlohmann/json.hpp>
#include <hex/api/localization.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/ui/view.hpp>
#include <hex/helpers/paths.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/helpers/project_file_handler.hpp>
@ -14,6 +15,7 @@
#include <imnodes.h>
#include <hex/ui/imgui_imhex_extensions.h>
#include <nlohmann/json.hpp>
#include <romfs/romfs.hpp>
#include <fontawesome_font.h>
@ -31,6 +33,23 @@ namespace hex::plugin::builtin {
static std::string s_tipOfTheDay;
static void initDefaultLayout() {
auto layouts = ContentRegistry::Interface::getLayouts();
if (!layouts.empty()) {
s_layoutConfigured = true;
for (auto &[viewName, view] : ContentRegistry::Views::getEntries()) {
view->getWindowOpenState() = false;
}
auto dockId = ImHexApi::System::getMainDockSpaceId();
ImGui::DockBuilderRemoveNode(dockId);
ImGui::DockBuilderAddNode(dockId);
layouts.front().callback(dockId);
ImGui::DockBuilderFinish(dockId);
}
}
static void drawPopups() {
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
@ -43,7 +62,7 @@ namespace hex::plugin::builtin {
static bool dontShowAgain = false;
if (ImGui::Checkbox("hex.common.dont_show_again"_lang, &dontShowAgain)) {
ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", dontShowAgain);
ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", !dontShowAgain);
}
ImGui::SameLine((ImGui::GetMainViewport()->Size / 3 - ImGui::CalcTextSize("hex.common.close"_lang) - ImGui::GetStyle().FramePadding).x);
@ -255,9 +274,6 @@ namespace hex::plugin::builtin {
ImGui::PopStyleVar();
}
ImGui::End();
} else if (!s_layoutConfigured) {
s_layoutConfigured = true;
// TODO: FIX RESET LAYOUT
}
}
ImGui::End();
@ -382,6 +398,12 @@ namespace hex::plugin::builtin {
ContentRegistry::Settings::write("hex.builtin.setting.imhex", "hex.builtin.setting.imhex.recent_files", recentFilesVector);
}
{
if (!s_layoutConfigured) {
initDefaultLayout();
}
}
});
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1050, [&] {