mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:07:35 +00:00
HexEditor: Make the application theme-aware
Also updates the ruler style a bit to be more consitent with TextEditor.
This commit is contained in:
parent
33864ab715
commit
6eae2ef9cf
1 changed files with 20 additions and 12 deletions
|
@ -49,6 +49,8 @@ HexEditor::HexEditor(GUI::Widget* parent)
|
||||||
set_frame_thickness(2);
|
set_frame_thickness(2);
|
||||||
set_scrollbars_enabled(true);
|
set_scrollbars_enabled(true);
|
||||||
set_font(GFontDatabase::the().get_by_name("Csilla Thin"));
|
set_font(GFontDatabase::the().get_by_name("Csilla Thin"));
|
||||||
|
set_background_role(ColorRole::Base);
|
||||||
|
set_foreground_role(ColorRole::BaseText);
|
||||||
vertical_scrollbar().set_step(line_height());
|
vertical_scrollbar().set_step(line_height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +486,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
||||||
GUI::Painter painter(*this);
|
GUI::Painter painter(*this);
|
||||||
painter.add_clip_rect(widget_inner_rect());
|
painter.add_clip_rect(widget_inner_rect());
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
painter.fill_rect(event.rect(), Color::White);
|
painter.fill_rect(event.rect(), palette().color(background_role()));
|
||||||
|
|
||||||
if (m_buffer.is_empty())
|
if (m_buffer.is_empty())
|
||||||
return;
|
return;
|
||||||
|
@ -498,13 +500,13 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
||||||
85,
|
85,
|
||||||
height() - height_occupied_by_horizontal_scrollbar() //(total_rows() * line_height()) + 5
|
height() - height_occupied_by_horizontal_scrollbar() //(total_rows() * line_height()) + 5
|
||||||
};
|
};
|
||||||
painter.fill_rect(offset_clip_rect, Color::WarmGray);
|
painter.fill_rect(offset_clip_rect, palette().ruler());
|
||||||
painter.draw_line(offset_clip_rect.top_right(), offset_clip_rect.bottom_right(), Color::DarkGray);
|
painter.draw_line(offset_clip_rect.top_right(), offset_clip_rect.bottom_right(), palette().ruler_border());
|
||||||
|
|
||||||
auto margin_and_hex_width = offset_margin_width() + (m_bytes_per_row * (character_width() * 3)) + 15;
|
auto margin_and_hex_width = offset_margin_width() + (m_bytes_per_row * (character_width() * 3)) + 15;
|
||||||
painter.draw_line({ margin_and_hex_width, 0 },
|
painter.draw_line({ margin_and_hex_width, 0 },
|
||||||
{ margin_and_hex_width, vertical_scrollbar().value() + (height() - height_occupied_by_horizontal_scrollbar()) },
|
{ margin_and_hex_width, vertical_scrollbar().value() + (height() - height_occupied_by_horizontal_scrollbar()) },
|
||||||
Color::LightGray);
|
palette().ruler_border());
|
||||||
|
|
||||||
auto view_height = (height() - height_occupied_by_horizontal_scrollbar());
|
auto view_height = (height() - height_occupied_by_horizontal_scrollbar());
|
||||||
auto min_row = max(0, vertical_scrollbar().value() / line_height()); // if below 0 then use 0
|
auto min_row = max(0, vertical_scrollbar().value() / line_height()); // if below 0 then use 0
|
||||||
|
@ -519,8 +521,14 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
||||||
height() - height_occupied_by_horizontal_scrollbar()
|
height() - height_occupied_by_horizontal_scrollbar()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool is_current_line = (m_position / bytes_per_row()) == i;
|
||||||
auto line = String::format("0x%08X", i * bytes_per_row());
|
auto line = String::format("0x%08X", i * bytes_per_row());
|
||||||
painter.draw_text(side_offset_rect, line);
|
painter.draw_text(
|
||||||
|
side_offset_rect,
|
||||||
|
line,
|
||||||
|
is_current_line ? Gfx::Font::default_bold_font() : font(),
|
||||||
|
Gfx::TextAlignment::TopLeft,
|
||||||
|
is_current_line ? palette().ruler_active_text() : palette().ruler_inactive_text());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = min_row; i < max_row; i++) {
|
for (int i = min_row; i < max_row; i++) {
|
||||||
|
@ -529,12 +537,11 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
||||||
if (byte_position >= m_buffer.size())
|
if (byte_position >= m_buffer.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Color text_color = Color::Black;
|
Color text_color = palette().color(foreground_role());
|
||||||
if (m_tracked_changes.contains(byte_position)) {
|
if (m_tracked_changes.contains(byte_position)) {
|
||||||
text_color = Color::Red;
|
text_color = Color::Red;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color highlight_color = palette().selection();
|
|
||||||
auto highlight_flag = false;
|
auto highlight_flag = false;
|
||||||
if (m_selection_start > -1 && m_selection_end > -1) {
|
if (m_selection_start > -1 && m_selection_end > -1) {
|
||||||
if (byte_position >= m_selection_start && byte_position <= m_selection_end) {
|
if (byte_position >= m_selection_start && byte_position <= m_selection_end) {
|
||||||
|
@ -552,10 +559,11 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
||||||
line_height() - m_line_spacing
|
line_height() - m_line_spacing
|
||||||
};
|
};
|
||||||
if (highlight_flag) {
|
if (highlight_flag) {
|
||||||
painter.fill_rect(hex_display_rect, highlight_color);
|
painter.fill_rect(hex_display_rect, palette().selection());
|
||||||
text_color = text_color == Color::Red ? Color::from_rgb(0xFFC0CB) : Color::White;
|
text_color = text_color == Color::Red ? Color::from_rgb(0xFFC0CB) : palette().selection_text();
|
||||||
} else if (byte_position == m_position) {
|
} else if (byte_position == m_position) {
|
||||||
painter.fill_rect(hex_display_rect, Color::from_rgb(0xCCCCCC));
|
painter.fill_rect(hex_display_rect, palette().inactive_selection());
|
||||||
|
text_color = palette().inactive_selection_text();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto line = String::format("%02X", m_buffer[byte_position]);
|
auto line = String::format("%02X", m_buffer[byte_position]);
|
||||||
|
@ -569,9 +577,9 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
|
||||||
};
|
};
|
||||||
// selection highlighting.
|
// selection highlighting.
|
||||||
if (highlight_flag) {
|
if (highlight_flag) {
|
||||||
painter.fill_rect(text_display_rect, highlight_color);
|
painter.fill_rect(text_display_rect, palette().selection());
|
||||||
} else if (byte_position == m_position) {
|
} else if (byte_position == m_position) {
|
||||||
painter.fill_rect(text_display_rect, Color::from_rgb(0xCCCCCC));
|
painter.fill_rect(text_display_rect, palette().inactive_selection());
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.draw_text(text_display_rect, String::format("%c", isprint(m_buffer[byte_position]) ? m_buffer[byte_position] : '.'), Gfx::TextAlignment::TopLeft, text_color);
|
painter.draw_text(text_display_rect, String::format("%c", isprint(m_buffer[byte_position]) ? m_buffer[byte_position] : '.'), Gfx::TextAlignment::TopLeft, text_color);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue