add label text align option

This commit is contained in:
hippoz 2022-07-26 02:44:09 +03:00
parent 4929424d2a
commit 360952c25d
No known key found for this signature in database
GPG key ID: 7C52899193467641
2 changed files with 11 additions and 1 deletions

View file

@ -28,7 +28,7 @@ void Label::on_paint() {
auto geometry = rect().max_geometry(); auto geometry = rect().max_geometry();
painter.source_rgb(style()->foreground()); 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(); painter.fill();
} }

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Widget.hpp" #include "Widget.hpp"
#include "Painter.hpp"
namespace Raven { namespace Raven {
@ -10,15 +11,24 @@ public:
: Widget(WidgetType::Label) : Widget(WidgetType::Label)
, m_text(text) {} , m_text(text) {}
Label(std::string text, PaintTextAlign align)
: Widget(WidgetType::Label)
, m_text(text)
, m_align(align) {}
~Label() {} ~Label() {}
void set_text(std::string text); void set_text(std::string text);
std::string &text() { return m_text; } std::string &text() { return m_text; }
PaintTextAlign &align() { return m_align; }
void set_align(PaintTextAlign align) { m_align = align; }
protected: protected:
void on_paint(); void on_paint();
void on_init(); void on_init();
private: private:
std::string m_text; std::string m_text;
PaintTextAlign m_align { PaintTextAlign::Left };
}; };
} }