2023-09-11 17:15:18 +00:00
|
|
|
/**
|
|
|
|
* @file Label.h
|
|
|
|
* @author apio (cloudapio.eu)
|
|
|
|
* @brief A simple one-line text widget.
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2023, the Luna authors.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2024-05-19 12:21:30 +00:00
|
|
|
#include <os/File.h>
|
2023-09-11 17:15:18 +00:00
|
|
|
#include <ui/Alignment.h>
|
|
|
|
#include <ui/Font.h>
|
|
|
|
#include <ui/Widget.h>
|
|
|
|
|
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief Displays one line of text.
|
|
|
|
*
|
|
|
|
* This component does not handle newlines.
|
|
|
|
*/
|
|
|
|
class Label final : public Widget
|
|
|
|
{
|
|
|
|
public:
|
2024-05-19 12:21:30 +00:00
|
|
|
Label(Window* window, Widget* parent);
|
2023-10-11 20:56:14 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-09-11 17:15:18 +00:00
|
|
|
|
|
|
|
void set_text(StringView text)
|
|
|
|
{
|
|
|
|
m_text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result<void> draw(Canvas& canvas) override;
|
|
|
|
|
2024-05-19 12:21:30 +00:00
|
|
|
void recalculate_pseudo_rects() override;
|
|
|
|
|
|
|
|
void show_tree(int indent) override
|
|
|
|
{
|
|
|
|
os::println("%*s- ui::Label '%s' (%d,%d,%d,%d)", indent, "", m_text.chars(), m_rect.pos.x, m_rect.pos.y,
|
|
|
|
m_rect.width, m_rect.height);
|
|
|
|
}
|
|
|
|
|
2023-09-11 17:15:18 +00:00
|
|
|
private:
|
|
|
|
StringView m_text;
|
2023-10-11 20:56:14 +00:00
|
|
|
VerticalAlignment m_valign = VerticalAlignment::Center;
|
|
|
|
HorizontalAlignment m_halign = HorizontalAlignment::Center;
|
|
|
|
ui::Color m_color = ui::WHITE;
|
2023-09-11 17:15:18 +00:00
|
|
|
SharedPtr<Font> m_font;
|
|
|
|
};
|
|
|
|
}
|