summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-24 23:42:49 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-24 23:42:49 +0200
commit0c88ce9ee302ec295e903ef65b8e7d4b8758b9bd (patch)
treefa4df37423c01549ac15f87b20772d0d5ce82661 /LibGUI
parentf1eba2295db08286a82d75da77d9222af0ba9f4a (diff)
downloadserenity-0c88ce9ee302ec295e903ef65b8e7d4b8758b9bd.zip
GTextEditor: Expand the content "to-fill" for right aligned text.
When using a right-side text alignment, hook the resize event to make sure that the content width is at least frame_inner_rect().width() wide. This allows us to use content_width() as the anchor point for right aligned text, rather than using the frame inner rect, which was clearly wrong in the overflow case.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GTextEditor.cpp18
-rw-r--r--LibGUI/GTextEditor.h1
2 files changed, 12 insertions, 7 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index 7c114f221a..bc0750394d 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -95,6 +95,8 @@ void GTextEditor::update_content_size()
for (auto& line : m_lines)
content_width = max(line->width(font()), content_width);
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 });
@@ -115,7 +117,7 @@ GTextPosition GTextEditor::text_position_at(const Point& a_position) const
column_index = position.x() / glyph_width();
break;
case TextAlignment::CenterRight:
- column_index = (position.x() - (frame_inner_rect().right() + 1 - (line.length() * glyph_width()))) / glyph_width();
+ column_index = (position.x() - (content_width() - (line.length() * glyph_width()))) / glyph_width();
break;
default:
ASSERT_NOT_REACHED();
@@ -566,10 +568,8 @@ int GTextEditor::content_x_for_position(const GTextPosition& position) const
switch (m_text_alignment) {
case TextAlignment::CenterLeft:
return m_horizontal_content_padding + position.column() * glyph_width();
- break;
case TextAlignment::CenterRight:
- return frame_inner_rect().right() + 1 - m_horizontal_content_padding - (line.length() * glyph_width()) + (position.column() * glyph_width());
- break;
+ return content_width() - m_horizontal_content_padding - (line.length() * glyph_width()) + (position.column() * glyph_width());
default:
ASSERT_NOT_REACHED();
}
@@ -606,9 +606,7 @@ Rect GTextEditor::line_widget_rect(int line_index) const
void GTextEditor::scroll_cursor_into_view()
{
- auto rect = cursor_content_rect();
- rect.set_x(content_x_for_position(m_cursor));
- scroll_into_view(rect, true, true);
+ scroll_into_view(cursor_content_rect(), true, true);
}
Rect GTextEditor::line_content_rect(int line_index) const
@@ -954,3 +952,9 @@ void GTextEditor::set_text_alignment(TextAlignment alignment)
m_text_alignment = alignment;
update();
}
+
+void GTextEditor::resize_event(GResizeEvent& event)
+{
+ GScrollableWidget::resize_event(event);
+ update_content_size();
+}
diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h
index 6df130f7eb..9b31274cb9 100644
--- a/LibGUI/GTextEditor.h
+++ b/LibGUI/GTextEditor.h
@@ -133,6 +133,7 @@ private:
virtual void enter_event(CEvent&) override;
virtual void leave_event(CEvent&) override;
virtual void context_menu_event(GContextMenuEvent&) override;
+ virtual void resize_event(GResizeEvent&) override;
void create_actions();
void paint_ruler(Painter&);