mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:37:44 +00:00
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:
parent
db23d0f464
commit
d3012f2df1
2 changed files with 12 additions and 6 deletions
|
@ -232,23 +232,28 @@ bool HexEditor::copy_selected_hex_to_clipboard_as_c_code()
|
||||||
return true;
|
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_width = offset_area_width() + hex_area_width() + text_area_width();
|
||||||
auto new_height = total_rows() * line_height() + 2 * m_padding;
|
auto new_height = total_rows() * line_height() + 2 * m_padding;
|
||||||
set_content_size({ static_cast<int>(new_width), static_cast<int>(new_height) });
|
set_content_size({ static_cast<int>(new_width), static_cast<int>(new_height) });
|
||||||
update();
|
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)
|
void HexEditor::set_content_length(size_t length)
|
||||||
{
|
{
|
||||||
if (length == m_content_length)
|
if (length == m_content_length)
|
||||||
return;
|
return;
|
||||||
m_content_length = length;
|
m_content_length = length;
|
||||||
auto new_width = offset_area_width() + hex_area_width() + text_area_width();
|
update_content_size();
|
||||||
auto new_height = total_rows() * line_height() + 2 * m_padding;
|
|
||||||
set_content_size({ static_cast<int>(new_width), static_cast<int>(new_height) });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<u8> HexEditor::get_byte(size_t position)
|
Optional<u8> HexEditor::get_byte(size_t position)
|
||||||
|
|
|
@ -125,7 +125,8 @@ private:
|
||||||
ErrorOr<void> hex_mode_keydown_event(GUI::KeyEvent&);
|
ErrorOr<void> hex_mode_keydown_event(GUI::KeyEvent&);
|
||||||
ErrorOr<void> text_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 update_status();
|
||||||
void did_change();
|
void did_change();
|
||||||
ErrorOr<void> did_complete_action(size_t position, u8 old_value, u8 new_value);
|
ErrorOr<void> did_complete_action(size_t position, u8 old_value, u8 new_value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue