diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 48e5a2f01..6bbe866c4 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -20,6 +20,7 @@ using ImGuiDataType = int; using ImGuiInputTextFlags = int; struct ImColor; enum ImGuiCustomCol : int; +typedef int ImGuiColorEditFlags; namespace hex { @@ -192,7 +193,7 @@ namespace hex { class ColorPicker : public Widget { public: - explicit ColorPicker(ImColor defaultColor); + explicit ColorPicker(ImColor defaultColor, ImGuiColorEditFlags flags = 0); bool draw(const std::string &name) override; @@ -202,7 +203,8 @@ namespace hex { [[nodiscard]] ImColor getColor() const; protected: - std::array m_value{}; + std::array m_value = {}, m_defaultValue = {}; + ImGuiColorEditFlags m_flags; }; class DropDown : public Widget { diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 16757d273..93c71c897 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -349,17 +349,34 @@ namespace hex { } - ColorPicker::ColorPicker(ImColor defaultColor) { - m_value = { - defaultColor.Value.x, - defaultColor.Value.y, - defaultColor.Value.z, - defaultColor.Value.w + ColorPicker::ColorPicker(ImColor defaultColor, ImGuiColorEditFlags flags) { + m_defaultValue = m_value = { + defaultColor.Value.x, + defaultColor.Value.y, + defaultColor.Value.z, + defaultColor.Value.w }; + m_flags = flags; } bool ColorPicker::draw(const std::string &name) { - return ImGui::ColorEdit4(name.c_str(), m_value.data(), ImGuiColorEditFlags_NoInputs); + ImGui::PushID(name.c_str()); + auto result = ImGui::ColorEdit4("##color_picker", m_value.data(), ImGuiColorEditFlags_NoInputs | m_flags); + + ImGui::SameLine(); + + if (ImGui::Button("X", ImGui::GetStyle().FramePadding * 2 + ImVec2(ImGui::GetTextLineHeight(), ImGui::GetTextLineHeight()))) { + m_value = m_defaultValue; + result = true; + } + + ImGui::SameLine(); + + ImGui::TextUnformatted(name.c_str()); + + ImGui::PopID(); + + return result; } void ColorPicker::load(const nlohmann::json &data) { diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 12b09cddf..416a06711 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -288,7 +288,7 @@ namespace hex::plugin::builtin { bool settingChanged = false; ImGui::BeginDisabled(m_drawShortcut.matches(m_defaultShortcut)); - if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { + if (ImGui::Button("X", ImGui::GetStyle().FramePadding * 2 + ImVec2(ImGui::GetTextLineHeight(), ImGui::GetTextLineHeight()))) { this->reset(); if (!m_hasDuplicate) { m_shortcut = m_defaultShortcut; @@ -789,11 +789,15 @@ namespace hex::plugin::builtin { } }); - ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.accent", ImGui::GetStyleColorVec4(ImGuiCol_Button)) - .setChangedCallback([](auto &widget) { - auto colorPicker = static_cast(&widget); - ThemeManager::setAccentColor(colorPicker->getColor()); - }); + ContentRegistry::Settings::add( + "hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.accent", + ImGui::GetStyleColorVec4(ImGuiCol_Button), + ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoDragDrop | ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoInputs + ) + .setChangedCallback([](auto &widget) { + auto colorPicker = static_cast(&widget); + ThemeManager::setAccentColor(colorPicker->getColor()); + }); ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.style", "hex.builtin.setting.interface.scaling_factor") .requiresRestart();