mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
GTextEditor: Fix wrong width calculations with line-wrapping enabled
There were various little mistakes in the width calculations used by the line-wrapping layout code. With this patch, we should no longer see the horizontal scrollbar get enabled with line-wrapping enabled. I will hide the scrollbar in a separate patch.
This commit is contained in:
parent
74ca299b4b
commit
906582d8df
2 changed files with 4 additions and 14 deletions
|
@ -306,10 +306,10 @@ Rect GTextEditor::ruler_rect_in_inner_coordinates() const
|
||||||
Rect GTextEditor::visible_text_rect_in_inner_coordinates() const
|
Rect GTextEditor::visible_text_rect_in_inner_coordinates() const
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
(m_horizontal_content_padding * 2) + (m_ruler_visible ? (ruler_rect_in_inner_coordinates().right() + 1) : 0),
|
m_horizontal_content_padding + (m_ruler_visible ? (ruler_rect_in_inner_coordinates().right() + 1) : 0),
|
||||||
0,
|
0,
|
||||||
width() - width_occupied_by_vertical_scrollbar() - ruler_width(),
|
frame_inner_rect().width() - (m_horizontal_content_padding * 2) - width_occupied_by_vertical_scrollbar() - ruler_width(),
|
||||||
height() - height_occupied_by_horizontal_scrollbar()
|
frame_inner_rect().height() - height_occupied_by_horizontal_scrollbar()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -941,13 +941,6 @@ void GTextEditor::Line::set_text(const StringView& text)
|
||||||
memcpy(m_text.data(), text.characters_without_null_termination(), text.length() + 1);
|
memcpy(m_text.data(), text.characters_without_null_termination(), text.length() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GTextEditor::Line::width(const Font& font) const
|
|
||||||
{
|
|
||||||
if (m_editor.is_line_wrapping_enabled())
|
|
||||||
return m_editor.visible_text_rect_in_inner_coordinates().width();
|
|
||||||
return font.width(view());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GTextEditor::Line::append(const char* characters, int length)
|
void GTextEditor::Line::append(const char* characters, int length)
|
||||||
{
|
{
|
||||||
int old_length = m_text.size() - 1;
|
int old_length = m_text.size() - 1;
|
||||||
|
@ -1367,8 +1360,6 @@ void GTextEditor::recompute_all_visual_lines()
|
||||||
line.m_visual_rect.set_y(y_offset);
|
line.m_visual_rect.set_y(y_offset);
|
||||||
y_offset += line.m_visual_rect.height();
|
y_offset += line.m_visual_rect.height();
|
||||||
}
|
}
|
||||||
if (content_size().height() == y_offset)
|
|
||||||
return;
|
|
||||||
|
|
||||||
update_content_size();
|
update_content_size();
|
||||||
}
|
}
|
||||||
|
@ -1387,7 +1378,7 @@ void GTextEditor::Line::recompute_visual_lines()
|
||||||
auto glyph_width = m_editor.font().glyph_width(ch);
|
auto glyph_width = m_editor.font().glyph_width(ch);
|
||||||
if ((line_width_so_far + glyph_width) > available_width) {
|
if ((line_width_so_far + glyph_width) > available_width) {
|
||||||
m_visual_line_breaks.append(i);
|
m_visual_line_breaks.append(i);
|
||||||
line_width_so_far = 0;
|
line_width_so_far = glyph_width;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
line_width_so_far += glyph_width;
|
line_width_so_far += glyph_width;
|
||||||
|
|
|
@ -199,7 +199,6 @@ private:
|
||||||
StringView view() const { return { characters(), length() }; }
|
StringView view() const { return { characters(), length() }; }
|
||||||
const char* characters() const { return m_text.data(); }
|
const char* characters() const { return m_text.data(); }
|
||||||
int length() const { return m_text.size() - 1; }
|
int length() const { return m_text.size() - 1; }
|
||||||
int width(const Font&) const;
|
|
||||||
void set_text(const StringView&);
|
void set_text(const StringView&);
|
||||||
void append(char);
|
void append(char);
|
||||||
void prepend(char);
|
void prepend(char);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue