From f49b5efac426f8bb4e6496ec7ab4302ae12af32e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 7 Nov 2023 00:46:17 +0100 Subject: [PATCH] fix: UI issues in the data information view --- lib/libimhex/include/hex/helpers/types.hpp | 7 ++++++- .../builtin/source/content/views/view_information.cpp | 10 ++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/types.hpp b/lib/libimhex/include/hex/helpers/types.hpp index 983650941..1d49c9ffb 100644 --- a/lib/libimhex/include/hex/helpers/types.hpp +++ b/lib/libimhex/include/hex/helpers/types.hpp @@ -44,7 +44,12 @@ namespace hex { } [[nodiscard]] constexpr u64 getStartAddress() const { return this->address; } - [[nodiscard]] constexpr u64 getEndAddress() const { return this->address + this->size - 1;} + [[nodiscard]] constexpr u64 getEndAddress() const { + if (this->size == 0) + return this->address; + else + return this->address + this->size - 1; + } [[nodiscard]] constexpr size_t getSize() const { return this->size; } [[nodiscard]] constexpr bool operator==(const Region &other) const { diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index b9029140d..606d7eaad 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -113,7 +113,7 @@ namespace hex::plugin::builtin { u64 count = 0; // Loop over each byte of the selection and update each analysis - // one byte at a time in order to process the file only once + // one byte at a time to process the file only once for (u8 byte : reader) { this->m_byteDistribution.update(byte); this->m_byteTypesDistribution.update(byte); @@ -228,10 +228,12 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } + + ImGui::NewLine(); } // Information analysis - { + if (this->m_analyzedRegion.getSize() > 0) { ImGui::Header("hex.builtin.view.information.info_analysis"_lang); @@ -253,7 +255,7 @@ namespace hex::plugin::builtin { true ); - // Display chunk based entropy analysis + // Display chunk-based entropy analysis ImGui::TextUnformatted("hex.builtin.view.information.entropy"_lang); this->m_chunkBasedEntropy.draw( ImVec2(-1, 0), @@ -283,7 +285,7 @@ namespace hex::plugin::builtin { ImGui::TextFormatted("{}", "hex.builtin.view.information.file_entropy"_lang); ImGui::TableNextColumn(); if (this->m_averageEntropy < 0) ImGui::TextUnformatted("???"); - else ImGui::TextFormatted("{:.5f}", this->m_averageEntropy); + else ImGui::TextFormatted("{:.5f}", std::abs(this->m_averageEntropy)); ImGui::TableNextColumn(); ImGui::TextFormatted("{}", "hex.builtin.view.information.highest_entropy"_lang);