add: Font registry

This commit is contained in:
Simon Hardt
2022-03-06 20:15:57 +01:00
parent 1772a3baff
commit fe9fc4d69c
9 changed files with 169 additions and 7 deletions

View File

@@ -1,15 +1,14 @@
#include "Analog.hpp"
#include "../../font/FontRegistry.hpp"
#include <ctime>
#include <fmt/chrono.h>
#include <fmt/format.h>
constexpr double pi = 3.14159;
#include "../WidgetRegistry.hpp"
/*
static bool registerd =
frame::Service::get<frame::widgets::WidgetRegistry>()
->Register<frame::widgets::AnalogClock>("AnalogClock");*/
REGISTER_WIDGET(frame::widgets::AnalogClock, "AnalogClock");
@@ -97,6 +96,37 @@ namespace frame::widgets
center.y + int32_t(std::sin(hour_rad) * radius * 0.6)});
setClear();
// Text
auto font = font::GetFont("Fira Code");
if(!font)
return;
auto text = fmt::format("{:%d.%m.%Y}", fmt::localtime(t));
auto text_center = center;
text_center.y += radius / 2;
auto const text_height_h = radius / 4;
auto const text_width_h = radius / 2;
Rect text_box{text_center.y - text_height_h,
text_center.x - text_width_h,
text_width_h * 2,
text_height_h * 2};
auto font_size = font->getOptimalSize(text, text_box);
rt.setInvert(true);
rt.DrawText(text_box,
text,
*font,
font_size,
AlignHorizontal::CENTER,
AlignVertical::CENTER);
rt.setInvert(false);
}
} // namespace frame::widgets