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-05-08 19:31:31 +03:00
|
|
|
#include <iostream>
|
2022-03-26 02:57:41 +02:00
|
|
|
|
|
|
|
namespace Raven {
|
|
|
|
|
|
|
|
void Label::on_init() {
|
|
|
|
// the label will inherit the background color properties from the parent
|
2022-04-30 09:40:09 +03:00
|
|
|
if (parent()) {
|
|
|
|
set_do_background_fill(parent()->do_background_fill());
|
|
|
|
set_background_fill_color(parent()->background_fill_color());
|
2022-03-26 02:57:41 +02:00
|
|
|
}
|
|
|
|
set_did_init(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Label::on_paint() {
|
2022-05-08 19:31:31 +03:00
|
|
|
do_generic_paint();
|
|
|
|
|
2022-04-30 09:40:09 +03:00
|
|
|
auto painter = window()->painter();
|
|
|
|
auto text_color = styles()->label_text_color();
|
2022-05-08 19:31:31 +03:00
|
|
|
auto text_geometry = current_geometry().max_geometry();
|
2022-05-10 21:14:55 +03:00
|
|
|
bool set_size = current_geometry().max_width() != -1 && current_geometry().max_height() != -1;
|
2022-03-26 02:57:41 +02:00
|
|
|
|
|
|
|
painter.source_rgb(text_color);
|
2022-04-30 09:40:09 +03:00
|
|
|
painter.set_pango_font_description(styles()->controls_font_description());
|
2022-05-10 21:14:55 +03:00
|
|
|
auto point = painter.text(text_geometry, m_text, PaintTextAlign::Left, PANGO_ELLIPSIZE_NONE, set_size);
|
2022-05-08 19:31:31 +03:00
|
|
|
resize(point);
|
2022-03-26 02:57:41 +02:00
|
|
|
painter.fill();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|