1
0
mirror of synced 2025-02-11 16:22:59 +01:00

impr: Make hex editor footer collapsible

This commit is contained in:
WerWolv 2023-12-07 11:20:54 +01:00
parent bfb2c6ab5f
commit f68202a098
2 changed files with 143 additions and 119 deletions

View File

@ -262,6 +262,7 @@ namespace hex::plugin::builtin::ui {
bool m_showHumanReadableUnits = true; bool m_showHumanReadableUnits = true;
bool m_syncScrolling = false; bool m_syncScrolling = false;
u32 m_byteCellPadding = 0, m_characterCellPadding = 0; u32 m_byteCellPadding = 0, m_characterCellPadding = 0;
bool m_footerCollapsed = true;
std::optional<EncodingFile> m_currCustomEncoding; std::optional<EncodingFile> m_currCustomEncoding;
std::vector<u64> m_encodingLineStartAddresses; std::vector<u64> m_encodingLineStartAddresses;

View File

@ -696,7 +696,10 @@ namespace hex::plugin::builtin::ui {
ImGui::GetWindowDrawList()->AddLine(windowEndPos - ImVec2(0, size.y - 1_scaled), windowEndPos - size + ImVec2(0, 1_scaled), ImGui::GetColorU32(ImGuiCol_Separator), 2.0_scaled); ImGui::GetWindowDrawList()->AddLine(windowEndPos - ImVec2(0, size.y - 1_scaled), windowEndPos - size + ImVec2(0, 1_scaled), ImGui::GetColorU32(ImGuiCol_Separator), 2.0_scaled);
if (ImGui::BeginChild("##footer", size, false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { if (ImGui::BeginChild("##footer", size, false, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
if (ImGui::BeginTable("##footer_table", 2)) { if (ImGui::BeginTable("##footer_table", 3, ImGuiTableFlags_SizingFixedFit)) {
ImGui::TableSetupColumn("Left", ImGuiTableColumnFlags_WidthStretch, 0.5f);
ImGui::TableSetupColumn("Center", ImGuiTableColumnFlags_WidthFixed, 20_scaled);
ImGui::TableSetupColumn("Right", ImGuiTableColumnFlags_WidthStretch, 0.5F);
ImGui::TableNextRow(); ImGui::TableNextRow();
// Page slider // Page slider
@ -709,12 +712,21 @@ namespace hex::plugin::builtin::ui {
ImGui::BeginDisabled(pageCount <= 1); ImGui::BeginDisabled(pageCount <= 1);
{ {
ImGui::PushItemWidth(-1);
if (ImGui::SliderScalar("##page_selection", ImGuiDataType_U32, &page, &MinPage, &pageCount, hex::format("0x%02llX / 0x{:02X}", pageCount).c_str())) if (ImGui::SliderScalar("##page_selection", ImGuiDataType_U32, &page, &MinPage, &pageCount, hex::format("0x%02llX / 0x{:02X}", pageCount).c_str()))
this->m_provider->setCurrentPage(page - 1); this->m_provider->setCurrentPage(page - 1);
ImGui::PopItemWidth();
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
} }
// Collapse button
ImGui::TableNextColumn();
{
if (ImGuiExt::DimmedIconButton(this->m_footerCollapsed ? ICON_VS_FOLD_UP : ICON_VS_FOLD_DOWN, ImGui::GetStyleColorVec4(ImGuiCol_Text)))
this->m_footerCollapsed = !this->m_footerCollapsed;
}
// Page Address // Page Address
ImGui::TableNextColumn(); ImGui::TableNextColumn();
{ {
@ -728,6 +740,7 @@ namespace hex::plugin::builtin::ui {
); );
} }
if (!this->m_footerCollapsed) {
ImGui::TableNextRow(); ImGui::TableNextRow();
// Selection // Selection
@ -753,6 +766,8 @@ namespace hex::plugin::builtin::ui {
ImGuiExt::TextFormattedSelectable(value); ImGuiExt::TextFormattedSelectable(value);
} }
ImGui::TableNextColumn();
// Loaded data size // Loaded data size
ImGui::TableNextColumn(); ImGui::TableNextColumn();
{ {
@ -769,6 +784,7 @@ namespace hex::plugin::builtin::ui {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
{
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 2_scaled); ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 2_scaled);
// Upper/lower case hex // Upper/lower case hex
@ -801,7 +817,9 @@ namespace hex::plugin::builtin::ui {
// Human-readable units // Human-readable units
ImGuiExt::DimmedIconToggle(ICON_VS_SYMBOL_NUMERIC, &this->m_showHumanReadableUnits); ImGuiExt::DimmedIconToggle(ICON_VS_SYMBOL_NUMERIC, &this->m_showHumanReadableUnits);
ImGuiExt::InfoTooltip("hex.builtin.hex_editor.human_readable_units_footer"_lang); ImGuiExt::InfoTooltip("hex.builtin.hex_editor.human_readable_units_footer"_lang);
}
ImGui::TableNextColumn();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
// Visualizer // Visualizer
@ -858,6 +876,7 @@ namespace hex::plugin::builtin::ui {
} }
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
}
ImGui::EndTable(); ImGui::EndTable();
} }
@ -891,16 +910,20 @@ namespace hex::plugin::builtin::ui {
void HexEditor::draw(float height) { void HexEditor::draw(float height) {
const auto width = ImGui::GetContentRegionAvail().x; const auto width = ImGui::GetContentRegionAvail().x;
auto FooterSize = ImVec2(width, ImGui::GetTextLineHeightWithSpacing() * 3.6F); auto footerSize = ImVec2(width, 0);
auto TableSize = ImVec2(width, height - FooterSize.y); if (!this->m_footerCollapsed)
footerSize.y = ImGui::GetTextLineHeightWithSpacing() * 3.6F;
else
footerSize.y = ImGui::GetTextLineHeightWithSpacing() * 1.4F;
if (TableSize.y <= 0) auto tableSize = ImVec2(width, height - footerSize.y);
TableSize.y = height; if (tableSize.y <= 0)
tableSize.y = height;
this->drawEditor(TableSize); this->drawEditor(tableSize);
if (TableSize.y > 0) if (tableSize.y > 0)
this->drawFooter(FooterSize); this->drawFooter(tableSize);
this->m_selectionChanged = false; this->m_selectionChanged = false;
} }