FullscreenUI: Add border rounding to menu items

This commit is contained in:
Stenzek 2025-03-23 16:40:54 +10:00
parent 9020959511
commit 03d7af2efc
No known key found for this signature in database
3 changed files with 33 additions and 33 deletions

View File

@ -7125,7 +7125,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
const float t = std::min(static_cast<float>(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1)), 1.0f);
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetColorU32(ImGuiCol_Border, t));
ImGuiFullscreen::DrawMenuButtonFrame(bb.Min, bb.Max, col, true, 0.0f);
ImGuiFullscreen::DrawMenuButtonFrame(bb.Min, bb.Max, col, true);
ImGui::PopStyleColor();
}
@ -7917,7 +7917,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size)
const float t = static_cast<float>(std::min(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1), 1.0));
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetColorU32(ImGuiCol_Border, t));
ImGuiFullscreen::DrawMenuButtonFrame(bb.Min, bb.Max, col, true, 0.0f);
ImGuiFullscreen::DrawMenuButtonFrame(bb.Min, bb.Max, col, true);
ImGui::PopStyleColor();
}

View File

@ -41,6 +41,7 @@ namespace ImGuiFullscreen {
using MessageDialogCallbackVariant = std::variant<InfoMessageDialogCallback, ConfirmMessageDialogCallback>;
static constexpr float MENU_BACKGROUND_ANIMATION_TIME = 0.5f;
static constexpr float MENU_ITEM_BORDER_ROUNDING = 10.0f;
static constexpr float SMOOTH_SCROLLING_SPEED = 3.5f;
static std::optional<Image> LoadTextureImage(std::string_view path, u32 svg_width, u32 svg_height);
@ -1161,7 +1162,7 @@ void ImGuiFullscreen::PrerenderMenuButtonBorder()
const float t = static_cast<float>(std::min(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1), 1.0));
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetColorU32(ImGuiCol_Border, t));
ImGui::RenderFrame(min, max, col, true, 0.0f);
ImGui::RenderFrame(min, max, col, true, LayoutScale(MENU_ITEM_BORDER_ROUNDING));
ImGui::PopStyleColor();
@ -1301,7 +1302,7 @@ bool ImGuiFullscreen::MenuButtonFrame(const char* str_id, bool enabled, float he
const float t = static_cast<float>(std::min(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1), 1.0));
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetColorU32(ImGuiCol_Border, t));
DrawMenuButtonFrame(bb->Min, bb->Max, col, true, 0.0f);
DrawMenuButtonFrame(bb->Min, bb->Max, col, true);
ImGui::PopStyleColor();
}
@ -1320,7 +1321,7 @@ bool ImGuiFullscreen::MenuButtonFrame(const char* str_id, bool enabled, float he
}
void ImGuiFullscreen::DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_max, ImU32 fill_col,
bool border /* = true */, float rounding /* = 0.0f */)
bool border /* = true */)
{
ImVec2 frame_min = p_min;
ImVec2 frame_max = p_max;
@ -1357,7 +1358,7 @@ void ImGuiFullscreen::DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_m
if (!s_state.rendered_menu_item_border)
{
s_state.rendered_menu_item_border = true;
ImGui::RenderFrame(frame_min, frame_max, fill_col, border, rounding);
ImGui::RenderFrame(frame_min, frame_max, fill_col, border, LayoutScale(MENU_ITEM_BORDER_ROUNDING));
}
}
@ -1538,8 +1539,8 @@ bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* r
const ImVec2 border_size_v = ImVec2(border_size, border_size);
ImVec2 pos, size;
GetMenuButtonFrameBounds(height, &pos, &size);
ImGui::RenderFrame(pos + border_size_v, pos + size - border_size_v, ImGui::GetColorU32(UIStyle.PrimaryColor),
false);
ImGui::RenderFrame(pos + border_size_v, pos + size - border_size_v, ImGui::GetColorU32(UIStyle.PrimaryColor), false,
LayoutScale(MENU_ITEM_BORDER_ROUNDING));
}
ImRect bb;
@ -1705,7 +1706,7 @@ bool ImGuiFullscreen::FloatingButton(const char* text, float x, float y, float w
const float t = std::min(static_cast<float>(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1)), 1.0f);
const ImU32 col = ImGui::GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered, 1.0f);
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetColorU32(ImGuiCol_Border, t));
DrawMenuButtonFrame(bb.Min, bb.Max, col, true, 0.0f);
DrawMenuButtonFrame(bb.Min, bb.Max, col, true);
ImGui::PopStyleColor();
}
}
@ -2158,7 +2159,7 @@ bool ImGuiFullscreen::NavButton(const char* title, bool is_active, bool enabled
if (hovered)
{
const ImU32 col = ImGui::GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered, 1.0f);
DrawMenuButtonFrame(bb.Min, bb.Max, col, true, 0.0f);
DrawMenuButtonFrame(bb.Min, bb.Max, col, true);
}
}
else
@ -2231,7 +2232,7 @@ bool ImGuiFullscreen::NavTab(const char* title, bool is_active, bool enabled /*
ImGui::GetColorU32(is_active ? background : ImVec4(background.x, background.y, background.z, 0.5f));
if (hovered)
DrawMenuButtonFrame(bb.Min, bb.Max, col, true, 0.0f);
DrawMenuButtonFrame(bb.Min, bb.Max, col, true);
if (is_active)
{
@ -2309,7 +2310,7 @@ bool ImGuiFullscreen::HorizontalMenuItem(GPUTexture* icon, const char* title, co
const float t = static_cast<float>(std::min(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1), 1.0));
ImGui::PushStyleColor(ImGuiCol_Border, ImGui::GetColorU32(ImGuiCol_Border, t));
DrawMenuButtonFrame(bb.Min, bb.Max, col, true, 0.0f);
DrawMenuButtonFrame(bb.Min, bb.Max, col, true);
ImGui::PopStyleColor();
}

View File

@ -250,8 +250,7 @@ void EndMenuButtons();
void GetMenuButtonFrameBounds(float height, ImVec2* pos, ImVec2* size);
bool MenuButtonFrame(const char* str_id, bool enabled, float height, bool* visible, bool* hovered, ImVec2* min,
ImVec2* max, ImGuiButtonFlags flags = 0, float hover_alpha = 1.0f);
void DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_max, ImU32 fill_col, bool border = true,
float rounding = 0.0f);
void DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_max, ImU32 fill_col, bool border = true);
void ResetMenuButtonFrame();
void RenderShadowedTextClipped(ImFont* font, const ImVec2& pos_min, const ImVec2& pos_max, u32 color, const char* text,
const char* text_end, const ImVec2* text_size_if_known = nullptr,