add label text align option

This commit is contained in:
hippoz 2022-07-26 02:44:09 +03:00
parent 4929424d2a
commit 360952c25d
Signed by: hippoz
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();
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();
}

View file

@ -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 };
};
}