mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 00:04:58 +00:00
GTextEditor: Set content size based on the visual line rects (#500)
When we update our content size, the width & height is now calculated from the visual line rect size. Also now after we recompute all visual lines, if the total height is different, we re-update the content size.
This commit is contained in:
parent
b15a7c435f
commit
d3ebd8897f
1 changed files with 13 additions and 3 deletions
|
@ -108,12 +108,18 @@ void GTextEditor::set_text(const StringView& text)
|
|||
void GTextEditor::update_content_size()
|
||||
{
|
||||
int content_width = 0;
|
||||
for (auto& line : m_lines)
|
||||
content_width = max(line.width(font()), content_width);
|
||||
int content_height = 0;
|
||||
for (auto& line : m_lines) {
|
||||
line.for_each_visual_line([&](const Rect& rect, const StringView&, int) {
|
||||
content_width = max(rect.width(), content_width);
|
||||
content_height += rect.height();
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
content_width += m_horizontal_content_padding * 2;
|
||||
if (is_right_text_alignment(m_text_alignment))
|
||||
content_width = max(frame_inner_rect().width(), content_width);
|
||||
int content_height = line_count() * line_height();
|
||||
|
||||
set_content_size({ content_width, content_height });
|
||||
set_size_occupied_by_fixed_elements({ ruler_width(), 0 });
|
||||
}
|
||||
|
@ -1360,6 +1366,10 @@ void GTextEditor::recompute_all_visual_lines()
|
|||
line.m_visual_rect.set_y(y_offset);
|
||||
y_offset += line.m_visual_rect.height();
|
||||
}
|
||||
if (content_size().height() == y_offset)
|
||||
return;
|
||||
|
||||
update_content_size();
|
||||
}
|
||||
|
||||
void GTextEditor::Line::recompute_visual_lines()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue