1
0
mirror of synced 2024-11-12 02:00:52 +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 6784678ff0
commit c7c4ecad6d

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");
else
ImGuiExt::TextFormatted("{0} bits", pattern.getBitSize());
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
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 {