add basic calendar

This commit is contained in:
Ammerhai 2025-08-11 21:17:29 +02:00
parent 86f2520c3e
commit 519124b8cf
2 changed files with 82 additions and 6 deletions

View File

@ -149,13 +149,13 @@ int main(int, char**)
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
//work calendar app
per_frame();
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
//work calendar app
per_frame();
// Rendering
ImGui::Render();
const float clear_color_with_alpha[4] = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w };

View File

@ -1,6 +1,82 @@
#include <imgui.h>
void per_frame(){
//TODO
//ImGui::Begin();
bool is_leap_year(int year) {
return ((year % 4) == 0 && (year % 100) != 0) || year % 400 == 0;
}
int weekday_from_day(int year, int month, int day) {
int a = (14 - month) / 12;
int y = year - a;
int m = month + (12 * a) - 2;
return (day + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12)) % 7;
}
int calendar_week_from_day(int year, int month, int day){
int days_sum[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int days = days_sum[month - 1];
if(is_leap_year(year) && month > 2)
days++;
return (10 + days + day - weekday_from_day(year, month, day)) / 7;
}
int days_per_month(int year, int month){
int days_in_month[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
if (month == 2) {
return is_leap_year(year) ? 29 : 28;
}
return days_in_month[month - 1];
}
void per_frame(){
static bool use_work_area = true;
static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings;
// We demonstrate using the full viewport area or the work area (without menu-bars, task-bars etc.)
// Based on your use case you may want one or the other.
const ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(use_work_area ? viewport->WorkPos : viewport->Pos);
ImGui::SetNextWindowSize(use_work_area ? viewport->WorkSize : viewport->Size);
//Begin
ImGui::Begin("Work Calendar", 0, flags);
for (int month = 1; month <= 12; month++) {
ImGui::PushID(month);
//month
if(ImGui::BeginTable("Month", 8, ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_NoHostExtendX)) {
ImGui::TableSetupColumn("KW");
ImGui::TableSetupColumn("Mo");
ImGui::TableSetupColumn("Di");
ImGui::TableSetupColumn("Mi");
ImGui::TableSetupColumn("Do");
ImGui::TableSetupColumn("Fr");
ImGui::TableSetupColumn("Sa");
ImGui::TableSetupColumn("So");
ImGui::TableHeadersRow();
int offset = weekday_from_day(2025, month, 1);
//tage
for (int day = 1; day <= days_per_month(2025, month); day++) {
int weekday = weekday_from_day(2025, month, day);
if(weekday == 0 || day == 1){
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Text("%d", calendar_week_from_day(2025, month, day));
}
ImGui::TableSetColumnIndex(weekday + 1);
ImGui::Text("%d", day);
}
ImGui::EndTable();
if ((month % 4) != 0)
ImGui::SameLine();
}
ImGui::PopID();
}
ImGui::End();
}