diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 050c995c0..099486a26 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 050c995c085e1312245b558f98ed7a2ab78913e4 +Subproject commit 099486a26f5248d2e99a01b464243fa29c46dd81 diff --git a/plugins/ui/source/ui/pattern_drawer.cpp b/plugins/ui/source/ui/pattern_drawer.cpp index 8d72a0f64..dc6da6621 100644 --- a/plugins/ui/source/ui/pattern_drawer.cpp +++ b/plugins/ui/source/ui/pattern_drawer.cpp @@ -501,7 +501,24 @@ namespace hex::ui { drawOffsetColumnForBitfieldMember(pattern); drawSizeColumnForBitfieldMember(pattern); ImGui::TableNextColumn(); - ImGuiExt::TextFormattedColored(ImColor(0xFF9BC64D), "bits"); + + if (dynamic_cast(&pattern) != nullptr) { + ImGuiExt::TextFormattedColored(ImColor(0xFFD69C56), "signed"); + ImGui::SameLine(); + ImGuiExt::TextFormattedColored(ImColor(0xFF9BC64D), pattern.getBitSize() == 1 ? "bit" : "bits"); + } else if (dynamic_cast(&pattern) != nullptr) { + ImGuiExt::TextFormattedColored(ImColor(0xFFD69C56), "enum"); + ImGui::SameLine(); + ImGui::TextUnformatted(pattern.getTypeName().c_str()); + } else if (dynamic_cast(&pattern) != nullptr) { + ImGuiExt::TextFormattedColored(ImColor(0xFF9BC64D), "bool"); + ImGui::SameLine(); + ImGuiExt::TextFormattedColored(ImColor(0xFF9BC64D), "bit"); + } else { + ImGuiExt::TextFormattedColored(ImColor(0xFFD69C56), "unsigned"); + ImGui::SameLine(); + ImGuiExt::TextFormattedColored(ImColor(0xFF9BC64D), pattern.getBitSize() == 1 ? "bit" : "bits"); + } if (!this->isEditingPattern(pattern)) { drawValueColumn(pattern); @@ -513,7 +530,24 @@ namespace hex::ui { auto value = pattern.getValue(); auto valueString = pattern.toString(); - if (pattern.getBitSize() == 1) { + if (auto enumPattern = dynamic_cast(&pattern); enumPattern != nullptr) { + if (ImGui::BeginCombo("##Enum", pattern.getFormattedValue().c_str())) { + auto currValue = pattern.getValue().toUnsigned(); + for (auto &enumValue : enumPattern->getEnumValues()) { + auto min = enumValue.min.toUnsigned(); + auto max = enumValue.max.toUnsigned(); + + bool isSelected = min <= currValue && max >= currValue; + if (ImGui::Selectable(fmt::format("{}::{}", pattern.getTypeName(), enumValue.name, min, pattern.getSize() * 2).c_str(), isSelected)) { + pattern.setValue(enumValue.min); + this->resetEditing(); + } + if (isSelected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + } else if (dynamic_cast(&pattern) != nullptr) { bool boolValue = value.toBoolean(); if (ImGui::Checkbox("##boolean", &boolValue)) { pattern.setValue(boolValue);