From d4c051ece2befd6a85b0d070b2baed47255ea2b5 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sun, 10 Mar 2024 21:14:20 +0000 Subject: [PATCH] HexEditor: Add gaps between byte groups --- Userland/Applications/HexEditor/HexEditor.cpp | 12 ++++++++---- Userland/Applications/HexEditor/HexEditor.h | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index a1296ceacc..6413b7fe0b 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -312,9 +312,10 @@ Optional HexEditor::offset_at(Gfx::IntPoint position) con auto hex_text_end_x = hex_end_x - m_padding; absolute_x = clamp(absolute_x, hex_text_start_x, hex_text_end_x); - auto byte_x = (absolute_x - hex_text_start_x) / cell_width(); + auto group_x = (absolute_x - hex_text_start_x) / group_width(); + auto byte_within_group = (absolute_x - hex_text_start_x - group_x * group_width()) / cell_width(); auto byte_y = (absolute_y - hex_start_y) / line_height(); - auto offset = (byte_y * bytes_per_row()) + byte_x; + auto offset = (byte_y * bytes_per_row()) + (group_x * bytes_per_group()) + byte_within_group; if (offset >= m_document->size()) return {}; @@ -666,11 +667,14 @@ void HexEditor::paint_event(GUI::PaintEvent& event) if (byte_position >= m_document->size()) return; + auto group = column / bytes_per_group(); + auto column_within_group = column % bytes_per_group(); + auto const cell = m_document->get(byte_position); auto const annotation = m_document->annotations().closest_annotation_at(byte_position); Gfx::IntRect hex_display_rect_high_nibble { - static_cast(hex_area_text_start_x + column * cell_width()), + static_cast(hex_area_text_start_x + (group * group_width()) + (column_within_group * cell_width())), row_text_y, static_cast(character_width()), static_cast(line_height() - m_line_spacing), @@ -686,7 +690,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event) Gfx::IntRect background_rect { static_cast(hex_display_rect_high_nibble.x() - character_width() / 2), row_background_y, - static_cast(cell_width()), + static_cast(character_width() * 3), static_cast(line_height()), }; diff --git a/Userland/Applications/HexEditor/HexEditor.h b/Userland/Applications/HexEditor/HexEditor.h index b83a4ce123..54dc1decf5 100644 --- a/Userland/Applications/HexEditor/HexEditor.h +++ b/Userland/Applications/HexEditor/HexEditor.h @@ -116,10 +116,23 @@ private: size_t total_rows() const { return ceil_div(m_content_length, bytes_per_row()); } size_t line_height() const { return font().pixel_size_rounded_up() + m_line_spacing; } size_t character_width() const { return font().glyph_fixed_width(); } - size_t cell_width() const { return character_width() * 3; } + size_t cell_gap() const { return character_width() / 2; } + size_t cell_width() const { return character_width() * 2 + cell_gap(); } + size_t group_gap() const { return character_width() * 1.5; } + size_t group_width() const + { + return (character_width() * 2 * bytes_per_group()) + + (cell_gap() * (bytes_per_group() - 1)) + + group_gap(); + } int offset_area_width() const { return m_padding + font().width_rounded_up("0X12345678"sv) + m_padding; } - int hex_area_width() const { return m_padding + bytes_per_row() * cell_width() + m_padding; } + int hex_area_width() const + { + return m_padding + + groups_per_row() * group_width() - group_gap() + + m_padding; + } int text_area_width() const { return m_padding + bytes_per_row() * character_width() + m_padding; } struct OffsetData {