1
0
mirror of synced 2024-11-24 07:40:17 +01:00

impr: Improved size display in pattern data view

This commit is contained in:
WerWolv 2024-07-02 17:38:39 +02:00
parent 09b9f26e6f
commit 313e3e748f

View File

@ -141,13 +141,42 @@ namespace hex::ui {
void drawSizeColumnForBitfieldMember(const pl::ptrn::PatternBitfieldMember &pattern) {
ImGui::TableNextColumn();
if (pattern.getBitSize() == 1)
ImGuiExt::TextFormatted("1 bit");
auto bits = pattern.getBitSize();
auto bytes = bits / 8;
bits = bits % 8;
std::string text;
if (bytes != 0) {
if (bytes == 1)
text += hex::format("{0} byte", bytes);
else
ImGuiExt::TextFormatted("{0} bits", pattern.getBitSize());
text += hex::format("{0} bytes", bytes);
if (bits != 0)
text += ", ";
}
if (bits != 0) {
if (bits == 1)
text += hex::format("{0} bit", bits);
else
text += hex::format("{0} bits", bits);
}
if (bytes == 0 && bits == 0) {
text = "0 bytes";
}
ImGui::TextUnformatted(text.c_str());
}
void drawSizeColumn(const pl::ptrn::Pattern& pattern) {
if (pattern.isPatternLocal()) {
ImGui::TableNextColumn();
return;
}
if (auto *bitfieldMember = dynamic_cast<const pl::ptrn::PatternBitfieldMember*>(&pattern); bitfieldMember != nullptr && bitfieldMember->getParentBitfield() != nullptr)
drawSizeColumnForBitfieldMember(*bitfieldMember);
else {