Skip to content

Commit

Permalink
feat: Added setting to disable hex editor highlights entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Dec 30, 2024
1 parent 0ae8237 commit 8911105
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 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 @@ -494,6 +494,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_highlights": "Show colorful highlightings",
"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",
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 @@ -835,6 +835,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::Checkbox>("hex.builtin.setting.hex_editor", "", "hex.builtin.setting.hex_editor.show_highlights", true);
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
18 changes: 13 additions & 5 deletions plugins/builtin/source/content/views/view_hex_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ namespace hex::plugin::builtin {
u64 inputA = m_region.getStartAddress();
u64 inputB = m_region.getEndAddress();

if (justOpened) {
if (m_justOpened) {
ImGui::SetKeyboardFocusHere();
justOpened = false;
m_justOpened = false;
}
ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.begin"_lang, &inputA, ImGuiInputTextFlags_AutoSelectAll);
ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.end"_lang, &inputB, ImGuiInputTextFlags_AutoSelectAll);
Expand All @@ -173,9 +173,9 @@ namespace hex::plugin::builtin {
u64 inputA = m_region.getStartAddress();
u64 inputB = m_region.getSize();

if (justOpened) {
if (m_justOpened) {
ImGui::SetKeyboardFocusHere();
justOpened = false;
m_justOpened = false;
}
ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.begin"_lang, &inputA, ImGuiInputTextFlags_AutoSelectAll);
ImGuiExt::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.size"_lang, &inputB, ImGuiInputTextFlags_AutoSelectAll);
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace hex::plugin::builtin {

private:
Region m_region = { 0, 1 };
bool justOpened = true;
bool m_justOpened = true;
};

class PopupBaseAddress : public ViewHexEditor::Popup {
Expand Down Expand Up @@ -550,7 +550,15 @@ namespace hex::plugin::builtin {
return result;
});

static bool showHighlights = true;
ContentRegistry::Settings::onChange("hex.builtin.setting.hex_editor", "hex.builtin.setting.hex_editor.show_highlights", [](const ContentRegistry::Settings::SettingsValue &value) {
showHighlights = value.get<bool>(true);
});

m_hexEditor.setBackgroundHighlightCallback([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
if (!showHighlights)
return std::nullopt;

if (auto highlight = m_backgroundHighlights->find(address); highlight != m_backgroundHighlights->end()) {
if (std::ranges::any_of(*m_hoverHighlights, [region = Region(address, size)](const Region &highlight) { return highlight.overlaps(region); }))
return ImAlphaBlendColors(highlight->second, 0xA0FFFFFF);
Expand Down

0 comments on commit 8911105

Please sign in to comment.