Skip to content

Commit

Permalink
feat: Added option to move selection back to hex editor footer
Browse files Browse the repository at this point in the history
Closes #2024
  • Loading branch information
WerWolv committed Dec 29, 2024
1 parent 3024c79 commit 5f5f6ac
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 19 deletions.
1 change: 1 addition & 0 deletions plugins/builtin/romfs/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions plugins/builtin/source/content/settings_entries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 0 additions & 10 deletions plugins/builtin/source/content/ui_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions plugins/builtin/source/content/views/view_hex_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions plugins/builtin/source/plugin_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {

registerMainMenuEntries();

addFooterItems();
addTitleBarButtons();
addToolbarItems();
addGlobalUIItems();

registerEventHandlers();
registerDataVisualizers();
registerMiniMapVisualizers();
Expand Down Expand Up @@ -122,10 +127,5 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
addWindowDecoration();
createWelcomeScreen();

addFooterItems();
addTitleBarButtons();
addToolbarItems();
addGlobalUIItems();

setupOutOfBoxExperience();
}
5 changes: 5 additions & 0 deletions plugins/ui/include/ui/hex_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ namespace hex::ui {
m_tooltipCallback = callback;
}

void setShowSelectionInFooter(bool showSelection) {
m_showSelectionInFooter = showSelection;
}

[[nodiscard]] i64 getScrollPosition() {
return m_scrollPosition.get();
}
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 20 additions & 4 deletions plugins/ui/source/ui/hex_editor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <algorithm>
#include <ui/hex_editor.hpp>

#include <hex/api/content_registry.hpp>
Expand All @@ -12,6 +11,8 @@
#include <fonts/vscode_icons.hpp>
#include <hex/providers/buffered_reader.hpp>

#include <algorithm>

namespace hex::ui {

/* Data Visualizer */
Expand Down Expand Up @@ -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();
{
Expand All @@ -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) {
Expand Down

0 comments on commit 5f5f6ac

Please sign in to comment.