All checks were successful
Build and test / build (push) Successful in 1m56s
Why are command-line utilities stored in "apps"? And why are apps like "editor" or "terminal" top-level directories? Command-line utilities now go in "utils". GUI stuff now goes in "gui". This includes: libui -> gui/libui, wind -> gui/wind, GUI apps -> gui/apps, editor&terminal -> gui/apps... System services go in "system".
37 lines
900 B
C++
37 lines
900 B
C++
/**
|
|
* @file Label.cpp
|
|
* @author apio (cloudapio.eu)
|
|
* @brief A simple one-line text widget.
|
|
*
|
|
* @copyright Copyright (c) 2023, the Luna authors.
|
|
*
|
|
*/
|
|
|
|
#include <luna/Utf8.h>
|
|
#include <ui/Label.h>
|
|
|
|
namespace ui
|
|
{
|
|
Label::Label(StringView text) : m_text(text)
|
|
{
|
|
m_font = ui::Font::default_font();
|
|
}
|
|
|
|
Result<void> Label::draw(Canvas& canvas)
|
|
{
|
|
ui::Rect contained;
|
|
contained.pos = { 0, 0 };
|
|
contained.width = static_cast<int>(m_text.length() * m_font->width());
|
|
contained.height = m_font->height();
|
|
auto subcanvas =
|
|
canvas.subcanvas(ui::align({ 0, 0, m_rect.width, m_rect.height }, contained, m_valign, m_halign));
|
|
|
|
Utf8StringDecoder decoder(m_text.chars());
|
|
wchar_t buf[4096];
|
|
TRY(decoder.decode(buf, sizeof(buf)));
|
|
|
|
m_font->render(buf, m_color, subcanvas);
|
|
return {};
|
|
}
|
|
}
|