impr: Make reset button of color settings widgets look nicer

This commit is contained in:
WerWolv
2025-08-06 22:20:03 +02:00
parent 064b21a264
commit abe13d9ff9

View File

@@ -362,16 +362,25 @@ namespace hex {
m_flags = flags;
}
static bool areColorsEquals(const std::array<float, 4> &a, const std::array<float, 4> &b) {
return std::abs(a[0] - b[0]) < 0.005f &&
std::abs(a[1] - b[1]) < 0.005f &&
std::abs(a[2] - b[2]) < 0.005f &&
std::abs(a[3] - b[3]) < 0.005f;
}
bool ColorPicker::draw(const std::string &name) {
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()))) {
ImGui::BeginDisabled(areColorsEquals(m_value, m_defaultValue));
if (ImGuiExt::DimmedButton("\xee\xab\xa2", ImGui::GetStyle().FramePadding * 2 + ImVec2(ImGui::GetTextLineHeight(), ImGui::GetTextLineHeight()))) {
m_value = m_defaultValue;
result = true;
}
ImGui::EndDisabled();
ImGui::SameLine();