fix: Icon scaling when using pixel perfect font

This commit is contained in:
WerWolv
2025-05-11 17:42:36 +02:00
parent 431eab47a2
commit 5a095cc993
2 changed files with 7 additions and 6 deletions

View File

@@ -57,7 +57,7 @@ namespace hex::fonts {
if (fontName.find("icon") != std::string::npos)
actualFontSize = ImHexApi::Fonts::pointsToPixels(fontSize);
else
actualFontSize = fontSize;
actualFontSize = fontSize;
if (FT_Set_Pixel_Sizes(face, actualFontSize, actualFontSize) != 0) {
log::fatal("Failed to set pixel size");
@@ -187,7 +187,7 @@ namespace hex::fonts {
// If there's no custom font set, or it failed to load, fall back to the default font
if (!defaultFont.has_value()) {
if (pixelPerfectFont) {
fontSize = std::max(1.0F, std::floor(ImHexApi::System::getGlobalScale() * ImHexApi::System::getBackingScaleFactor() * 13.0F));
realFontSize = fontSize = std::max(1.0F, std::floor(ImHexApi::System::getBackingScaleFactor() * 13.0F));
defaultFont = fontAtlas->addDefaultFont();
std::string defaultFontName = "Proggy Clean";
memcpy(fontAtlas->getAtlas()->ConfigData[fontIndex].Name, defaultFontName.c_str(), defaultFontName.size());

View File

@@ -101,13 +101,14 @@ namespace hex::fonts {
}
bool SliderPoints::draw(const std::string &name) {
float value = ImHexApi::Fonts::pixelsToPoints(m_value);
float min = ImHexApi::Fonts::pixelsToPoints(m_min);
float max = ImHexApi::Fonts::pixelsToPoints(m_max);
auto scaleFactor = ImHexApi::System::getBackingScaleFactor();
float value = ImHexApi::Fonts::pixelsToPoints(m_value) * scaleFactor;
float min = ImHexApi::Fonts::pixelsToPoints(m_min) * scaleFactor;
float max = ImHexApi::Fonts::pixelsToPoints(m_max) * scaleFactor;
auto changed = ImGui::SliderFloat(name.c_str(), &value, min, max, "%.0f pt");
m_value = ImHexApi::Fonts::pointsToPixels(value);
m_value = ImHexApi::Fonts::pointsToPixels(value / scaleFactor);
return changed;
}