HexEditor: Share the code for updating the content size

And make setting the bytes_per_row a no-op if it's the same value.
This commit is contained in:
Sam Atkins 2024-02-05 11:57:40 +00:00 committed by Sam Atkins
parent db23d0f464
commit d3012f2df1
2 changed files with 12 additions and 6 deletions

View file

@ -232,23 +232,28 @@ bool HexEditor::copy_selected_hex_to_clipboard_as_c_code()
return true;
}
void HexEditor::set_bytes_per_row(size_t bytes_per_row)
void HexEditor::update_content_size()
{
m_bytes_per_row = bytes_per_row;
auto new_width = offset_area_width() + hex_area_width() + text_area_width();
auto new_height = total_rows() * line_height() + 2 * m_padding;
set_content_size({ static_cast<int>(new_width), static_cast<int>(new_height) });
update();
}
void HexEditor::set_bytes_per_row(size_t bytes_per_row)
{
if (bytes_per_row == m_bytes_per_row)
return;
m_bytes_per_row = bytes_per_row;
update_content_size();
}
void HexEditor::set_content_length(size_t length)
{
if (length == m_content_length)
return;
m_content_length = length;
auto new_width = offset_area_width() + hex_area_width() + text_area_width();
auto new_height = total_rows() * line_height() + 2 * m_padding;
set_content_size({ static_cast<int>(new_width), static_cast<int>(new_height) });
update_content_size();
}
Optional<u8> HexEditor::get_byte(size_t position)

View file

@ -125,7 +125,8 @@ private:
ErrorOr<void> hex_mode_keydown_event(GUI::KeyEvent&);
ErrorOr<void> text_mode_keydown_event(GUI::KeyEvent&);
void set_content_length(size_t); // I might make this public if I add fetching data on demand.
void set_content_length(size_t);
void update_content_size();
void update_status();
void did_change();
ErrorOr<void> did_complete_action(size_t position, u8 old_value, u8 new_value);