impr: Better font scaling with larger backing scale factors

This commit is contained in:
WerWolv
2025-01-25 22:27:59 +01:00
parent 93e5d62782
commit 93f1f5d076
7 changed files with 38 additions and 24 deletions

View File

@@ -8,6 +8,7 @@
#include <hex/api/events/events_gui.hpp>
#include <hex/api/events/events_interaction.hpp>
#include <hex/api/events/requests_gui.hpp>
#include <hex/api/theme_manager.hpp>
#include <imgui.h>
#include <imgui_internal.h>
@@ -154,6 +155,27 @@ namespace hex {
}
void Window::endNativeWindowFrame() {
static float prevScaleFactor = 0;
const float currScaleFactor = MAIN_THREAD_EM_ASM_DOUBLE({
try {
// Take square root of scaling to counter scaling applied by Browser
return Math.sqrt(window.devicePixelRatio);
} catch (e) {
return 1.0;
}
});
if (prevScaleFactor != 0 && prevScaleFactor != currScaleFactor) {
EventDPIChanged::post(prevScaleFactor, currScaleFactor);
resizeCanvas();
ImHexApi::System::impl::setNativeScale(currScaleFactor);
ThemeManager::reapplyCurrentTheme();
ImGui::GetStyle().ScaleAllSizes(currScaleFactor);
}
prevScaleFactor = currScaleFactor;
}
}

View File

@@ -1,13 +1,12 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/theme_manager.hpp>
#include "window.hpp"
#if defined(OS_WINDOWS)
#include "messaging.hpp"
#include <hex/api/content_registry.hpp>
#include <hex/api/theme_manager.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/helpers/default_paths.hpp>

View File

@@ -813,8 +813,6 @@ namespace hex {
// NOTE: This needs to be done before a new frame is started, otherwise ImGui won't handle docking correctly
LayoutManager::process();
WorkspaceManager::process();
ImGui::GetIO().FontGlobalScale = 1.0F / ImHexApi::System::getBackingScaleFactor();
}
void Window::drawImGui() {