diff options
author | Karol Kosek <krkk@serenityos.org> | 2022-07-10 23:53:23 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-11 18:11:11 +0200 |
commit | ff0b4bf360dc6d8c32c7efe3284f789677562450 (patch) | |
tree | b5408dcae8150d81d25ea48afa343549ba974cd8 /Userland/Applications/HexEditor/HexEditor.cpp | |
parent | 8717e78918ba071e981cab23440acd0f7142dc35 (diff) | |
download | serenity-ff0b4bf360dc6d8c32c7efe3284f789677562450.zip |
HexEditor: Gray-out null bytes
This should improve an overall visibility of "meaningful" data. :^)
Diffstat (limited to 'Userland/Applications/HexEditor/HexEditor.cpp')
-rw-r--r-- | Userland/Applications/HexEditor/HexEditor.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index 2aebcd1f5a..c76504e3f4 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -604,8 +604,17 @@ void HexEditor::paint_event(GUI::PaintEvent& event) line_height() - m_line_spacing }; + const u8 cell_value = m_document->get(byte_position).value; + auto line = String::formatted("{:02X}", cell_value); + Gfx::Color background_color = palette().color(background_role()); - Gfx::Color text_color = edited_flag ? Color::Red : palette().color(foreground_role()); + Gfx::Color text_color = [&]() -> Gfx::Color { + if (edited_flag) + return Color::Red; + if (cell_value == 0x00) + return palette().color(ColorRole::PlaceholderText); + return palette().color(foreground_role()); + }(); if (highlight_flag) { background_color = edited_flag ? palette().selection().inverted() : palette().selection(); @@ -616,8 +625,6 @@ void HexEditor::paint_event(GUI::PaintEvent& event) } painter.fill_rect(hex_display_rect, background_color); - const u8 cell_value = m_document->get(byte_position).value; - auto line = String::formatted("{:02X}", cell_value); painter.draw_text(hex_display_rect, line, Gfx::TextAlignment::TopLeft, text_color); if (m_edit_mode == EditMode::Hex) { @@ -640,7 +647,13 @@ void HexEditor::paint_event(GUI::PaintEvent& event) }; background_color = palette().color(background_role()); - text_color = edited_flag ? Color::Red : palette().color(foreground_role()); + text_color = [&]() -> Gfx::Color { + if (edited_flag) + return Color::Red; + if (cell_value == 0x00) + return palette().color(ColorRole::PlaceholderText); + return palette().color(foreground_role()); + }(); if (highlight_flag) { background_color = edited_flag ? palette().selection().inverted() : palette().selection(); |