2022-03-26 02:57:41 +02:00
|
|
|
#include "Label.hpp"
|
|
|
|
#include "Window.hpp"
|
2022-03-29 09:27:59 +03:00
|
|
|
#include "pango/pango-layout.h"
|
2022-06-11 15:52:23 +03:00
|
|
|
#include "Styles.hpp"
|
2022-05-08 19:31:31 +03:00
|
|
|
#include <iostream>
|
2022-03-26 02:57:41 +02:00
|
|
|
|
|
|
|
namespace Raven {
|
|
|
|
|
2022-05-14 13:05:52 +03:00
|
|
|
void Label::set_text(std::string text) {
|
|
|
|
m_text = text;
|
|
|
|
|
2022-07-10 04:30:42 +03:00
|
|
|
if (!fit_text(text)) {
|
|
|
|
repaint();
|
2022-03-26 02:57:41 +02:00
|
|
|
}
|
2022-05-14 13:05:52 +03:00
|
|
|
}
|
2022-06-11 16:19:02 +03:00
|
|
|
|
2022-05-14 13:05:52 +03:00
|
|
|
void Label::on_init() {
|
2022-07-10 04:30:42 +03:00
|
|
|
set_style_pure(&default_label_style);
|
|
|
|
|
2022-03-26 02:57:41 +02:00
|
|
|
set_did_init(true);
|
2022-07-10 04:30:42 +03:00
|
|
|
if (!fit_text(m_text)) {
|
|
|
|
reflow();
|
|
|
|
}
|
2022-03-26 02:57:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Label::on_paint() {
|
2022-04-30 09:40:09 +03:00
|
|
|
auto painter = window()->painter();
|
2022-03-26 02:57:41 +02:00
|
|
|
|
2022-06-11 15:52:23 +03:00
|
|
|
painter.source_rgb(style()->foreground());
|
2022-06-11 16:19:02 +03:00
|
|
|
painter.text(rect(), m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, style()->font_description());
|
2022-03-26 02:57:41 +02:00
|
|
|
painter.fill();
|
|
|
|
}
|
|
|
|
|
2022-05-14 13:05:52 +03:00
|
|
|
}
|