diff --git a/UnleashedRecomp/ui/reddog/reddog_controls.cpp b/UnleashedRecomp/ui/reddog/reddog_controls.cpp index 6c52817..96aa929 100644 --- a/UnleashedRecomp/ui/reddog/reddog_controls.cpp +++ b/UnleashedRecomp/ui/reddog/reddog_controls.cpp @@ -119,3 +119,56 @@ void Reddog::Separator(float upperPadding, float lowerPadding) ImGui::Separator(); ImGui::Dummy(ImVec2(0.0f, lowerPadding)); } + +bool Reddog::ExplicitButton(const char* label, EButtonTextAlignment textAlignment, const ImVec2& size, float fontScale) +{ + auto window = ImGui::GetCurrentWindow(); + + if (window->SkipItems) + return false; + + auto font = ImGui::GetFont(); + font->Scale = fontScale; + + ImGui::PushFont(font); + + ImVec2 textSize = ImGui::CalcTextSize(label); + ImVec2 pos = ImGui::GetCursorScreenPos(); + ImVec2 buttonMax = { pos.x + size.x, pos.y + size.y }; + + ImGui::InvisibleButton(label, size); + + bool isHovered = ImGui::IsItemHovered(); + bool isActive = ImGui::IsItemActive(); + + ImVec4 colBg = isHovered ? ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered) : ImGui::GetStyleColorVec4(ImGuiCol_Button); + ImVec4 colBorder = ImGui::GetStyleColorVec4(ImGuiCol_Border); + ImVec4 colText = ImGui::GetStyleColorVec4(ImGuiCol_Text); + + window->DrawList->AddRectFilled(pos, buttonMax, ImGui::ColorConvertFloat4ToU32(colBg)); + window->DrawList->AddRect(pos, buttonMax, ImGui::ColorConvertFloat4ToU32(colBorder)); + + auto colTextU32 = ImGui::ColorConvertFloat4ToU32(colText); + auto framePadding = ImGui::GetStyle().FramePadding; + auto marginX = 8.0f; + auto textY = (pos.y + (size.y - textSize.y) * 0.5f) - 1.0f; + + switch (textAlignment) + { + case EButtonTextAlignment::Left: + window->DrawList->AddText({ pos.x + framePadding.x + marginX, textY }, colTextU32, label); + break; + + case EButtonTextAlignment::Centre: + window->DrawList->AddText({ pos.x + (size.x - textSize.x) * 0.5f, textY }, colTextU32, label); + break; + + case EButtonTextAlignment::Right: + window->DrawList->AddText({ size.x - framePadding.x - textSize.x - marginX, textY }, colTextU32, label); + break; + } + + ImGui::PopFont(); + + return isActive; +} diff --git a/UnleashedRecomp/ui/reddog/reddog_controls.h b/UnleashedRecomp/ui/reddog/reddog_controls.h index adef2da..90bc78f 100644 --- a/UnleashedRecomp/ui/reddog/reddog_controls.h +++ b/UnleashedRecomp/ui/reddog/reddog_controls.h @@ -2,8 +2,16 @@ namespace Reddog { + enum class EButtonTextAlignment + { + Left, + Centre, + Right + }; + void InitControlsResources(); bool Button(const char* label); bool Checkbox(const char* label, bool* v); + bool ExplicitButton(const char* label, EButtonTextAlignment textAlignment = EButtonTextAlignment::Centre, const ImVec2& size = { 0, 0 }, float fontScale = 1); void Separator(float upperPadding = 0, float lowerPadding = 0); } diff --git a/UnleashedRecomp/ui/reddog/reddog_window.cpp b/UnleashedRecomp/ui/reddog/reddog_window.cpp index f349bfa..b625b8c 100644 --- a/UnleashedRecomp/ui/reddog/reddog_window.cpp +++ b/UnleashedRecomp/ui/reddog/reddog_window.cpp @@ -59,6 +59,7 @@ void Reddog::InitWindowResources() void Reddog::Window::BeginStyle() { g_font->Scale = ImGui::GetDefaultFont()->FontSize / g_font->FontSize; + ImGui::PushFont(g_font); UpdateStyle(); @@ -71,8 +72,8 @@ void Reddog::Window::UpdateStyle() style.WindowMinSize = { 0, MIN_WINDOW_SIZE }; auto colBg = IsFocused - ? ImU32ToImVec4(ActiveColour) - : ImU32ToImVec4(InactiveColour); + ? ImGui::ColorConvertU32ToFloat4(ActiveColour) + : ImGui::ColorConvertU32ToFloat4(InactiveColour); auto colBlack = ImVec4(0, 0, 0, 1); auto colTrans = ImVec4(0, 0, 0, 0); @@ -106,6 +107,7 @@ void Reddog::Window::UpdateStyle() void Reddog::Window::EndStyle() { ImGui::PopFont(); + g_font->Scale = g_defaultFontScale; ImGui::GetStyle() = g_defaultStyle; diff --git a/UnleashedRecomp/ui/reddog/windows/window_list.cpp b/UnleashedRecomp/ui/reddog/windows/window_list.cpp index 798dda2..d8109e8 100644 --- a/UnleashedRecomp/ui/reddog/windows/window_list.cpp +++ b/UnleashedRecomp/ui/reddog/windows/window_list.cpp @@ -1,4 +1,5 @@ #include "window_list.h" +#include static WindowList g_window; @@ -13,7 +14,7 @@ void WindowList::Draw() if ((pTrueWindow->Flags & Reddog::eWindowFlags_NoListEntry) != 0) continue; - if (ImGui::Button(pTrueWindow->Name, { 190, 26 })) + if (Reddog::ExplicitButton(pTrueWindow->Name, Reddog::EButtonTextAlignment::Left, { 190, 32 }, 1.1f)) pTrueWindow->SetVisible(); } }