mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibGfx: Add support for TextAlignment::TopCenter / BottomCenter
Now supports TextAlignment::TopCenter and TextAlignment::BottomCenter for the Painter::draw_text. Also patched this in Spreadsheet/CellTypeDialog.cpp
This commit is contained in:
parent
73ade62d4f
commit
3b22fd9a9f
5 changed files with 33 additions and 2 deletions
|
@ -74,10 +74,12 @@ constexpr static CellTypeDialog::VerticalAlignment vertical_alignment_from(Gfx::
|
|||
case Gfx::TextAlignment::Center:
|
||||
return CellTypeDialog::VerticalAlignment::Center;
|
||||
|
||||
case Gfx::TextAlignment::TopCenter:
|
||||
case Gfx::TextAlignment::TopRight:
|
||||
case Gfx::TextAlignment::TopLeft:
|
||||
return CellTypeDialog::VerticalAlignment::Top;
|
||||
|
||||
case Gfx::TextAlignment::BottomCenter:
|
||||
case Gfx::TextAlignment::BottomLeft:
|
||||
case Gfx::TextAlignment::BottomRight:
|
||||
return CellTypeDialog::VerticalAlignment::Bottom;
|
||||
|
@ -89,7 +91,9 @@ constexpr static CellTypeDialog::VerticalAlignment vertical_alignment_from(Gfx::
|
|||
constexpr static CellTypeDialog::HorizontalAlignment horizontal_alignment_from(Gfx::TextAlignment alignment)
|
||||
{
|
||||
switch (alignment) {
|
||||
case Gfx::TextAlignment::BottomCenter:
|
||||
case Gfx::TextAlignment::Center:
|
||||
case Gfx::TextAlignment::TopCenter:
|
||||
return CellTypeDialog::HorizontalAlignment::Center;
|
||||
|
||||
case Gfx::TextAlignment::TopRight:
|
||||
|
|
|
@ -376,8 +376,10 @@ T* Object::find_descendant_of_type_named(String const& name) requires IsBaseOf<O
|
|||
{ Gfx::TextAlignment::Center, "Center" }, \
|
||||
{ Gfx::TextAlignment::CenterLeft, "CenterLeft" }, \
|
||||
{ Gfx::TextAlignment::CenterRight, "CenterRight" }, \
|
||||
{ Gfx::TextAlignment::TopLeft, "TopCenter" }, \
|
||||
{ Gfx::TextAlignment::TopLeft, "TopLeft" }, \
|
||||
{ Gfx::TextAlignment::TopRight, "TopRight" }, \
|
||||
{ Gfx::TextAlignment::TopLeft, "BottomCenter" }, \
|
||||
{ Gfx::TextAlignment::BottomLeft, "BottomLeft" }, \
|
||||
{ Gfx::TextAlignment::BottomRight, "BottomRight" })
|
||||
|
||||
|
|
|
@ -1336,6 +1336,8 @@ void draw_text_line(IntRect const& a_rect, Utf8View const& text, Font const& fon
|
|||
case TextAlignment::BottomRight:
|
||||
rect.set_x(rect.right() - font.width(text));
|
||||
break;
|
||||
case TextAlignment::TopCenter:
|
||||
case TextAlignment::BottomCenter:
|
||||
case TextAlignment::Center: {
|
||||
auto shrunken_rect = rect;
|
||||
shrunken_rect.set_width(font.width(text));
|
||||
|
@ -1554,6 +1556,10 @@ void Painter::do_draw_text(IntRect const& rect, Utf8View const& text, Font const
|
|||
auto bounding_rect = layout.bounding_rect(wrapping, line_spacing);
|
||||
|
||||
switch (alignment) {
|
||||
case TextAlignment::TopCenter:
|
||||
bounding_rect.set_y(rect.y());
|
||||
bounding_rect.center_horizontally_within(rect);
|
||||
break;
|
||||
case TextAlignment::TopLeft:
|
||||
bounding_rect.set_location(rect.location());
|
||||
break;
|
||||
|
@ -1569,6 +1575,10 @@ void Painter::do_draw_text(IntRect const& rect, Utf8View const& text, Font const
|
|||
case TextAlignment::Center:
|
||||
bounding_rect.center_within(rect);
|
||||
break;
|
||||
case TextAlignment::BottomCenter:
|
||||
bounding_rect.set_y((rect.bottom() + 1) - bounding_rect.height());
|
||||
bounding_rect.center_horizontally_within(rect);
|
||||
break;
|
||||
case TextAlignment::BottomLeft:
|
||||
bounding_rect.set_location({ rect.x(), (rect.bottom() + 1) - bounding_rect.height() });
|
||||
break;
|
||||
|
|
|
@ -132,9 +132,15 @@ Rect<T> Rect<T>::aligned_within(Size<T> const& rect_size, Point<T> const& align_
|
|||
|
||||
Rect<T> rect;
|
||||
switch (alignment) {
|
||||
case TextAlignment::TopCenter:
|
||||
rect = { { align_at.x() - rect_size.width() / 2, align_at.y() }, rect_size };
|
||||
break;
|
||||
case TextAlignment::TopLeft:
|
||||
rect = { align_at, rect_size };
|
||||
break;
|
||||
case TextAlignment::TopRight:
|
||||
rect = { { align_at.x() - rect_size.width(), align_at.y() }, rect_size };
|
||||
break;
|
||||
case TextAlignment::CenterLeft:
|
||||
rect = { { align_at.x(), align_at.y() - rect_size.height() / 2 }, rect_size };
|
||||
break;
|
||||
|
@ -144,8 +150,8 @@ Rect<T> Rect<T>::aligned_within(Size<T> const& rect_size, Point<T> const& align_
|
|||
case TextAlignment::CenterRight:
|
||||
rect = { { align_at.x() - rect_size.width() / 2, align_at.y() }, rect_size };
|
||||
break;
|
||||
case TextAlignment::TopRight:
|
||||
rect = { { align_at.x() - rect_size.width(), align_at.y() }, rect_size };
|
||||
case TextAlignment::BottomCenter:
|
||||
rect = { { align_at.x() - rect_size.width() / 2, align_at.y() - rect_size.width() }, rect_size };
|
||||
break;
|
||||
case TextAlignment::BottomLeft:
|
||||
rect = { { align_at.x(), align_at.y() - rect_size.width() }, rect_size };
|
||||
|
@ -270,6 +276,9 @@ void Rect<T>::align_within(Rect<T> const& other, TextAlignment alignment)
|
|||
case TextAlignment::Center:
|
||||
center_within(other);
|
||||
return;
|
||||
case TextAlignment::TopCenter:
|
||||
set_x(other.x() + other.width() / 2);
|
||||
return;
|
||||
case TextAlignment::TopLeft:
|
||||
set_location(other.location());
|
||||
return;
|
||||
|
@ -285,6 +294,10 @@ void Rect<T>::align_within(Rect<T> const& other, TextAlignment alignment)
|
|||
set_x(other.x() + other.width() - width());
|
||||
center_vertically_within(other);
|
||||
return;
|
||||
case TextAlignment::BottomCenter:
|
||||
set_x(other.x() + other.width() / 2);
|
||||
set_y(other.y() + other.height() - height());
|
||||
return;
|
||||
case TextAlignment::BottomLeft:
|
||||
set_x(other.x());
|
||||
set_y(other.y() + other.height() - height());
|
||||
|
|
|
@ -15,8 +15,10 @@ namespace Gfx {
|
|||
M(Center) \
|
||||
M(CenterLeft) \
|
||||
M(CenterRight) \
|
||||
M(TopCenter) \
|
||||
M(TopLeft) \
|
||||
M(TopRight) \
|
||||
M(BottomCenter) \
|
||||
M(BottomLeft) \
|
||||
M(BottomRight)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue