mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 23:58:12 +00:00
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.
This commit is contained in:
parent
f1eba2295d
commit
0c88ce9ee3
2 changed files with 12 additions and 7 deletions
|
@ -95,6 +95,8 @@ void GTextEditor::update_content_size()
|
||||||
for (auto& line : m_lines)
|
for (auto& line : m_lines)
|
||||||
content_width = max(line->width(font()), content_width);
|
content_width = max(line->width(font()), content_width);
|
||||||
content_width += m_horizontal_content_padding * 2;
|
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();
|
int content_height = line_count() * line_height();
|
||||||
set_content_size({ content_width, content_height });
|
set_content_size({ content_width, content_height });
|
||||||
set_size_occupied_by_fixed_elements({ ruler_width(), 0 });
|
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();
|
column_index = position.x() / glyph_width();
|
||||||
break;
|
break;
|
||||||
case TextAlignment::CenterRight:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
|
@ -566,10 +568,8 @@ int GTextEditor::content_x_for_position(const GTextPosition& position) const
|
||||||
switch (m_text_alignment) {
|
switch (m_text_alignment) {
|
||||||
case TextAlignment::CenterLeft:
|
case TextAlignment::CenterLeft:
|
||||||
return m_horizontal_content_padding + position.column() * glyph_width();
|
return m_horizontal_content_padding + position.column() * glyph_width();
|
||||||
break;
|
|
||||||
case TextAlignment::CenterRight:
|
case TextAlignment::CenterRight:
|
||||||
return frame_inner_rect().right() + 1 - m_horizontal_content_padding - (line.length() * glyph_width()) + (position.column() * glyph_width());
|
return content_width() - m_horizontal_content_padding - (line.length() * glyph_width()) + (position.column() * glyph_width());
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -606,9 +606,7 @@ Rect GTextEditor::line_widget_rect(int line_index) const
|
||||||
|
|
||||||
void GTextEditor::scroll_cursor_into_view()
|
void GTextEditor::scroll_cursor_into_view()
|
||||||
{
|
{
|
||||||
auto rect = cursor_content_rect();
|
scroll_into_view(cursor_content_rect(), true, true);
|
||||||
rect.set_x(content_x_for_position(m_cursor));
|
|
||||||
scroll_into_view(rect, true, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect GTextEditor::line_content_rect(int line_index) const
|
Rect GTextEditor::line_content_rect(int line_index) const
|
||||||
|
@ -954,3 +952,9 @@ void GTextEditor::set_text_alignment(TextAlignment alignment)
|
||||||
m_text_alignment = alignment;
|
m_text_alignment = alignment;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GTextEditor::resize_event(GResizeEvent& event)
|
||||||
|
{
|
||||||
|
GScrollableWidget::resize_event(event);
|
||||||
|
update_content_size();
|
||||||
|
}
|
||||||
|
|
|
@ -133,6 +133,7 @@ private:
|
||||||
virtual void enter_event(CEvent&) override;
|
virtual void enter_event(CEvent&) override;
|
||||||
virtual void leave_event(CEvent&) override;
|
virtual void leave_event(CEvent&) override;
|
||||||
virtual void context_menu_event(GContextMenuEvent&) override;
|
virtual void context_menu_event(GContextMenuEvent&) override;
|
||||||
|
virtual void resize_event(GResizeEvent&) override;
|
||||||
|
|
||||||
void create_actions();
|
void create_actions();
|
||||||
void paint_ruler(Painter&);
|
void paint_ruler(Painter&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue