add: Font registry
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user