From 9dd3203cc694295ca1b587d0405290a8fa46c145 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 21 May 2021 01:03:02 +0100 Subject: [PATCH] LibGfx: Add missing TextAlignment::BottomLeft --- Userland/Applications/Spreadsheet/CellTypeDialog.cpp | 4 +++- Userland/Demos/LibGfxDemo/main.cpp | 2 ++ Userland/Libraries/LibCore/Object.h | 5 +++-- Userland/Libraries/LibGfx/Painter.cpp | 4 ++++ Userland/Libraries/LibGfx/Rect.cpp | 4 ++++ Userland/Libraries/LibGfx/TextAlignment.h | 5 +++-- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Userland/Applications/Spreadsheet/CellTypeDialog.cpp b/Userland/Applications/Spreadsheet/CellTypeDialog.cpp index d04820a8d0..4153a05b40 100644 --- a/Userland/Applications/Spreadsheet/CellTypeDialog.cpp +++ b/Userland/Applications/Spreadsheet/CellTypeDialog.cpp @@ -78,6 +78,7 @@ constexpr static CellTypeDialog::VerticalAlignment vertical_alignment_from(Gfx:: case Gfx::TextAlignment::TopLeft: return CellTypeDialog::VerticalAlignment::Top; + case Gfx::TextAlignment::BottomLeft: case Gfx::TextAlignment::BottomRight: return CellTypeDialog::VerticalAlignment::Bottom; } @@ -91,13 +92,14 @@ constexpr static CellTypeDialog::HorizontalAlignment horizontal_alignment_from(G case Gfx::TextAlignment::Center: return CellTypeDialog::HorizontalAlignment::Center; - case Gfx::TextAlignment::CenterRight: case Gfx::TextAlignment::TopRight: + case Gfx::TextAlignment::CenterRight: case Gfx::TextAlignment::BottomRight: return CellTypeDialog::HorizontalAlignment::Right; case Gfx::TextAlignment::TopLeft: case Gfx::TextAlignment::CenterLeft: + case Gfx::TextAlignment::BottomLeft: return CellTypeDialog::HorizontalAlignment::Left; } diff --git a/Userland/Demos/LibGfxDemo/main.cpp b/Userland/Demos/LibGfxDemo/main.cpp index a293bd7dff..992906b9e4 100644 --- a/Userland/Demos/LibGfxDemo/main.cpp +++ b/Userland/Demos/LibGfxDemo/main.cpp @@ -141,6 +141,8 @@ void Canvas::draw() painter.draw_text({ 520, 260, 240, 80 }, "CenterRight", Gfx::TextAlignment::CenterRight, Color::White); painter.draw_text({ 520, 260, 240, 80 }, "TopLeft", Gfx::TextAlignment::TopLeft, Color::White); painter.draw_text({ 520, 260, 240, 80 }, "TopRight", Gfx::TextAlignment::TopRight, Color::White); + painter.draw_text({ 520, 260, 240, 80 }, "BottomLeft", Gfx::TextAlignment::BottomLeft, Color::White); + painter.draw_text({ 520, 260, 240, 80 }, "BottomRight", Gfx::TextAlignment::BottomRight, Color::White); painter.draw_rect({ 520, 360, 240, 30 }, Color::DarkGray); painter.draw_text({ 520, 360, 240, 30 }, "Emojis! 🙂😂🐞🦄", Gfx::TextAlignment::Center, Color::White); diff --git a/Userland/Libraries/LibCore/Object.h b/Userland/Libraries/LibCore/Object.h index 271df32d94..d9d0a2df2a 100644 --- a/Userland/Libraries/LibCore/Object.h +++ b/Userland/Libraries/LibCore/Object.h @@ -353,11 +353,12 @@ T* Object::find_descendant_of_type_named(String const& name) requires IsBaseOf::align_within(const Rect& other, TextAlignment alignment) set_x(other.x() + other.width() - width()); center_vertically_within(other); return; + case TextAlignment::BottomLeft: + set_x(other.x()); + set_y(other.y() + other.height() - height()); + return; case TextAlignment::BottomRight: set_x(other.x() + other.width() - width()); set_y(other.y() + other.height() - height()); diff --git a/Userland/Libraries/LibGfx/TextAlignment.h b/Userland/Libraries/LibGfx/TextAlignment.h index 914adefc1e..1b199eaecc 100644 --- a/Userland/Libraries/LibGfx/TextAlignment.h +++ b/Userland/Libraries/LibGfx/TextAlignment.h @@ -12,11 +12,12 @@ namespace Gfx { #define GFX_ENUMERATE_TEXT_ALIGNMENTS(M) \ - M(TopLeft) \ - M(CenterLeft) \ M(Center) \ + M(CenterLeft) \ M(CenterRight) \ + M(TopLeft) \ M(TopRight) \ + M(BottomLeft) \ M(BottomRight) enum class TextAlignment {