1
0
mirror of synced 2025-01-22 11:33:46 +01:00

impr: Move Jetbrains mono into regular font selector, allow it to be scaled

This commit is contained in:
WerWolv 2025-01-13 21:48:14 +01:00
parent ae622e6d75
commit 9f9a6d9827
2 changed files with 19 additions and 33 deletions

View File

@ -656,11 +656,14 @@ namespace hex::plugin::builtin {
bool changed = false; bool changed = false;
const auto &fonts = hex::getFonts(); const auto &fonts = hex::getFonts();
const bool pixelPerfectFont = ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true);
bool customFont = false; bool customFont = false;
std::string pathPreview = ""; std::string pathPreview = "";
if (m_path.empty()) { if (m_path.empty() && pixelPerfectFont) {
pathPreview = "Default Font"; pathPreview = "Pixel-Perfect Default Font (Proggy Clean)";
} else if (m_path.empty() && !pixelPerfectFont) {
pathPreview = "Smooth Default Font (JetbrainsMono)";
} else if (fonts.contains(m_path)) { } else if (fonts.contains(m_path)) {
pathPreview = fonts.at(m_path); pathPreview = fonts.at(m_path);
} else { } else {
@ -669,9 +672,17 @@ namespace hex::plugin::builtin {
} }
if (ImGui::BeginCombo(name.c_str(), pathPreview.c_str())) { 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(); m_path.clear();
changed = true; changed = true;
ContentRegistry::Settings::write<bool>("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<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", false);
} }
if (ImGui::Selectable("Custom Font", customFont)) { if (ImGui::Selectable("Custom Font", customFont)) {
@ -878,6 +889,7 @@ namespace hex::plugin::builtin {
s_showScalingWarning = ImHexApi::Fonts::getCustomFontPath().empty() && s_showScalingWarning = ImHexApi::Fonts::getCustomFontPath().empty() &&
ContentRegistry::Settings::read<bool>("hex.builtin.setting.font", "hex.builtin.setting.font.pixel_perfect_default_font", true); ContentRegistry::Settings::read<bool>("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<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false) ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.font", "hex.builtin.setting.font.glyphs", "hex.builtin.setting.font.load_all_unicode_chars", false)
.requiresRestart(); .requiresRestart();
@ -897,21 +909,11 @@ namespace hex::plugin::builtin {
const auto customFontSettingsEnabled = [customFontEnabledSetting, customFontPathSetting] { const auto customFontSettingsEnabled = [customFontEnabledSetting, customFontPathSetting] {
auto &customFontsEnabled = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget()); auto &customFontsEnabled = static_cast<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
auto &fontPath = static_cast<Widgets::FilePicker &>(customFontPathSetting.getWidget()); const bool pixelPerfectFont = ContentRegistry::Settings::read<bool>("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<Widgets::Checkbox>("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<Widgets::Checkbox &>(customFontEnabledSetting.getWidget());
auto &fontPath = static_cast<Widgets::FilePicker &>(customFontPathSetting.getWidget());
return customFontsEnabled.isChecked()&& fontPath.getPath().empty();
})
.requiresRestart();
ContentRegistry::Settings::add<Widgets::Label>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_info") ContentRegistry::Settings::add<Widgets::Label>("hex.builtin.setting.font", "hex.builtin.setting.font.custom_font", "hex.builtin.setting.font.custom_font_info")
.setEnabledCallback(customFontsEnabled); .setEnabledCallback(customFontsEnabled);

View File

@ -263,23 +263,7 @@ namespace hex::fonts {
} }
float getFontSize() { float getFontSize() {
float fontSize = ImHexApi::Fonts::DefaultFontSize; return float(ContentRegistry::Settings::read<int>("hex.builtin.setting.font", "hex.builtin.setting.font.font_size", 13)) * ImHexApi::System::getGlobalScale();
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<int>("hex.builtin.setting.font", "hex.builtin.setting.font.font_size", 13)) * ImHexApi::System::getGlobalScale();
}
return fontSize;
} }
} }
@ -330,7 +314,7 @@ namespace hex::fonts {
if (pixelPerfectFont) if (pixelPerfectFont)
defaultFont = fontAtlas.addDefaultFont(); defaultFont = fontAtlas.addDefaultFont();
else 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()) { if (!fontAtlas.build()) {
log::fatal("Failed to load default font!"); log::fatal("Failed to load default font!");