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.
void ImGuiStyle::ScaleAllSizes(float scale_factor)
{
WindowPadding = ImTrunc(WindowPadding * scale_factor + ImVec2(0.5f, 0.5f));
WindowRounding = ImTrunc(WindowRounding * scale_factor + 0.5f);
WindowMinSize = ImTrunc(WindowMinSize * scale_factor + ImVec2(0.5f, 0.5f));
ChildRounding = ImTrunc(ChildRounding * scale_factor + 0.5f);
PopupRounding = ImTrunc(PopupRounding * scale_factor + 0.5f);
FramePadding = ImTrunc(FramePadding * scale_factor + ImVec2(0.5f, 0.5f));
FrameRounding = ImTrunc(FrameRounding * scale_factor + 0.5f);
ItemSpacing = ImTrunc(ItemSpacing * scale_factor + ImVec2(0.5f, 0.5f));
ItemInnerSpacing = ImTrunc(ItemInnerSpacing * scale_factor + ImVec2(0.5f, 0.5f));
CellPadding = ImTrunc(CellPadding * scale_factor + ImVec2(0.5f, 0.5f));
TouchExtraPadding = ImTrunc(TouchExtraPadding * scale_factor + ImVec2(0.5f, 0.5f));
IndentSpacing = ImTrunc(IndentSpacing * scale_factor + 0.5f);
ColumnsMinSpacing = ImTrunc(ColumnsMinSpacing * scale_factor + 0.5f);
ScrollbarSize = ImTrunc(ScrollbarSize * scale_factor + 0.5f);
ScrollbarRounding = ImTrunc(ScrollbarRounding * scale_factor + 0.5f);
GrabMinSize = ImTrunc(GrabMinSize * scale_factor + 0.5f);
GrabRounding = ImTrunc(GrabRounding * scale_factor + 0.5f);
LogSliderDeadzone = ImTrunc(LogSliderDeadzone * scale_factor + 0.5f);
TabRounding = ImTrunc(TabRounding * scale_factor + 0.5f);
TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImTrunc(TabMinWidthForCloseButton * scale_factor + 0.5f) : FLT_MAX;
SeparatorTextPadding = ImTrunc(SeparatorTextPadding * scale_factor + ImVec2(0.5f, 0.5f));
DisplayWindowPadding = ImTrunc(DisplayWindowPadding * scale_factor + ImVec2(0.5f, 0.5f));
DisplaySafeAreaPadding = ImTrunc(DisplaySafeAreaPadding * scale_factor + ImVec2(0.5f, 0.5f));
MouseCursorScale = ImTrunc(MouseCursorScale * scale_factor + 0.5f);
WindowPadding = ImVec2(ImCeil(WindowPadding.x * scale_factor), ImCeil(WindowPadding.x * scale_factor));
WindowRounding = ImCeil(WindowRounding * scale_factor);
WindowMinSize = ImVec2(ImCeil(WindowMinSize.x * scale_factor), ImCeil(WindowMinSize.y * scale_factor));
ChildRounding = ImCeil(ChildRounding * scale_factor);
PopupRounding = ImCeil(PopupRounding * scale_factor);
FramePadding = ImVec2(ImCeil(FramePadding.x * scale_factor), ImCeil(FramePadding.y * scale_factor));
FrameRounding = ImCeil(FrameRounding * scale_factor);
ItemSpacing = ImVec2(ImCeil(ItemSpacing.x * scale_factor), ImCeil(ItemSpacing.y * scale_factor));
ItemInnerSpacing = ImVec2(ImCeil(ItemInnerSpacing.x * scale_factor), ImCeil(ItemInnerSpacing.y * scale_factor));
CellPadding = ImVec2(ImCeil(CellPadding.x * scale_factor), ImCeil(CellPadding.y * scale_factor));
TouchExtraPadding = ImVec2(ImCeil(TouchExtraPadding.x * scale_factor), ImCeil(TouchExtraPadding.y * scale_factor));
IndentSpacing = ImCeil(IndentSpacing * scale_factor);
ColumnsMinSpacing = ImCeil(ColumnsMinSpacing * scale_factor);
ScrollbarSize = ImCeil(ScrollbarSize * scale_factor);
ScrollbarRounding = ImCeil(ScrollbarRounding * scale_factor);
GrabMinSize = ImCeil(GrabMinSize * scale_factor);
GrabRounding = ImCeil(GrabRounding * scale_factor);
LogSliderDeadzone = ImCeil(LogSliderDeadzone * scale_factor);
TabRounding = ImCeil(TabRounding * scale_factor);
TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImCeil(TabMinWidthForCloseButton * scale_factor) : FLT_MAX;
SeparatorTextPadding = ImVec2(ImCeil(SeparatorTextPadding.x * scale_factor), ImCeil(SeparatorTextPadding.y * scale_factor));
DisplayWindowPadding = ImVec2(ImCeil(DisplayWindowPadding.x * scale_factor), ImCeil(DisplayWindowPadding.y * scale_factor));
DisplaySafeAreaPadding = ImVec2(ImCeil(DisplaySafeAreaPadding.x * scale_factor), ImCeil(DisplaySafeAreaPadding.y * scale_factor));
MouseCursorScale = ImCeil(MouseCursorScale * scale_factor);
}
ImGuiIO::ImGuiIO()

View file

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

View file

@ -67,63 +67,32 @@ extern ImVec4 UISecondaryWeakColor; // Not currently used.
extern ImVec4 UISecondaryStrongColor;
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)
{
return g_layout_scale * v;
return ImCeil(g_layout_scale * 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)
{
return ImVec2(x * g_layout_scale, 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);
return ImVec2(ImCeil(x * g_layout_scale), ImCeil(y * g_layout_scale));
}
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)
{
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)
{
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)

View file

@ -631,12 +631,12 @@ bool ImGuiManager::AddImGuiFonts(bool 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);
if (!s_medium_font || !AddIconFonts(medium_font_size))
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);
if (!s_large_font || !AddIconFonts(large_font_size))
return false;