Skip to content

Commit 1cbe657

Browse files
committed
fix month display overflow
1 parent d094734 commit 1cbe657

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

GUI/Calendar.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void DrawMonthDay(Adafruit_GFX *gfx, int16_t x, int16_t y, tm_t *tm, stru
3838
{
3939
if (day == tm->tm_mday)
4040
{
41-
GFX_fillCircle(gfx, x + 10, y + 9, 22, GFX_RED);
41+
GFX_fillCircle(gfx, x + 10, y + 9, 20, GFX_RED);
4242
GFX_setTextColor(gfx, GFX_WHITE, GFX_RED);
4343
}
4444
else
@@ -51,7 +51,7 @@ static void DrawMonthDay(Adafruit_GFX *gfx, int16_t x, int16_t y, tm_t *tm, stru
5151
GFX_printf(gfx, "%d", day);
5252

5353
GFX_setFont(gfx, u8g2_font_wqy9_t_lunar);
54-
GFX_setCursor(gfx, x, y + 24);
54+
GFX_setCursor(gfx, x, y + 20);
5555
uint8_t JQdate;
5656
if (GetJieQi(tm->tm_year + YEAR0, tm->tm_mon + 1, day, &JQdate) && JQdate == day)
5757
{
@@ -81,6 +81,7 @@ void DrawCalendar(uint32_t timestamp)
8181

8282
uint8_t firstDayWeek = get_first_day_week(tm.tm_year + YEAR0, tm.tm_mon + 1);
8383
uint8_t monthMaxDays = thisMonthMaxDays(tm.tm_year + YEAR0, tm.tm_mon + 1);
84+
uint8_t monthDayRows = 1 + (monthMaxDays - (7 - firstDayWeek) + 6) / 7;
8485

8586
Adafruit_GFX gfx;
8687

@@ -97,8 +98,11 @@ void DrawCalendar(uint32_t timestamp)
9798
DrawDateHeader(&gfx, 10, 22, &tm, &Lunar);
9899
DrawWeekHeader(&gfx, 10, 26);
99100

100-
for (uint8_t i = 0; i < monthMaxDays; i++)
101-
DrawMonthDay(&gfx, 22 + (firstDayWeek + i) % 7 * 55, 60 + (firstDayWeek + i) / 7 * 50, &tm, &Lunar, i + 1);
101+
for (uint8_t i = 0; i < monthMaxDays; i++) {
102+
int16_t x = 22 + (firstDayWeek + i) % 7 * 55;
103+
int16_t y = (monthDayRows > 5 ? 60 : 65) + (firstDayWeek + i) / 7 * (monthDayRows > 5 ? 42 : 50);
104+
DrawMonthDay(&gfx, x, y, &tm, &Lunar, i + 1);
105+
}
102106
} while(GFX_nextPage(&gfx, driver->write_image));
103107

104108
GFX_end(&gfx);

0 commit comments

Comments
 (0)