Aligment of label texts to support buttons

In order to support touch sensitive buttons on to teeui based confirmationui layouts, we need to be able to center align label texts.

Bug: 149791276
Test: N/A
Change-Id: Icbeed22e28ebbc689969505fec7c1edcee408e1d
diff --git a/libteeui/example/layout.h b/libteeui/example/layout.h
index 8f78020..5e47970 100644
--- a/libteeui/example/layout.h
+++ b/libteeui/example/layout.h
@@ -142,7 +142,7 @@
 Position(BorderWidth, BottomOfScreen() - BorderWidth - dim_h);
 DefaultText("This confirmation provides an extra layer of security for the action you're "
             "about to take.");
-VerticallyCentered;
+VerticalTextAlignment(Alignment::BOTTOM);
 TextColor(ColorText());
 Font(DefaultFont);
 TextID(217688588483778177);
diff --git a/libteeui/include/teeui/label.h b/libteeui/include/teeui/label.h
index acead70..0a30877 100644
--- a/libteeui/include/teeui/label.h
+++ b/libteeui/include/teeui/label.h
@@ -25,6 +25,8 @@
 
 namespace teeui {
 
+enum class Alignment : int8_t { LEFT, CENTER, RIGHT, TOP, BOTTOM };
+
 class FontBuffer {
     const uint8_t* data_;
     size_t size_;
@@ -64,12 +66,12 @@
     };
 
     LabelImpl()
-        : fontSize_(10_px), lineHeight_(12_px), text_{}, rightJustified_(false),
-          verticallyCentered_(false), textColor_(0), font_{}, textId_(0) {}
-    LabelImpl(pxs fontSize, pxs lineHeight, text_t text, bool rightJustified,
-              bool verticallyCentered, Color textColor, FontBuffer font, uint64_t textId)
+        : fontSize_(10_px), lineHeight_(12_px), text_{}, horizontalTextAlignment_(Alignment::LEFT),
+          verticalTextAlignment_(Alignment::TOP), textColor_(0), font_{}, textId_(0) {}
+    LabelImpl(pxs fontSize, pxs lineHeight, text_t text, Alignment horizontal,
+              Alignment verticalJustified, Color textColor, FontBuffer font, uint64_t textId)
         : fontSize_(fontSize), lineHeight_(lineHeight), text_(text),
-          rightJustified_(rightJustified), verticallyCentered_(verticallyCentered),
+          horizontalTextAlignment_(horizontal), verticalTextAlignment_(verticalJustified),
           textColor_(textColor), font_(font), textId_(textId) {}
 
     pxs fontSize() const { return fontSize_; }
@@ -86,8 +88,8 @@
     pxs fontSize_;
     pxs lineHeight_;
     text_t text_;
-    bool rightJustified_;
-    bool verticallyCentered_;
+    Alignment horizontalTextAlignment_;
+    Alignment verticalTextAlignment_;
     Color textColor_;
     FontBuffer font_;
     uint64_t textId_;
@@ -100,8 +102,8 @@
  */
 template <typename Derived> class Label : public LayoutElement<Derived>, public LabelImpl {
   public:
-    static const constexpr bool label_right_justified = false;
-    static const constexpr bool label_vertically_centered = false;
+    static const constexpr Alignment label_horizontal_text_alignment = Alignment::LEFT;
+    static const constexpr Alignment label_vertical_text_alignment = Alignment::TOP;
     static const constexpr Color label_text_color = 0xff000000;
     static const constexpr int label_font = 0;
     static const constexpr uint64_t text_id = 0;
@@ -113,7 +115,7 @@
           LabelImpl(
               context = Derived::label_font_size, context = Derived::label_line_height,
               {&Derived::label_text[0], &Derived::label_text[sizeof(Derived::label_text) - 1]},
-              Derived::label_right_justified, Derived::label_vertically_centered,
+              Derived::label_horizontal_text_alignment, Derived::label_vertical_text_alignment,
               context = Derived::label_text_color, getFont(Derived::label_font), Derived::text_id) {
     }
 
@@ -136,9 +138,15 @@
 
 #define HeightFromLines (label_line_height * pxs(label_number_of_lines))
 
-#define RightJustified static const constexpr bool label_right_justified = true
+#define HorizontalTextAlignment(horizontalAligment)                                                \
+    static const constexpr Alignment label_horizontal_text_alignment = horizontalAligment;
 
-#define VerticallyCentered static const constexpr bool label_vertically_centered = true
+#define RightJustified HorizontalTextAlignment(Alignment::RIGHT)
+
+#define VerticalTextAlignment(verticalAligment)                                                    \
+    static const constexpr Alignment label_vertical_text_alignment = verticalAligment;
+
+#define VerticallyCentered VerticalTextAlignment(Alignment::CENTER)
 
 #define TextColor(color) static const constexpr auto label_text_color = color
 
diff --git a/libteeui/src/label.cpp b/libteeui/src/label.cpp
index 3255714..8267bf2 100644
--- a/libteeui/src/label.cpp
+++ b/libteeui/src/label.cpp
@@ -75,10 +75,21 @@
             findLongestWordSequence(&face, text_t(*textBegin, *text_.end()), bounds);
         if (error) return error;
 
-        if (rightJustified_)
-            pen = {-bBox.w(), pen.y()};
-        else
-            pen = {-bBox.x(), pen.y()};
+        pen = {-bBox.x(), pen.y()};
+
+        // check horizontal justification to set pen value
+        switch (horizontalTextAlignment_) {
+        case Alignment::LEFT:
+        case Alignment::TOP:
+        case Alignment::BOTTOM:
+            break;
+        case Alignment::CENTER:
+            pen += {(bounds.w() - bBox.w()) / 2.0_px, 0};
+            break;
+        case Alignment::RIGHT:
+            pen += {bounds.w() - bBox.w(), 0};
+            break;
+        }
 
         curLine->lineStart = pen;
         bBox.translateSelf(pen);
@@ -100,8 +111,10 @@
     offset -= {0, boundingBox->y()};
     TEEUI_LOG << "Offset: " << offset << ENDL;
 
-    if (rightJustified_) offset += {bounds.w(), 0};
-    if (verticallyCentered_) offset += {0, (bounds.h() - boundingBox->h()) / 2.0_px};
+    if (verticalTextAlignment_ == Alignment::CENTER)
+        offset += {0, (bounds.h() - boundingBox->h()) / 2.0_px};
+    else if (verticalTextAlignment_ == Alignment::BOTTOM)
+        offset += {0, (bounds.h() - boundingBox->h())};
 
     auto lineEnd = curLine;
     curLine = lineInfo->begin();