From 440a2d6bc0b38dadffb8373851f39fa7032ef891 Mon Sep 17 00:00:00 2001 From: Ammerhai Date: Sun, 17 Aug 2025 20:37:40 +0200 Subject: [PATCH] add offset for days (started one day after) add background coloring of day cells #4 --- src/work-calendar.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/work-calendar.cpp b/src/work-calendar.cpp index b2fb57f..b12c740 100644 --- a/src/work-calendar.cpp +++ b/src/work-calendar.cpp @@ -12,7 +12,7 @@ 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; + return (day + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12) - 1) % 7; } int calendar_week_from_day(int year, int month, int day){ @@ -41,7 +41,6 @@ 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); @@ -115,7 +114,7 @@ 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); - //tage + for (int day = 1; day <= days_per_month(2025, month); day++) { int weekday = weekday_from_day(2025, month, day); @@ -124,6 +123,20 @@ void per_frame(){ } ImGui::TableSetColumnIndex(weekday); + ImU32 cell_bg_color_workweek = ImGui::GetColorU32(ImVec4(255/255.0f, 255/255.0f, 255/255.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)); + 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)); + ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color_sun); + } + ImGui::TextAligned(0.5, -FLT_MIN, "%d", day); }