pattern: Allow pattern with nested children to be selectable, make pointers inlinable

This commit is contained in:
WerWolv 2022-02-07 23:21:04 +01:00
parent a8e49c5a85
commit 37ea9c6656
1 changed files with 49 additions and 22 deletions

View File

@ -332,7 +332,8 @@ namespace hex::pl {
[[nodiscard]] bool operator==(const PatternData &other) const override { return areCommonPropertiesEqual<decltype(*this)>(other); } [[nodiscard]] bool operator==(const PatternData &other) const override { return areCommonPropertiesEqual<decltype(*this)>(other); }
}; };
class PatternDataPointer : public PatternData { class PatternDataPointer : public PatternData,
public Inlinable {
public: public:
PatternDataPointer(Evaluator *evaluator, u64 offset, size_t size, u32 color = 0) PatternDataPointer(Evaluator *evaluator, u64 offset, size_t size, u32 color = 0)
: PatternData(evaluator, offset, size, color), m_pointedAt(nullptr) { : PatternData(evaluator, offset, size, color), m_pointedAt(nullptr) {
@ -355,25 +356,34 @@ namespace hex::pl {
provider->read(this->getOffset(), &data, this->getSize()); provider->read(this->getOffset(), &data, this->getSize());
data = hex::changeEndianess(data, this->getSize(), this->getEndian()); data = hex::changeEndianess(data, this->getSize(), this->getEndian());
ImGui::TableNextRow(); bool open = true;
ImGui::TableNextColumn();
bool open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap); if (!this->isInlined()) {
this->drawCommentTooltip(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight())); open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1); if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
ImGui::TableNextColumn(); EventManager::post<RequestSelectionChange>(Region { this->getOffset(), this->getSize() });
ImGui::TextFormatted("0x{0:04X}", this->getSize()); }
ImGui::TableNextColumn(); this->drawCommentTooltip();
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName()); ImGui::SameLine(0, 0);
ImGui::TableNextColumn(); ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
ImGui::TextFormatted("{}", formatDisplayValue(hex::format("*(0x{0:X})", data), u128(data))); ImGui::TableNextColumn();
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
ImGui::TableNextColumn();
ImGui::TextFormatted("0x{0:04X}", this->getSize());
ImGui::TableNextColumn();
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName());
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", formatDisplayValue(hex::format("*(0x{0:X})", data), u128(data)));
}
if (open) { if (open) {
this->m_pointedAt->createEntry(provider); this->m_pointedAt->createEntry(provider);
ImGui::TreePop(); if (!this->isInlined())
ImGui::TreePop();
} }
} }
@ -791,6 +801,10 @@ namespace hex::pl {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth); open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
ImGui::TableNextColumn();
if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
EventManager::post<RequestSelectionChange>(Region { this->getOffset(), this->getSize() });
}
this->drawCommentTooltip(); this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight())); ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
@ -937,6 +951,10 @@ namespace hex::pl {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth); open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
ImGui::TableNextColumn();
if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
EventManager::post<RequestSelectionChange>(Region { this->getOffset(), this->getSize() });
}
this->drawCommentTooltip(); this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight())); ImGui::ColorButton("color", ImColor(this->getColor()), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight()));
@ -1023,13 +1041,13 @@ namespace hex::pl {
this->m_entryCount = count; this->m_entryCount = count;
} }
void setEntries(PatternData *templ, size_t count) { void setEntries(PatternData *templatePattern, size_t count) {
this->m_template = templ; this->m_template = templatePattern;
this->m_highlightTemplate = this->m_template->clone(); this->m_highlightTemplate = this->m_template->clone();
this->m_entryCount = count; this->m_entryCount = count;
if (this->hasOverriddenColor()) this->setColor(this->m_template->getColor()); if (this->hasOverriddenColor()) this->setColor(this->m_template->getColor());
this->m_template->setEndian(templ->getEndian()); this->m_template->setEndian(templatePattern->getEndian());
} }
[[nodiscard]] bool operator==(const PatternData &other) const override { [[nodiscard]] bool operator==(const PatternData &other) const override {
@ -1093,8 +1111,11 @@ namespace hex::pl {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth); open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
EventManager::post<RequestSelectionChange>(Region { this->getOffset(), this->getSize() });
}
this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1)); ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1));
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@ -1240,8 +1261,11 @@ namespace hex::pl {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth); open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
EventManager::post<RequestSelectionChange>(Region { this->getOffset(), this->getSize() });
}
this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), std::max(this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1), u64(0))); ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), std::max(this->getOffset() + this->getSize() - (this->getSize() == 0 ? 0 : 1), u64(0)));
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@ -1556,8 +1580,11 @@ namespace hex::pl {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth); open = ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth);
this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::Selectable(("##PatternDataLine"s + std::to_string(this->getOffset())).c_str(), false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
EventManager::post<RequestSelectionChange>(Region { this->getOffset(), this->getSize() });
}
this->drawCommentTooltip();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1); ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", this->getOffset(), this->getOffset() + this->getSize() - 1);
ImGui::TableNextColumn(); ImGui::TableNextColumn();