Public Access
Add dynamic pages with clock, date, Home Assistant values and fonts
The hardcoded clock is now the built-in dynamic page "Clock". A dynamic page has a background bitmap per time of day and up to 8 elements (clock, date, Home Assistant value, text), each with position, alignment, font and overlay. Pages are drawn on the ESP32, also for the web previews. - Pages tab in the web UI: page editor with drag and drop, font upload (TTF/OTF converted in the browser to the FDF1 dot font format) - Built-in fonts Small, Normal, Large and Full height (generated by tools/make_builtin_fonts.py), built-in bitmaps Pikachu and Pikachu yawning - Home Assistant values over the REST API (URL and token in the HA tab) - Settings version 4: evening settings removed (now time slots of the Clock page), old records are converted - HA Mode dropdown lists the dynamic pages and bitmaps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1d3b084de1
commit
0411804a2f
49 files changed
+3058
-331
No files matched your search
@@ -0,0 +1,58 @@
|
||||
#include "logic/page_render.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "logic/bitmap_format.h"
|
||||
#include "logic/builtin_fonts.h"
|
||||
|
||||
static Font usableFont(PageResources &resources, const char *name)
|
||||
{
|
||||
Font font = resources.font(name);
|
||||
if (validFont(font.data, font.size) && font.scale >= 1)
|
||||
return font;
|
||||
return builtinFont(*findBuiltinFont(FONT_NORMAL_NAME));
|
||||
}
|
||||
|
||||
static void clearBox(uint8_t *bitmap, int x, int y, int width, int height)
|
||||
{
|
||||
for (int yy = y; yy < y + height; yy++)
|
||||
for (int xx = x; xx < x + width; xx++)
|
||||
setBitmapPixel(bitmap, xx, yy, false);
|
||||
}
|
||||
|
||||
void renderPage(const DynamicPage &page, const LocalTime &time, PageResources &resources, uint8_t *bitmap,
|
||||
ElementBox *boxes)
|
||||
{
|
||||
memset(bitmap, 0, BITMAP_BYTES);
|
||||
const PageSlot *slot = activeSlot(page, time.hour * 60 + time.minute);
|
||||
if (slot && slot->bitmap[0] && !resources.background(slot->bitmap, bitmap))
|
||||
memset(bitmap, 0, BITMAP_BYTES);
|
||||
|
||||
for (int i = 0; i < page.element_count && i < PAGE_ELEMENTS; i++)
|
||||
{
|
||||
const PageElement &e = page.elements[i];
|
||||
const char *ha_value = e.type == ElementType::HaValue ? resources.haValue(e) : nullptr;
|
||||
char text[64];
|
||||
elementText(e, time, ha_value, text, sizeof(text));
|
||||
|
||||
Font font = usableFont(resources, e.font);
|
||||
int width = textWidth(font, text), height = fontHeight(font);
|
||||
int x = e.x;
|
||||
if (e.align == Align::Center)
|
||||
x -= width / 2;
|
||||
else if (e.align == Align::Right)
|
||||
x -= width;
|
||||
|
||||
if (e.overlay == Overlay::Box)
|
||||
clearBox(bitmap, x - 1, e.y - 1, width + 2, height + 2);
|
||||
drawText(bitmap, font, x, e.y, text, e.overlay == Overlay::Invert ? DrawMode::Invert : DrawMode::Set);
|
||||
|
||||
if (boxes)
|
||||
{
|
||||
boxes[i].x = x;
|
||||
boxes[i].y = e.y;
|
||||
boxes[i].width = width;
|
||||
boxes[i].height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user