FullscreenUI: Fix gaps between some UI elements

By rounding sizes up to the nearest pixel.
This commit is contained in:
Stenzek 2024-04-16 13:38:58 +10:00
parent d2d6e397e6
commit 4d8ed49b24
No known key found for this signature in database
4 changed files with 32 additions and 64 deletions

View File

@ -1240,30 +1240,30 @@ ImGuiStyle::ImGuiStyle()
// Important: This operation is lossy because we round all sizes to integer. If you need to change your scale multiples, call this over a freshly initialized ImGuiStyle structure rather than scaling multiple times. // Important: This operation is lossy because we round all sizes to integer. If you need to change your scale multiples, call this over a freshly initialized ImGuiStyle structure rather than scaling multiple times.
void ImGuiStyle::ScaleAllSizes(float scale_factor) void ImGuiStyle::ScaleAllSizes(float scale_factor)
{ {
WindowPadding = ImTrunc(WindowPadding * scale_factor + ImVec2(0.5f, 0.5f)); WindowPadding = ImVec2(ImCeil(WindowPadding.x * scale_factor), ImCeil(WindowPadding.x * scale_factor));
WindowRounding = ImTrunc(WindowRounding * scale_factor + 0.5f); WindowRounding = ImCeil(WindowRounding * scale_factor);
WindowMinSize = ImTrunc(WindowMinSize * scale_factor + ImVec2(0.5f, 0.5f)); WindowMinSize = ImVec2(ImCeil(WindowMinSize.x * scale_factor), ImCeil(WindowMinSize.y * scale_factor));
ChildRounding = ImTrunc(ChildRounding * scale_factor + 0.5f); ChildRounding = ImCeil(ChildRounding * scale_factor);
PopupRounding = ImTrunc(PopupRounding * scale_factor + 0.5f); PopupRounding = ImCeil(PopupRounding * scale_factor);
FramePadding = ImTrunc(FramePadding * scale_factor + ImVec2(0.5f, 0.5f)); FramePadding = ImVec2(ImCeil(FramePadding.x * scale_factor), ImCeil(FramePadding.y * scale_factor));
FrameRounding = ImTrunc(FrameRounding * scale_factor + 0.5f); FrameRounding = ImCeil(FrameRounding * scale_factor);
ItemSpacing = ImTrunc(ItemSpacing * scale_factor + ImVec2(0.5f, 0.5f)); ItemSpacing = ImVec2(ImCeil(ItemSpacing.x * scale_factor), ImCeil(ItemSpacing.y * scale_factor));
ItemInnerSpacing = ImTrunc(ItemInnerSpacing * scale_factor + ImVec2(0.5f, 0.5f)); ItemInnerSpacing = ImVec2(ImCeil(ItemInnerSpacing.x * scale_factor), ImCeil(ItemInnerSpacing.y * scale_factor));
CellPadding = ImTrunc(CellPadding * scale_factor + ImVec2(0.5f, 0.5f)); CellPadding = ImVec2(ImCeil(CellPadding.x * scale_factor), ImCeil(CellPadding.y * scale_factor));
TouchExtraPadding = ImTrunc(TouchExtraPadding * scale_factor + ImVec2(0.5f, 0.5f)); TouchExtraPadding = ImVec2(ImCeil(TouchExtraPadding.x * scale_factor), ImCeil(TouchExtraPadding.y * scale_factor));
IndentSpacing = ImTrunc(IndentSpacing * scale_factor + 0.5f); IndentSpacing = ImCeil(IndentSpacing * scale_factor);
ColumnsMinSpacing = ImTrunc(ColumnsMinSpacing * scale_factor + 0.5f); ColumnsMinSpacing = ImCeil(ColumnsMinSpacing * scale_factor);
ScrollbarSize = ImTrunc(ScrollbarSize * scale_factor + 0.5f); ScrollbarSize = ImCeil(ScrollbarSize * scale_factor);
ScrollbarRounding = ImTrunc(ScrollbarRounding * scale_factor + 0.5f); ScrollbarRounding = ImCeil(ScrollbarRounding * scale_factor);
GrabMinSize = ImTrunc(GrabMinSize * scale_factor + 0.5f); GrabMinSize = ImCeil(GrabMinSize * scale_factor);
GrabRounding = ImTrunc(GrabRounding * scale_factor + 0.5f); GrabRounding = ImCeil(GrabRounding * scale_factor);
LogSliderDeadzone = ImTrunc(LogSliderDeadzone * scale_factor + 0.5f); LogSliderDeadzone = ImCeil(LogSliderDeadzone * scale_factor);
TabRounding = ImTrunc(TabRounding * scale_factor + 0.5f); TabRounding = ImCeil(TabRounding * scale_factor);
TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImTrunc(TabMinWidthForCloseButton * scale_factor + 0.5f) : FLT_MAX; TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImCeil(TabMinWidthForCloseButton * scale_factor) : FLT_MAX;
SeparatorTextPadding = ImTrunc(SeparatorTextPadding * scale_factor + ImVec2(0.5f, 0.5f)); SeparatorTextPadding = ImVec2(ImCeil(SeparatorTextPadding.x * scale_factor), ImCeil(SeparatorTextPadding.y * scale_factor));
DisplayWindowPadding = ImTrunc(DisplayWindowPadding * scale_factor + ImVec2(0.5f, 0.5f)); DisplayWindowPadding = ImVec2(ImCeil(DisplayWindowPadding.x * scale_factor), ImCeil(DisplayWindowPadding.y * scale_factor));
DisplaySafeAreaPadding = ImTrunc(DisplaySafeAreaPadding * scale_factor + ImVec2(0.5f, 0.5f)); DisplaySafeAreaPadding = ImVec2(ImCeil(DisplaySafeAreaPadding.x * scale_factor), ImCeil(DisplaySafeAreaPadding.y * scale_factor));
MouseCursorScale = ImTrunc(MouseCursorScale * scale_factor + 0.5f); MouseCursorScale = ImCeil(MouseCursorScale * scale_factor);
} }
ImGuiIO::ImGuiIO() ImGuiIO::ImGuiIO()

View File

@ -117,7 +117,6 @@ using ImGuiFullscreen::BeginNavBar;
using ImGuiFullscreen::CenterImage; using ImGuiFullscreen::CenterImage;
using ImGuiFullscreen::CloseChoiceDialog; using ImGuiFullscreen::CloseChoiceDialog;
using ImGuiFullscreen::CloseFileSelector; using ImGuiFullscreen::CloseFileSelector;
using ImGuiFullscreen::DPIScale;
using ImGuiFullscreen::DrawShadowedText; using ImGuiFullscreen::DrawShadowedText;
using ImGuiFullscreen::EndFullscreenColumns; using ImGuiFullscreen::EndFullscreenColumns;
using ImGuiFullscreen::EndFullscreenColumnWindow; using ImGuiFullscreen::EndFullscreenColumnWindow;

View File

@ -67,63 +67,32 @@ extern ImVec4 UISecondaryWeakColor; // Not currently used.
extern ImVec4 UISecondaryStrongColor; extern ImVec4 UISecondaryStrongColor;
extern ImVec4 UISecondaryTextColor; extern ImVec4 UISecondaryTextColor;
ALWAYS_INLINE static float DPIScale(float v)
{
return ImGui::GetIO().DisplayFramebufferScale.x * v;
}
ALWAYS_INLINE static float DPIScale(int v)
{
return ImGui::GetIO().DisplayFramebufferScale.x * static_cast<float>(v);
}
ALWAYS_INLINE static ImVec2 DPIScale(const ImVec2& v)
{
const ImVec2& fbs = ImGui::GetIO().DisplayFramebufferScale;
return ImVec2(v.x * fbs.x, v.y * fbs.y);
}
ALWAYS_INLINE static float WindowWidthScale(float v)
{
return ImGui::GetWindowWidth() * v;
}
ALWAYS_INLINE static float WindowHeightScale(float v)
{
return ImGui::GetWindowHeight() * v;
}
ALWAYS_INLINE static float LayoutScale(float v) ALWAYS_INLINE static float LayoutScale(float v)
{ {
return g_layout_scale * v; return ImCeil(g_layout_scale * v);
} }
ALWAYS_INLINE static ImVec2 LayoutScale(const ImVec2& v) ALWAYS_INLINE static ImVec2 LayoutScale(const ImVec2& v)
{ {
return ImVec2(v.x * g_layout_scale, v.y * g_layout_scale); return ImVec2(ImCeil(v.x * g_layout_scale), ImCeil(v.y * g_layout_scale));
} }
ALWAYS_INLINE static ImVec2 LayoutScale(float x, float y) ALWAYS_INLINE static ImVec2 LayoutScale(float x, float y)
{ {
return ImVec2(x * g_layout_scale, y * g_layout_scale); return ImVec2(ImCeil(x * g_layout_scale), ImCeil(y * g_layout_scale));
}
ALWAYS_INLINE static ImVec2 LayoutScaleAndOffset(float x, float y)
{
return ImVec2(g_layout_padding_left + x * g_layout_scale, g_layout_padding_top + y * g_layout_scale);
} }
ALWAYS_INLINE static float LayoutUnscale(float v) ALWAYS_INLINE static float LayoutUnscale(float v)
{ {
return g_rcp_layout_scale * v; return ImCeil(g_rcp_layout_scale * v);
} }
ALWAYS_INLINE static ImVec2 LayoutUnscale(const ImVec2& v) ALWAYS_INLINE static ImVec2 LayoutUnscale(const ImVec2& v)
{ {
return ImVec2(v.x * g_rcp_layout_scale, v.y * g_rcp_layout_scale); return ImVec2(ImCeil(v.x * g_rcp_layout_scale), ImCeil(v.y * g_rcp_layout_scale));
} }
ALWAYS_INLINE static ImVec2 LayoutUnscale(float x, float y) ALWAYS_INLINE static ImVec2 LayoutUnscale(float x, float y)
{ {
return ImVec2(x * g_rcp_layout_scale, y * g_rcp_layout_scale); return ImVec2(ImCeil(x * g_rcp_layout_scale), ImCeil(y * g_rcp_layout_scale));
} }
ALWAYS_INLINE static ImVec4 ModAlpha(const ImVec4& v, float a) ALWAYS_INLINE static ImVec4 ModAlpha(const ImVec4& v, float a)

View File

@ -631,12 +631,12 @@ bool ImGuiManager::AddImGuiFonts(bool fullscreen_fonts)
if (fullscreen_fonts) if (fullscreen_fonts)
{ {
const float medium_font_size = std::ceil(ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE)); const float medium_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE);
s_medium_font = AddTextFont(medium_font_size); s_medium_font = AddTextFont(medium_font_size);
if (!s_medium_font || !AddIconFonts(medium_font_size)) if (!s_medium_font || !AddIconFonts(medium_font_size))
return false; return false;
const float large_font_size = std::ceil(ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE)); const float large_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE);
s_large_font = AddTextFont(large_font_size); s_large_font = AddTextFont(large_font_size);
if (!s_large_font || !AddIconFonts(large_font_size)) if (!s_large_font || !AddIconFonts(large_font_size))
return false; return false;