1
0
mirror of synced 2025-01-10 21:41:53 +01:00

feat: Added option to move selection back to hex editor footer

Closes #2024
This commit is contained in:
WerWolv 2024-12-29 21:08:08 +01:00
parent 3024c79f4f
commit 5f5f6ac539
7 changed files with 52 additions and 19 deletions

View File

@ -493,6 +493,7 @@
"hex.builtin.setting.hex_editor.pattern_parent_highlighting": "Highlight pattern parents on hover",
"hex.builtin.setting.hex_editor.paste_behaviour": "Single-Byte Paste behaviour",
"hex.builtin.setting.hex_editor.sync_scrolling": "Synchronize editor scroll position",
"hex.builtin.setting.hex_editor.show_selection": "Move selection display to hex editor footer",
"hex.builtin.setting.imhex": "ImHex",
"hex.builtin.setting.imhex.recent_files": "Recent Files",
"hex.builtin.setting.interface": "Interface",

View File

@ -834,6 +834,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Settings::add<Widgets::ColorPicker>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.highlight_color", ImColor(0x80, 0x80, 0xC0, 0x60));
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.sync_scrolling", false);
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.show_selection", false);
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.byte_padding", 0, 0, 50);
ContentRegistry::Settings::add<Widgets::SliderInteger>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.char_padding", 0, 0, 50);

View File

@ -313,16 +313,6 @@ namespace hex::plugin::builtin {
}
}
});
ContentRegistry::Interface::addFooterItem([] {
if (auto selection = ImHexApi::HexEditor::getSelection(); selection.has_value()) {
ImGuiExt::TextFormatted("0x{0:02X} - 0x{1:02X} (0x{2:02X} | {2} bytes)",
selection->getStartAddress(),
selection->getEndAddress(),
selection->getSize()
);
}
});
}
static void drawProviderContextMenu(prv::Provider *provider) {

View File

@ -1110,6 +1110,26 @@ namespace hex::plugin::builtin {
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.char_padding", [this](const ContentRegistry::Settings::SettingsValue &value) {
m_hexEditor.setCharacterCellPadding(value.get<int>(0));
});
static bool showSelectionInWindowFooter = true;
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.show_selection", [this](const ContentRegistry::Settings::SettingsValue &value) {
const auto show = value.get<bool>(false);
m_hexEditor.setShowSelectionInFooter(show);
showSelectionInWindowFooter = !show;
});
ContentRegistry::Interface::addFooterItem([] {
if (!showSelectionInWindowFooter) return;
if (auto selection = ImHexApi::HexEditor::getSelection(); selection.has_value()) {
ImGuiExt::TextFormatted("0x{0:02X} - 0x{1:02X} (0x{2:02X} | {2} bytes)",
selection->getStartAddress(),
selection->getEndAddress(),
selection->getSize()
);
}
});
}
void ViewHexEditor::registerMenuItems() {

View File

@ -90,6 +90,11 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
registerMainMenuEntries();
addFooterItems();
addTitleBarButtons();
addToolbarItems();
addGlobalUIItems();
registerEventHandlers();
registerDataVisualizers();
registerMiniMapVisualizers();
@ -122,10 +127,5 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
addWindowDecoration();
createWelcomeScreen();
addFooterItems();
addTitleBarButtons();
addToolbarItems();
addGlobalUIItems();
setupOutOfBoxExperience();
}

View File

@ -279,6 +279,10 @@ namespace hex::ui {
m_tooltipCallback = callback;
}
void setShowSelectionInFooter(bool showSelection) {
m_showSelectionInFooter = showSelection;
}
[[nodiscard]] i64 getScrollPosition() {
return m_scrollPosition.get();
}
@ -367,6 +371,7 @@ namespace hex::ui {
bool m_showAscii = true;
bool m_showCustomEncoding = true;
bool m_showMiniMap = false;
bool m_showSelectionInFooter = false;
int m_miniMapWidth = 5;
u32 m_byteCellPadding = 0, m_characterCellPadding = 0;
bool m_footerCollapsed = true;

View File

@ -1,4 +1,3 @@
#include <algorithm>
#include <ui/hex_editor.hpp>
#include <hex/api/content_registry.hpp>
@ -12,6 +11,8 @@
#include <fonts/vscode_icons.hpp>
#include <hex/providers/buffered_reader.hpp>
#include <algorithm>
namespace hex::ui {
/* Data Visualizer */
@ -1075,6 +1076,14 @@ namespace hex::ui {
}
}
ImGui::SameLine(0, 15_scaled);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 2_scaled);
if (m_mode == Mode::Insert) {
ImGui::TextUnformatted("[ INSERT ]");
} else {
ImGui::Dummy({});
}
// Collapse button
ImGui::TableNextColumn();
{
@ -1084,9 +1093,16 @@ namespace hex::ui {
ImGui::TableNextColumn();
ImGui::SameLine(0, 20_scaled);
if (m_mode == Mode::Insert) {
ImGui::TextUnformatted("[ INSERT ]");
if (m_showSelectionInFooter && this->isSelectionValid()) {
const auto selection = this->getSelection();
ImGui::SameLine(0, 15_scaled);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 2_scaled);
ImGuiExt::TextFormattedSelectable("0x{0:02X} - 0x{1:02X} (0x{2:02X} | {2} bytes)",
selection.getStartAddress(),
selection.getEndAddress(),
selection.getSize()
);
}
if (!m_footerCollapsed) {