1
0
mirror of synced 2025-01-31 03:53:44 +01:00

impr: Improve icon scaling a bit

This commit is contained in:
WerWolv 2024-06-18 22:10:02 +02:00
parent 80cb126200
commit 3e347fb6d4
2 changed files with 19 additions and 10 deletions

View File

@ -574,7 +574,7 @@ namespace ImGuiExt {
if (IsItemHovered() && (currTime - lastMoveTime) >= 0.5 && hoveredID == lastHoveredID) {
if (!std::string_view(text).empty()) {
const auto width = 300 * hex::ImHexApi::System::getGlobalScale();
ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(width, FLT_MAX));
ImGui::SetNextWindowSizeConstraints(ImVec2(width / 2, 0), ImVec2(width, FLT_MAX));
if (BeginTooltip()) {
if (isSeparator)
SeparatorText(text);
@ -754,6 +754,8 @@ namespace ImGuiExt {
ImVec2 size = CalcItemSize(ImVec2(1, 1) * GetCurrentWindow()->MenuBarHeight, label_size.x + style.FramePadding.x * 2.0F, label_size.y + style.FramePadding.y * 2.0F);
ImVec2 padding = (size - label_size) / 2;
const ImRect bb(pos, pos + size);
ItemSize(size, style.FramePadding.y);
if (!ItemAdd(bb, id))
@ -769,7 +771,7 @@ namespace ImGuiExt {
: ImGuiCol_MenuBarBg);
RenderNavHighlight(bb, id);
RenderFrame(bb.Min, bb.Max, col, false, style.FrameRounding);
RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, symbol, nullptr, &label_size, style.ButtonTextAlign, &bb);
RenderTextClipped(bb.Min + padding, bb.Max - padding, symbol, nullptr, &size, style.ButtonTextAlign, &bb);
PopStyleColor();

View File

@ -4,14 +4,16 @@
#include <memory>
#include <list>
#include <hex/api/imhex_api.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/helpers/logger.hpp>
#include <wolv/utils/string.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/utils.hpp>
#include <romfs/romfs.hpp>
#include "wolv/io/file.hpp"
#include "hex/api/content_registry.hpp"
#include "hex/helpers/logger.hpp"
#include "wolv/utils/string.hpp"
#include "hex/helpers/fs.hpp"
#include <wolv/io/file.hpp>
namespace hex::fonts {
@ -158,7 +160,7 @@ namespace hex::fonts {
// Calculate the expected font size
auto size = fontSize;
if (font.defaultSize.has_value())
size = font.defaultSize.value() * std::floor(ImHexApi::Fonts::getFontSize() / ImHexApi::Fonts::DefaultFontSize);
size = font.defaultSize.value() * std::max(1.0F, std::floor(ImHexApi::Fonts::getFontSize() / ImHexApi::Fonts::DefaultFontSize));
else
size = std::max(1.0F, std::floor(size / ImHexApi::Fonts::DefaultFontSize)) * ImHexApi::Fonts::DefaultFontSize;
@ -227,7 +229,12 @@ namespace hex::fonts {
}
float getFontSize() {
float fontSize = ImHexApi::Fonts::DefaultFontSize * ImHexApi::System::getGlobalScale();
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)
@ -310,7 +317,7 @@ namespace hex::fonts {
glyphRanges.push_back(glyphRange);
// Calculate the glyph offset for the font
ImVec2 offset = { font.offset.x, font.offset.y - defaultFont->getDescent() + fontAtlas.calculateFontDescend(font, fontSize) };
ImVec2 offset = { font.offset.x, font.offset.y - (defaultFont->getDescent() - fontAtlas.calculateFontDescend(font, fontSize)) };
// Load the font
fontAtlas.addFontFromMemory(font.fontData, font.defaultSize.value_or(fontSize), offset, false, glyphRanges.back());