From 0e41813cfc966a02b4c788114b4b020b34d6d5c6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 18 Jan 2026 21:56:09 +0100 Subject: [PATCH] fix: `[[format_write]]` attribute not working as expected on integer and floating point types --- plugins/ui/source/ui/pattern_value_editor.cpp | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/plugins/ui/source/ui/pattern_value_editor.cpp b/plugins/ui/source/ui/pattern_value_editor.cpp index 6ca17ae61..61a8beaa8 100644 --- a/plugins/ui/source/ui/pattern_value_editor.cpp +++ b/plugins/ui/source/ui/pattern_value_editor.cpp @@ -63,19 +63,28 @@ namespace hex::ui { } } else if (std::holds_alternative(value)) { if (ImGui::InputText("##Value", valueString, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) { - wolv::math_eval::MathEvaluator mathEvaluator; + if (pattern.getWriteFormatterFunction().empty()) { + wolv::math_eval::MathEvaluator mathEvaluator; - if (auto result = mathEvaluator.evaluate(valueString); result.has_value()) - pattern.setValue(result.value()); + if (auto result = mathEvaluator.evaluate(valueString); result.has_value()) + pattern.setValue(result.value()); + } else { + pattern.setValue(valueString); + } m_onEditCallback(); } } else if (std::holds_alternative(value)) { if (ImGui::InputText("##Value", valueString, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) { - wolv::math_eval::MathEvaluator mathEvaluator; + if (pattern.getWriteFormatterFunction().empty()) { + wolv::math_eval::MathEvaluator mathEvaluator; + + if (auto result = mathEvaluator.evaluate(valueString); result.has_value()) + pattern.setValue(result.value()); + } else { + pattern.setValue(valueString); + } - if (auto result = mathEvaluator.evaluate(valueString); result.has_value()) - pattern.setValue(result.value()); m_onEditCallback(); } @@ -129,10 +138,14 @@ namespace hex::ui { void PatternValueEditor::visit(pl::ptrn::PatternFloat& pattern) { auto value = pattern.toString(); if (ImGui::InputText("##Value", value, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) { - wolv::math_eval::MathEvaluator mathEvaluator; + if (pattern.getWriteFormatterFunction().empty()) { + wolv::math_eval::MathEvaluator mathEvaluator; - if (auto result = mathEvaluator.evaluate(value); result.has_value()) - pattern.setValue(double(result.value())); + if (auto result = mathEvaluator.evaluate(value); result.has_value()) + pattern.setValue(double(result.value())); + } else { + pattern.setValue(value); + } m_onEditCallback(); } @@ -149,10 +162,14 @@ namespace hex::ui { void PatternValueEditor::visit(pl::ptrn::PatternSigned& pattern) { auto value = pattern.getFormattedValue(); if (ImGui::InputText("##Value", value, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) { - wolv::math_eval::MathEvaluator mathEvaluator; + if (pattern.getWriteFormatterFunction().empty()) { + wolv::math_eval::MathEvaluator mathEvaluator; - if (auto result = mathEvaluator.evaluate(value); result.has_value()) - pattern.setValue(result.value()); + if (auto result = mathEvaluator.evaluate(value); result.has_value()) + pattern.setValue(result.value()); + } else { + pattern.setValue(value); + } m_onEditCallback(); } @@ -185,10 +202,14 @@ namespace hex::ui { void PatternValueEditor::visit(pl::ptrn::PatternUnsigned& pattern) { auto value = pattern.toString(); if (ImGui::InputText("##Value", value, ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue)) { - wolv::math_eval::MathEvaluator mathEvaluator; + if (pattern.getWriteFormatterFunction().empty()) { + wolv::math_eval::MathEvaluator mathEvaluator; - if (auto result = mathEvaluator.evaluate(value); result.has_value()) - pattern.setValue(result.value()); + if (auto result = mathEvaluator.evaluate(value); result.has_value()) + pattern.setValue(result.value()); + } else { + pattern.setValue(value); + } m_onEditCallback(); }