summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-01-06 09:30:07 +0100
committerAndreas Kling <kling@serenityos.org>2023-01-06 12:02:20 +0100
commitd2195f8088be78b9243f920f55c52ad25a5510ff (patch)
treef65aa19f1681e017c3c6ea8c7ebfd20d899111fa /Userland/Libraries
parent6b421fb5214d4ea3646ddd230a895c8a57453dc2 (diff)
downloadserenity-d2195f8088be78b9243f920f55c52ad25a5510ff.zip
LibGfx: Use Gfx::Rect::align_within() to simplify text drawing logic
Instead of doing this manually, just use the helper we already have.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGfx/Painter.cpp35
1 files changed, 1 insertions, 34 deletions
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp
index efa88f7772..81c5395cb2 100644
--- a/Userland/Libraries/LibGfx/Painter.cpp
+++ b/Userland/Libraries/LibGfx/Painter.cpp
@@ -1731,40 +1731,7 @@ void Painter::do_draw_text(FloatRect const& rect, Utf8View const& text, Font con
auto lines = layout.lines(elision, wrapping, LINE_SPACING);
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;
- case TextAlignment::TopRight:
- bounding_rect.set_location({ (rect.right() + 1) - bounding_rect.width(), rect.y() });
- break;
- case TextAlignment::CenterLeft:
- bounding_rect.set_location({ rect.x(), rect.center().y() - int(bounding_rect.height() / 2) });
- break;
- case TextAlignment::CenterRight:
- bounding_rect.set_location({ (rect.right() + 1) - bounding_rect.width(), rect.center().y() - int(bounding_rect.height() / 2) });
- break;
- 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;
- case TextAlignment::BottomRight:
- bounding_rect.set_location({ (rect.right() + 1) - bounding_rect.width(), (rect.bottom() + 1) - bounding_rect.height() });
- break;
- default:
- VERIFY_NOT_REACHED();
- }
-
+ bounding_rect.align_within(rect, alignment);
bounding_rect.intersect(rect);
for (size_t i = 0; i < lines.size(); ++i) {