add year and buttons to switch year

change last week of previous week to 53 instead of 1
#3 #4
This commit is contained in:
Ammerhai 2025-08-23 11:17:12 +02:00
parent 440a2d6bc0
commit 9daff74e9e

View File

@ -3,6 +3,7 @@
#include "inter.h"
int year = 2025;
bool is_leap_year(int year) {
return ((year % 4) == 0 && (year % 100) != 0) || year % 400 == 0;
@ -57,6 +58,25 @@ void per_frame(){
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, {0,0,0,0});
ImGui::PushStyleColor(ImGuiCol_HeaderActive, {0,0,0,0});
if(ImGui::BeginTable("Calendar", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoHostExtendX)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::BeginGroup();
if (ImGui::ArrowButton("##left", ImGuiDir_Left))
year--;
ImGui::SameLine(0, 0);
if (ImGui::ArrowButton("##right", ImGuiDir_Right))
year++;
ImGui::SameLine(0, 0);
ImGui::TextAligned(0.5, -FLT_MIN, "%d", year);
ImGui::EndGroup();
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
for (int month = 1; month <= 12; month++) {
ImGui::PushID(month);
ImGui::PushStyleColor(ImGuiCol_TableBorderStrong, {0,0,0,0});
@ -76,13 +96,20 @@ void per_frame(){
ImGui::TableSetColumnIndex(0);
ImGui::TextAligned(0.5, -FLT_MIN, "KW");
for (int day = 1; day <= days_per_month(2025, month); day++) {
int weekday = weekday_from_day(2025, month, day);
for (int day = 1; day <= days_per_month(year, month); day++) {
int weekday = weekday_from_day(year, month, day);
if(weekday == 0 || day == 1){
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::TextAligned(0.5, -FLT_MIN, "%d", calendar_week_from_day(2025, month, day));
//if first week has 3 or less days, last week from previous year
int calender_week = calendar_week_from_day(year, month, day);
if(calender_week == 0) {
ImGui::TextAligned(0.5, -FLT_MIN, "%d", 53);
} else {
ImGui::TextAligned(0.5, -FLT_MIN, "%d", calender_week);
}
}
}
@ -113,27 +140,27 @@ void per_frame(){
//days of month table
if(ImGui::BeginTable("Weekdays", 7, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_Borders)) {
int offset = weekday_from_day(2025, month, 1);
int offset = weekday_from_day(year, month, 1);
for (int day = 1; day <= days_per_month(2025, month); day++) {
int weekday = weekday_from_day(2025, month, day);
int weekday = weekday_from_day(year, month, day);
if(weekday == 0 || day == 1){
ImGui::TableNextRow();
}
ImGui::TableSetColumnIndex(weekday);
ImU32 cell_bg_color_workweek = ImGui::GetColorU32(ImVec4(255/255.0f, 255/255.0f, 255/255.0f, 1.0f));
ImU32 cell_bg_color_workweek = ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color_workweek);
//weekend coloring
if(weekday == 5){
ImU32 cell_bg_color_sat = ImGui::GetColorU32(ImVec4(178/255.0f, 178/255.0f, 178/255.0f, 100/255.0f));
ImU32 cell_bg_color_sat = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 0.1f));
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color_sat);
}
if(weekday == 6){
ImU32 cell_bg_color_sun = ImGui::GetColorU32(ImVec4(100/255.0f, 100/255.0f, 100/255.0f, 100/255.0f));
ImU32 cell_bg_color_sun = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 0.2f));
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color_sun);
}
@ -155,6 +182,9 @@ void per_frame(){
ImGui::PopID();
}
//calendar table
ImGui::EndTable();
}
ImGui::PopStyleColor(3);