libui: Make Label initialization step-by-step instead of setting everything in the constructor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-10-11 22:56:14 +02:00
parent 7812a4a44a
commit 37e046d766
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 29 additions and 12 deletions

View File

@ -24,8 +24,9 @@ Result<int> luna_main(int argc, char** argv)
ui::VerticalLayout main_layout;
window->set_main_widget(main_layout);
ui::Label title("About Luna", ui::WHITE, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center,
ui::Font::default_bold_font());
ui::Label title("About Luna");
title.set_font(ui::Font::default_bold_font());
main_layout.add_widget(title);
ui::VerticalLayout version_info;

View File

@ -30,8 +30,10 @@ Result<int> luna_main(int argc, char** argv)
window->set_title("Clock");
window->set_background(ui::GRAY);
g_label = TRY(make<ui::Label>("00:00:00", ui::BLACK, ui::VerticalAlignment::Center, ui::HorizontalAlignment::Center,
ui::Font::default_bold_font()));
g_label = TRY(make<ui::Label>("00:00:00"));
g_label->set_font(ui::Font::default_bold_font());
g_label->set_color(ui::BLACK);
window->set_main_widget(*g_label);
update_time();

View File

@ -22,8 +22,23 @@ namespace ui
class Label final : public Widget
{
public:
Label(StringView text, ui::Color color = ui::WHITE, VerticalAlignment valign = VerticalAlignment::Center,
HorizontalAlignment halign = HorizontalAlignment::Center, SharedPtr<Font> font = Font::default_font());
Label(StringView text);
void set_alignment(VerticalAlignment valign, HorizontalAlignment halign)
{
m_valign = valign;
m_halign = halign;
}
void set_color(ui::Color color)
{
m_color = color;
}
void set_font(SharedPtr<ui::Font> font)
{
m_font = font;
}
void set_text(StringView text)
{
@ -34,9 +49,9 @@ namespace ui
private:
StringView m_text;
VerticalAlignment m_valign;
HorizontalAlignment m_halign;
ui::Color m_color;
VerticalAlignment m_valign = VerticalAlignment::Center;
HorizontalAlignment m_halign = HorizontalAlignment::Center;
ui::Color m_color = ui::WHITE;
SharedPtr<Font> m_font;
};
}

View File

@ -12,10 +12,9 @@
namespace ui
{
Label::Label(StringView text, ui::Color color, VerticalAlignment valign, HorizontalAlignment halign,
SharedPtr<Font> font)
: m_text(text), m_valign(valign), m_halign(halign), m_color(color), m_font(font)
Label::Label(StringView text) : m_text(text)
{
m_font = ui::Font::default_font();
}
Result<void> Label::draw(Canvas& canvas)