add: Container Widget

This commit is contained in:
Simon Hardt
2022-03-06 22:03:12 +01:00
parent 33f79d9f92
commit 4c70f3440d
11 changed files with 288 additions and 13 deletions

View File

@@ -0,0 +1,54 @@
#include "Date.hpp"
REGISTER_WIDGET(frame::widgets::Date, "Date");
#include "../../font/FontRegistry.hpp"
#include <ctime>
#include <fmt/chrono.h>
#include <fmt/format.h>
namespace frame::widgets
{
Widget::shared_ptr Date::Create()
{
return std::make_shared<Date>();
}
void Date::Update()
{
auto const now = std::chrono::system_clock::now();
auto const min = std::chrono::floor<std::chrono::minutes>(now);
if(last_time != min)
{
setDirty();
last_time = min;
}
}
void Date::Render(render::RenderTarget& rt)
{
std::time_t t = std::chrono::system_clock::to_time_t(last_time);
auto const& size = getSize();
Rect draw{0, 0, size.x, size.y};
auto text = fmt::format("{:%d.%m.%Y}", fmt::localtime(t));
auto font = font::GetFont("Fira Code");
auto font_size = font->getOptimalSize(text, draw);
rt.DrawText(draw,
text,
*font,
font_size,
AlignHorizontal::CENTER,
AlignVertical::CENTER);
setClear();
}
} // namespace frame::widgets