parent
22abd958fe
commit
11110f23c9
@ -71,12 +71,22 @@ typedef struct Categorized_Day {
|
||||
int category;
|
||||
} Categorized_Day;
|
||||
|
||||
static int year_min_size = 1;
|
||||
static size_t num_categorized_days = 0;
|
||||
static Categorized_Day categorized_days[365*50];
|
||||
|
||||
//Colors
|
||||
ImVec4 table_white_bg = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
ImVec4 table_saturday_bg = ImVec4(0.0f, 0.0f, 0.0f, 0.1f);
|
||||
ImVec4 table_sunday_bg = ImVec4(0.0f, 0.0f, 0.0f, 0.2f);
|
||||
|
||||
ImVec4 table_hover_color = ImVec4(0.0f, 0.3f, 0.6f, 0.2f);
|
||||
|
||||
void per_frame(){
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
|
||||
year_min_size = ImGui::CalcTextSize("8888").x + 5;
|
||||
|
||||
ImGuiID main_viewport_dock = ImGui::GetID("main_viewport_dock");
|
||||
if (!ImGui::DockBuilderGetNode(main_viewport_dock)) {
|
||||
ImGui::DockBuilderAddNode (main_viewport_dock, ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_NoTabBar);
|
||||
@ -109,17 +119,30 @@ void per_frame(){
|
||||
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, {0,0,0,0});
|
||||
ImGui::PushStyleColor(ImGuiCol_HeaderActive, {0,0,0,0});
|
||||
|
||||
ImGui::BeginGroup();
|
||||
if (ImGui::ArrowButton("##left", ImGuiDir_Left))
|
||||
year--;
|
||||
ImGui::SameLine(0, 0);
|
||||
if(ImGui::BeginTable("CalendarHeader", 5)) {
|
||||
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); // Left side
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed); // Prev year
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, year_min_size); // Year
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed); // Next year
|
||||
ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch); // Right side
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
||||
if (ImGui::ArrowButton("##right", ImGuiDir_Right))
|
||||
year++;
|
||||
ImGui::SameLine(0, 0);
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
if (ImGui::ArrowButton("##left", ImGuiDir_Left))
|
||||
year--;
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
ImGui::TextAligned(0.5, -FLT_MIN, "%d", year);
|
||||
|
||||
ImGui::TableSetColumnIndex(3);
|
||||
if (ImGui::ArrowButton("##right", ImGuiDir_Right))
|
||||
year++;
|
||||
|
||||
ImGui::TextAligned(0.5, -FLT_MIN, "%d", year);
|
||||
ImGui::EndGroup();
|
||||
ImGui::TableSetColumnIndex(4);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
for (int month = 1; month <= 12; month++) {
|
||||
ImGui::PushID(month);
|
||||
@ -194,32 +217,51 @@ void per_frame(){
|
||||
}
|
||||
|
||||
ImGui::TableSetColumnIndex(weekday);
|
||||
ImU32 cell_bg_color_workweek = ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
ImU32 cell_bg_color_workweek = ImGui::GetColorU32(table_white_bg);
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color_workweek);
|
||||
|
||||
//weekend coloring
|
||||
if(weekday == 5){
|
||||
ImU32 cell_bg_color_sat = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 0.1f));
|
||||
ImU32 cell_bg_color_sat = ImGui::GetColorU32(table_saturday_bg);
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color_sat);
|
||||
}
|
||||
|
||||
if(weekday == 6){
|
||||
ImU32 cell_bg_color_sun = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 0.2f));
|
||||
ImU32 cell_bg_color_sun = ImGui::GetColorU32(table_sunday_bg);
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, cell_bg_color_sun);
|
||||
}
|
||||
|
||||
//color field with category
|
||||
for (int i = 0; i < num_categorized_days; i++) {
|
||||
if (categorized_days[i].year != year) continue;
|
||||
if (categorized_days[i].month != month) continue;
|
||||
if (categorized_days[i].day != day) continue;
|
||||
|
||||
|
||||
ImColor color = categories[categorized_days[i].category].color;
|
||||
color.Value.w = 0.5;
|
||||
|
||||
//sat + sun: add alpha value
|
||||
if(weekday == 5)
|
||||
color.Value.w = color.Value.w + table_saturday_bg.w;
|
||||
if(weekday == 6)
|
||||
color.Value.w = color.Value.w + table_sunday_bg.w;
|
||||
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ImU32(color));
|
||||
}
|
||||
|
||||
ImGui::TextAligned(0.5, -FLT_MIN, "%d", day);
|
||||
|
||||
if(ImGui::IsItemHovered()){
|
||||
if(selected_category != -1) {
|
||||
ImColor hover_color = categories[selected_category].color;
|
||||
hover_color.Value.w = 0.2;
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ImGui::GetColorU32(ImU32(hover_color)));
|
||||
} else {
|
||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ImGui::GetColorU32(table_hover_color));
|
||||
}
|
||||
}
|
||||
|
||||
//apply selected color to field
|
||||
if (selected_category != -1 && ImGui::IsItemClicked()) {
|
||||
for (int i = 0; i < num_categorized_days; i++) {
|
||||
if (categorized_days[i].year != year) continue;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user