reddog: improve window list accuracy

This commit is contained in:
Hyper 2025-01-08 09:48:33 +00:00
parent a7e004fb60
commit d5e947f520
4 changed files with 67 additions and 3 deletions

View file

@ -119,3 +119,56 @@ void Reddog::Separator(float upperPadding, float lowerPadding)
ImGui::Separator(); ImGui::Separator();
ImGui::Dummy(ImVec2(0.0f, lowerPadding)); 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;
}

View file

@ -2,8 +2,16 @@
namespace Reddog namespace Reddog
{ {
enum class EButtonTextAlignment
{
Left,
Centre,
Right
};
void InitControlsResources(); void InitControlsResources();
bool Button(const char* label); bool Button(const char* label);
bool Checkbox(const char* label, bool* v); 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); void Separator(float upperPadding = 0, float lowerPadding = 0);
} }

View file

@ -59,6 +59,7 @@ void Reddog::InitWindowResources()
void Reddog::Window::BeginStyle() void Reddog::Window::BeginStyle()
{ {
g_font->Scale = ImGui::GetDefaultFont()->FontSize / g_font->FontSize; g_font->Scale = ImGui::GetDefaultFont()->FontSize / g_font->FontSize;
ImGui::PushFont(g_font); ImGui::PushFont(g_font);
UpdateStyle(); UpdateStyle();
@ -71,8 +72,8 @@ void Reddog::Window::UpdateStyle()
style.WindowMinSize = { 0, MIN_WINDOW_SIZE }; style.WindowMinSize = { 0, MIN_WINDOW_SIZE };
auto colBg = IsFocused auto colBg = IsFocused
? ImU32ToImVec4(ActiveColour) ? ImGui::ColorConvertU32ToFloat4(ActiveColour)
: ImU32ToImVec4(InactiveColour); : ImGui::ColorConvertU32ToFloat4(InactiveColour);
auto colBlack = ImVec4(0, 0, 0, 1); auto colBlack = ImVec4(0, 0, 0, 1);
auto colTrans = ImVec4(0, 0, 0, 0); auto colTrans = ImVec4(0, 0, 0, 0);
@ -106,6 +107,7 @@ void Reddog::Window::UpdateStyle()
void Reddog::Window::EndStyle() void Reddog::Window::EndStyle()
{ {
ImGui::PopFont(); ImGui::PopFont();
g_font->Scale = g_defaultFontScale; g_font->Scale = g_defaultFontScale;
ImGui::GetStyle() = g_defaultStyle; ImGui::GetStyle() = g_defaultStyle;

View file

@ -1,4 +1,5 @@
#include "window_list.h" #include "window_list.h"
#include <ui/reddog/reddog_controls.h>
static WindowList g_window; static WindowList g_window;
@ -13,7 +14,7 @@ void WindowList::Draw()
if ((pTrueWindow->Flags & Reddog::eWindowFlags_NoListEntry) != 0) if ((pTrueWindow->Flags & Reddog::eWindowFlags_NoListEntry) != 0)
continue; continue;
if (ImGui::Button(pTrueWindow->Name, { 190, 26 })) if (Reddog::ExplicitButton(pTrueWindow->Name, Reddog::EButtonTextAlignment::Left, { 190, 32 }, 1.1f))
pTrueWindow->SetVisible(); pTrueWindow->SetVisible();
} }
} }