From ba96d86dc2355fa7930f1b94cd50d22836d8a954 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 29 Dec 2024 20:38:25 +0100 Subject: [PATCH] impr: Properly align favorite icons inside of the buttons in the pattern drawer --- lib/libimhex/include/hex/ui/imgui_imhex_extensions.h | 6 +++--- lib/libimhex/source/ui/imgui_imhex_extensions.cpp | 12 ++++++------ plugins/ui/source/ui/pattern_drawer.cpp | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index 419f389bf..fcf43dabe 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -144,7 +144,7 @@ namespace ImGuiExt { bool TitleBarButton(const char *label, ImVec2 size_arg); bool ToolBarButton(const char *symbol, ImVec4 color); - bool IconButton(const char *symbol, ImVec4 color, ImVec2 size_arg = ImVec2(0, 0)); + bool IconButton(const char *symbol, ImVec4 color, ImVec2 size_arg = ImVec2(0, 0), ImVec2 iconOffset = ImVec2(0, 0)); bool InputIntegerPrefix(const char* label, const char *prefix, void *value, ImGuiDataType type, const char *format, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None); bool InputHexadecimal(const char* label, u32 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None); @@ -291,8 +291,8 @@ namespace ImGuiExt { bool BitCheckbox(const char* label, bool* v); bool DimmedButton(const char* label, ImVec2 size = ImVec2(0, 0)); - bool DimmedIconButton(const char *symbol, ImVec4 color, ImVec2 size = ImVec2(0, 0)); - bool DimmedButtonToggle(const char *icon, bool *v, ImVec2 size); + bool DimmedIconButton(const char *symbol, ImVec4 color, ImVec2 size = ImVec2(0, 0), ImVec2 iconOffset = ImVec2(0, 0)); + bool DimmedButtonToggle(const char *icon, bool *v, ImVec2 size = ImVec2(0, 0), ImVec2 iconOffset = ImVec2(0, 0)); bool DimmedIconToggle(const char *icon, bool *v); bool DimmedIconToggle(const char *iconOn, const char *iconOff, bool *v); diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index bab531909..6fc7e97a8 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -824,7 +824,7 @@ namespace ImGuiExt { return pressed; } - bool IconButton(const char *symbol, ImVec4 color, ImVec2 size_arg) { + bool IconButton(const char *symbol, ImVec4 color, ImVec2 size_arg, ImVec2 iconOffset) { ImGuiWindow *window = GetCurrentWindow(); if (window->SkipItems) return false; @@ -855,7 +855,7 @@ namespace ImGuiExt { : ImGuiCol_Button); RenderNavCursor(bb, id); RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); - RenderTextClipped(bb.Min + style.FramePadding * ImVec2(1.3, 1), bb.Max - style.FramePadding, symbol, nullptr, &label_size, style.ButtonTextAlign, &bb); + RenderTextClipped(bb.Min + style.FramePadding * ImVec2(1.3, 1) + iconOffset, bb.Max - style.FramePadding, symbol, nullptr, &label_size, style.ButtonTextAlign, &bb); PopStyleColor(); @@ -1101,14 +1101,14 @@ namespace ImGuiExt { return res; } - bool DimmedIconButton(const char *symbol, ImVec4 color, ImVec2 size){ + bool DimmedIconButton(const char *symbol, ImVec4 color, ImVec2 size, ImVec2 iconOffset) { PushStyleColor(ImGuiCol_ButtonHovered, GetCustomColorU32(ImGuiCustomCol_DescButtonHovered)); PushStyleColor(ImGuiCol_Button, GetCustomColorU32(ImGuiCustomCol_DescButton)); PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_ButtonActive)); PushStyleColor(ImGuiCol_ButtonActive, GetCustomColorU32(ImGuiCustomCol_DescButtonActive)); PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1); - bool res = IconButton(symbol, color, size); + bool res = IconButton(symbol, color, size, iconOffset); PopStyleColor(4); PopStyleVar(1); @@ -1116,7 +1116,7 @@ namespace ImGuiExt { return res; } - bool DimmedButtonToggle(const char *icon, bool *v, ImVec2 size) { + bool DimmedButtonToggle(const char *icon, bool *v, ImVec2 size, ImVec2 iconOffset) { bool pushed = false; bool toggled = false; @@ -1125,7 +1125,7 @@ namespace ImGuiExt { pushed = true; } - if (DimmedIconButton(icon, GetStyleColorVec4(ImGuiCol_Text), size)) { + if (DimmedIconButton(icon, GetStyleColorVec4(ImGuiCol_Text), size, iconOffset)) { *v = !*v; toggled = true; } diff --git a/plugins/ui/source/ui/pattern_drawer.cpp b/plugins/ui/source/ui/pattern_drawer.cpp index cb8cef940..b2b24c44a 100644 --- a/plugins/ui/source/ui/pattern_drawer.cpp +++ b/plugins/ui/source/ui/pattern_drawer.cpp @@ -302,12 +302,12 @@ namespace hex::ui { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); if (m_favorites.contains(m_currPatternPath)) { - if (ImGuiExt::DimmedIconButton(ICON_VS_STAR_DELETE, ImGui::GetStyleColorVec4(ImGuiCol_PlotHistogram))) { + if (ImGuiExt::DimmedIconButton(ICON_VS_STAR_DELETE, ImGui::GetStyleColorVec4(ImGuiCol_PlotHistogram), {}, { 1_scaled, 0 })) { m_favorites.erase(m_currPatternPath); } } else { - if (ImGuiExt::DimmedIconButton(ICON_VS_STAR_ADD, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled))) { + if (ImGuiExt::DimmedIconButton(ICON_VS_STAR_ADD, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled), {}, { 1_scaled, 0 })) { m_favorites.insert({ m_currPatternPath, pattern.clone() }); } }