From 9f9a6d9827b2d6ac70ed9144b2223e1afcc58681 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 13 Jan 2025 21:48:14 +0100 Subject: [PATCH] impr: Move Jetbrains mono into regular font selector, allow it to be scaled --- .../source/content/settings_entries.cpp | 32 ++++++++++--------- plugins/fonts/source/font_loader.cpp | 20 ++---------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index e6e416b04..7717733bf 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -656,11 +656,14 @@ namespace hex::plugin::builtin { bool changed = false; const auto &fonts = hex::getFonts(); + const bool pixelPerfectFont = ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true); bool customFont = false; std::string pathPreview = ""; - if (m_path.empty()) { - pathPreview = "Default Font"; + if (m_path.empty() && pixelPerfectFont) { + pathPreview = "Pixel-Perfect Default Font (Proggy Clean)"; + } else if (m_path.empty() && !pixelPerfectFont) { + pathPreview = "Smooth Default Font (JetbrainsMono)"; } else if (fonts.contains(m_path)) { pathPreview = fonts.at(m_path); } else { @@ -669,9 +672,17 @@ namespace hex::plugin::builtin { } if (ImGui::BeginCombo(name.c_str(), pathPreview.c_str())) { - if (ImGui::Selectable("Default Font", m_path.empty())) { + + if (ImGui::Selectable("Pixel-Perfect Default Font (Proggy Clean)", m_path.empty() && pixelPerfectFont)) { m_path.clear(); changed = true; + ContentRegistry::Settings::write("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true); + } + + if (ImGui::Selectable("Smooth Default Font (JetbrainsMono)", m_path.empty() && !pixelPerfectFont)) { + m_path.clear(); + changed = true; + ContentRegistry::Settings::write("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", false); } if (ImGui::Selectable("Custom Font", customFont)) { @@ -878,6 +889,7 @@ namespace hex::plugin::builtin { s_showScalingWarning = ImHexApi::Fonts::getCustomFontPath().empty() && ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true); }; + ContentRegistry::Settings::onChange("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", scaleWarningHandler); ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false) .requiresRestart(); @@ -897,21 +909,11 @@ namespace hex::plugin::builtin { const auto customFontSettingsEnabled = [customFontEnabledSetting, customFontPathSetting] { auto &customFontsEnabled = static_cast(customFontEnabledSetting.getWidget()); - auto &fontPath = static_cast(customFontPathSetting.getWidget()); + const bool pixelPerfectFont = ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true); - return customFontsEnabled.isChecked() && !fontPath.getPath().empty(); + return customFontsEnabled.isChecked() && !pixelPerfectFont; }; - ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.pixel_perfect_default_font", true) - .setChangedCallback(scaleWarningHandler) - .setEnabledCallback([customFontPathSetting, customFontEnabledSetting] { - auto &customFontsEnabled = static_cast(customFontEnabledSetting.getWidget()); - auto &fontPath = static_cast(customFontPathSetting.getWidget()); - - return customFontsEnabled.isChecked()&& fontPath.getPath().empty(); - }) - .requiresRestart(); - ContentRegistry::Settings::add("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_info") .setEnabledCallback(customFontsEnabled); diff --git a/plugins/fonts/source/font_loader.cpp b/plugins/fonts/source/font_loader.cpp index cf91f61d5..6f1483d3d 100644 --- a/plugins/fonts/source/font_loader.cpp +++ b/plugins/fonts/source/font_loader.cpp @@ -263,23 +263,7 @@ namespace hex::fonts { } float getFontSize() { - float fontSize = ImHexApi::Fonts::DefaultFontSize; - - if (auto scaling = ImHexApi::System::getGlobalScale(); u32(scaling) * 10 == u32(scaling * 10)) - fontSize *= scaling; - else - fontSize *= scaling * 0.75F; - - // Fall back to the default font if the global scale is 0 - if (fontSize == 0.0F) - fontSize = ImHexApi::Fonts::DefaultFontSize; - - // If a custom font is used, adjust the font size - if (!ImHexApi::Fonts::getCustomFontPath().empty()) { - fontSize = float(ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.font_size", 13)) * ImHexApi::System::getGlobalScale(); - } - - return fontSize; + return float(ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.font_size", 13)) * ImHexApi::System::getGlobalScale(); } } @@ -330,7 +314,7 @@ namespace hex::fonts { if (pixelPerfectFont) defaultFont = fontAtlas.addDefaultFont(); else - defaultFont = fontAtlas.addFontFromRomFs("fonts/JetBrainsMono.ttf", 14 * ImHexApi::System::getGlobalScale(), true, ImVec2()); + defaultFont = fontAtlas.addFontFromRomFs("fonts/JetBrainsMono.ttf", fontSize, true, ImVec2()); if (!fontAtlas.build()) { log::fatal("Failed to load default font!");