mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-11-02 10:51:57 +00:00
feat: a node map and a calendar on ui-new, a banner switch on the L2
- Nearby › Map (ui-new): the positioned nodes and you on one view, scaled to fit, with north, a scale bar and the selected node's name and distance; Left / Right picks a node, Up / Down zooms on it, Enter opens it. - Clock tools › Calendar (ui-new): the month with today and the alarm's days; a tight grid on small screens, Left / Right pages the months. - L2 Settings: a Message banner switch (on / off) in place of ui-new's three-way alert setting. - Simulator: sim_nodes() puts eight positioned contacts around Kraków. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
// The current month as a grid of days, weeks from Monday, today in a filled
|
||||
// soft box, marked days (the alarm's) underlined. For the room a tall e-ink
|
||||
// screen has under its clock (the Clock page, the lock screen).
|
||||
// screen has under its clock (the Clock page, the lock screen), and Clock
|
||||
// tools > Calendar. `tight`: rows a line apart, for a 64-pixel screen.
|
||||
|
||||
#include <time.h>
|
||||
#include <helpers/ui/DisplayDriver.h>
|
||||
@@ -15,25 +16,30 @@ using calmath::firstCol;
|
||||
using calmath::weeks;
|
||||
|
||||
// Its height: the day names, a rule, then a row a week.
|
||||
inline int height(DisplayDriver& d, const struct tm& t) {
|
||||
inline int height(DisplayDriver& d, const struct tm& t, bool tight = false) {
|
||||
if (tight) return (1 + weeks(t)) * d.getLineHeight() + 1;
|
||||
return (1 + weeks(t)) * (d.getLineHeight() + 2) + 3;
|
||||
}
|
||||
|
||||
// `marked`: bit (day - 1) set for each day to underline.
|
||||
inline void draw(DisplayDriver& d, int x, int y, int w, const struct tm& t, uint32_t marked = 0) {
|
||||
// `marked`: bit (day - 1) set for each day to underline. `today`: box
|
||||
// t.tm_mday (off for another month than the current).
|
||||
inline void draw(DisplayDriver& d, int x, int y, int w, const struct tm& t, uint32_t marked = 0,
|
||||
bool tight = false, bool today = true) {
|
||||
static const char* const NAMES[] = { "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su" };
|
||||
const int lh = d.getLineHeight(), step = lh + 2, cw = w / 7;
|
||||
static const char* const INITIALS[] = { "M", "T", "W", "T", "F", "S", "S" };
|
||||
const int lh = d.getLineHeight(), step = tight ? lh : lh + 2, cw = w / 7;
|
||||
const int x0 = x + (w - 7 * cw) / 2;
|
||||
d.setColor(DisplayDriver::LIGHT);
|
||||
for (int c = 0; c < 7; c++) d.drawTextCentered(x0 + c * cw + cw / 2, y, NAMES[c]);
|
||||
info::rule(d, x0, y + lh + 1, 7 * cw);
|
||||
const int top = y + step + 3, col0 = firstCol(t), n = daysIn(t.tm_year, t.tm_mon);
|
||||
for (int c = 0; c < 7; c++) d.drawTextCentered(x0 + c * cw + cw / 2, y, (tight ? INITIALS : NAMES)[c]);
|
||||
info::rule(d, x0, y + (tight ? lh - 1 : lh + 1), 7 * cw);
|
||||
const int top = y + (tight ? lh + 1 : step + 3), col0 = firstCol(t), n = daysIn(t.tm_year, t.tm_mon);
|
||||
char buf[3];
|
||||
for (int day = 1; day <= n; day++) {
|
||||
const int k = col0 + day - 1, cx = x0 + (k % 7) * cw, cy = top + (k / 7) * step;
|
||||
snprintf(buf, sizeof(buf), "%d", day);
|
||||
if (day == t.tm_mday) {
|
||||
d.fillSoftRect(cx + 1, cy - 1, cw - 2, lh + 2);
|
||||
if (today && day == t.tm_mday) {
|
||||
if (tight) d.fillSoftRect(cx, cy - 1, cw, lh);
|
||||
else d.fillSoftRect(cx + 1, cy - 1, cw - 2, lh + 2);
|
||||
d.setColor(DisplayDriver::DARK);
|
||||
d.drawTextCentered(cx + cw / 2, cy, buf);
|
||||
d.setColor(DisplayDriver::LIGHT);
|
||||
@@ -42,8 +48,8 @@ inline void draw(DisplayDriver& d, int x, int y, int w, const struct tm& t, uint
|
||||
}
|
||||
if (marked & (1UL << (day - 1))) { // under the number, in the gap below it
|
||||
const int uw = d.getTextWidth(buf);
|
||||
d.setColor(day == t.tm_mday ? DisplayDriver::DARK : DisplayDriver::LIGHT);
|
||||
d.fillRect(cx + (cw - uw) / 2, cy + lh, uw, 1);
|
||||
d.setColor(today && day == t.tm_mday ? DisplayDriver::DARK : DisplayDriver::LIGHT);
|
||||
d.fillRect(cx + (cw - uw) / 2, cy + (tight ? lh - 2 : lh), uw, 1);
|
||||
d.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user