1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:37:45 +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:
Vrins 2022-02-27 01:33:48 +01:00 committed by Andreas Kling
parent 73ade62d4f
commit 3b22fd9a9f
5 changed files with 33 additions and 2 deletions

View file

@ -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;