mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
GTextEditor: Clean up some of the rect computations
Moving some rect computations to separate functions to make it easier to reuse them.
This commit is contained in:
parent
ac7a559d96
commit
23b70d5c59
2 changed files with 31 additions and 9 deletions
|
@ -258,9 +258,24 @@ Rect GTextEditor::ruler_content_rect(int line_index) const
|
||||||
return {};
|
return {};
|
||||||
return {
|
return {
|
||||||
0 - ruler_width() + horizontal_scrollbar().value(),
|
0 - ruler_width() + horizontal_scrollbar().value(),
|
||||||
line_index * line_height(),
|
line_content_rect(line_index).y(),
|
||||||
ruler_width(),
|
ruler_width(),
|
||||||
line_height()
|
line_content_rect(line_index).height()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect GTextEditor::ruler_rect_in_inner_coordinates() const
|
||||||
|
{
|
||||||
|
return { 0, 0, ruler_width(), height() - height_occupied_by_horizontal_scrollbar() };
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect GTextEditor::visible_text_rect_in_inner_coordinates() const
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
(m_horizontal_content_padding * 2) + (m_ruler_visible ? (ruler_rect_in_inner_coordinates().right() + 1) : 0),
|
||||||
|
0,
|
||||||
|
width() - width_occupied_by_vertical_scrollbar() - ruler_width(),
|
||||||
|
height() - height_occupied_by_horizontal_scrollbar()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +290,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
||||||
|
|
||||||
painter.translate(frame_thickness(), frame_thickness());
|
painter.translate(frame_thickness(), frame_thickness());
|
||||||
|
|
||||||
Rect ruler_rect { 0, 0, ruler_width(), height() - height_occupied_by_horizontal_scrollbar() };
|
auto ruler_rect = ruler_rect_in_inner_coordinates();
|
||||||
|
|
||||||
if (m_ruler_visible) {
|
if (m_ruler_visible) {
|
||||||
painter.fill_rect(ruler_rect, Color::WarmGray);
|
painter.fill_rect(ruler_rect, Color::WarmGray);
|
||||||
|
@ -305,7 +320,13 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.add_clip_rect({ m_ruler_visible ? (ruler_rect.right() + frame_thickness() + 1) : frame_thickness(), frame_thickness(), width() - width_occupied_by_vertical_scrollbar() - ruler_width(), height() - height_occupied_by_horizontal_scrollbar() });
|
Rect text_clip_rect {
|
||||||
|
(m_ruler_visible ? (ruler_rect_in_inner_coordinates().right() + frame_thickness() + 1) : frame_thickness()),
|
||||||
|
frame_thickness(),
|
||||||
|
width() - width_occupied_by_vertical_scrollbar() - ruler_width(),
|
||||||
|
height() - height_occupied_by_horizontal_scrollbar()
|
||||||
|
};
|
||||||
|
painter.add_clip_rect(text_clip_rect);
|
||||||
|
|
||||||
for (int i = first_visible_line; i <= last_visible_line; ++i) {
|
for (int i = first_visible_line; i <= last_visible_line; ++i) {
|
||||||
auto& line = m_lines[i];
|
auto& line = m_lines[i];
|
||||||
|
@ -685,7 +706,6 @@ Rect GTextEditor::content_rect_for_position(const GTextPosition& position) const
|
||||||
return { x, position.line() * line_height(), 1, line_height() };
|
return { x, position.line() * line_height(), 1, line_height() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Rect GTextEditor::cursor_content_rect() const
|
Rect GTextEditor::cursor_content_rect() const
|
||||||
{
|
{
|
||||||
return content_rect_for_position(m_cursor);
|
return content_rect_for_position(m_cursor);
|
||||||
|
|
|
@ -226,6 +226,8 @@ private:
|
||||||
void did_update_selection();
|
void did_update_selection();
|
||||||
int content_x_for_position(const GTextPosition&) const;
|
int content_x_for_position(const GTextPosition&) const;
|
||||||
char character_at(const GTextPosition&) const;
|
char character_at(const GTextPosition&) const;
|
||||||
|
Rect ruler_rect_in_inner_coordinates() const;
|
||||||
|
Rect visible_text_rect_in_inner_coordinates() const;
|
||||||
|
|
||||||
Type m_type { MultiLine };
|
Type m_type { MultiLine };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue