mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 00:47: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);
|
||||||
|
@ -1107,10 +1127,10 @@ GTextPosition GTextEditor::next_position_after(const GTextPosition& position, Sh
|
||||||
|
|
||||||
GTextPosition GTextEditor::prev_position_before(const GTextPosition& position, ShouldWrapAtStartOfDocument should_wrap)
|
GTextPosition GTextEditor::prev_position_before(const GTextPosition& position, ShouldWrapAtStartOfDocument should_wrap)
|
||||||
{
|
{
|
||||||
if (position.column() == 0){
|
if (position.column() == 0) {
|
||||||
if (position.line() == 0) {
|
if (position.line() == 0) {
|
||||||
if (should_wrap == ShouldWrapAtStartOfDocument::Yes) {
|
if (should_wrap == ShouldWrapAtStartOfDocument::Yes) {
|
||||||
auto& last_line = m_lines[line_count() - 1];
|
auto& last_line = m_lines[line_count() - 1];
|
||||||
return { line_count() - 1, last_line.length() };
|
return { line_count() - 1, last_line.length() };
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
@ -1146,7 +1166,7 @@ GTextRange GTextEditor::find_next(const StringView& needle, const GTextPosition&
|
||||||
needle_index = 0;
|
needle_index = 0;
|
||||||
}
|
}
|
||||||
position = next_position_after(position);
|
position = next_position_after(position);
|
||||||
} while(position.is_valid() && position != original_position);
|
} while (position.is_valid() && position != original_position);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -1176,7 +1196,7 @@ GTextRange GTextEditor::find_prev(const StringView& needle, const GTextPosition&
|
||||||
needle_index = needle.length() - 1;
|
needle_index = needle.length() - 1;
|
||||||
}
|
}
|
||||||
position = prev_position_before(position);
|
position = prev_position_before(position);
|
||||||
} while(position.is_valid() && position != original_position);
|
} while (position.is_valid() && position != original_position);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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