From 360952c25d68d2149c4271477ff85d7ee18f9e91 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Tue, 26 Jul 2022 02:44:09 +0300 Subject: [PATCH] add label text align option --- src/Label.cpp | 2 +- src/Label.hpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Label.cpp b/src/Label.cpp index 1c57b25..11c40af 100644 --- a/src/Label.cpp +++ b/src/Label.cpp @@ -28,7 +28,7 @@ void Label::on_paint() { auto geometry = rect().max_geometry(); painter.source_rgb(style()->foreground()); - painter.text(geometry, m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_END, style()->font_description()); + painter.text(geometry, m_text, m_align, PANGO_ELLIPSIZE_END, style()->font_description()); painter.fill(); } diff --git a/src/Label.hpp b/src/Label.hpp index 430742f..c580852 100644 --- a/src/Label.hpp +++ b/src/Label.hpp @@ -1,6 +1,7 @@ #pragma once #include "Widget.hpp" +#include "Painter.hpp" namespace Raven { @@ -10,15 +11,24 @@ public: : Widget(WidgetType::Label) , m_text(text) {} + Label(std::string text, PaintTextAlign align) + : Widget(WidgetType::Label) + , m_text(text) + , m_align(align) {} + ~Label() {} void set_text(std::string text); std::string &text() { return m_text; } + + PaintTextAlign &align() { return m_align; } + void set_align(PaintTextAlign align) { m_align = align; } protected: void on_paint(); void on_init(); private: std::string m_text; + PaintTextAlign m_align { PaintTextAlign::Left }; }; }