selectable day

This commit is contained in:
2022-12-22 11:31:52 +01:00
parent 22f9a8a1a6
commit a7a7c1c845
2 changed files with 51 additions and 20 deletions

View File

@@ -29,6 +29,7 @@ DrawData* gDrawData;
ApplicationData* gAppData;
bool justDocked = false;
bool isHidden = false;
time_t selectedDay = 0;
int main()
{
@@ -49,6 +50,16 @@ int main()
startImgui(callbacks, "Audio Thingy", 700, 400);
}
time_t getDayStartOf(time_t time)
{
tm localTime;
localtime_s(&localTime, &time);
localTime.tm_hour = 0;
localTime.tm_min = 0;
localTime.tm_sec = 0;
return mktime(&localTime);
}
void init(DrawData& drawData, ApplicationData& appData)
{
std::wstring appPath;
@@ -77,6 +88,8 @@ void init(DrawData& drawData, ApplicationData& appData)
iconFontPath.append("\\remixicon.ttf");
io.Fonts->AddFontFromFileTTF(iconFontPath.c_str(), 14.0f, &icons_config, icons_ranges);
// Time
selectedDay = getDayStartOf(std::time(nullptr));
initShell(drawData);
initSettings(drawData, appData);
@@ -216,7 +229,7 @@ bool customButton(const char* id_start, const char* id_end, const char* title, b
return result;
}
void drawCheclistDayLines(ApplicationData& appData, ImDrawList* drawList, float lineHeight, time_t day)
void drawChecklistDayLines(ApplicationData& appData, ImDrawList* drawList, float lineHeight, time_t day)
{
auto& tasks = appData.settings.tasks;
size_t totalTasks = appData.settings.taskNames.size();
@@ -224,25 +237,35 @@ void drawCheclistDayLines(ApplicationData& appData, ImDrawList* drawList, float
for (int i = 0; i < count; i++)
{
ImVec2 cursorPos = ImGui::GetCursorScreenPos();
drawList->AddLine({ cursorPos.x, cursorPos.y }, { cursorPos.x, cursorPos.y + lineHeight }, ImColor(.4f, .9f, .3f), 3.f);
ImGui::SetCursorScreenPos({ cursorPos.x + 5.f, cursorPos.y });
drawList->AddLine({ cursorPos.x, cursorPos.y }, { cursorPos.x, cursorPos.y + lineHeight }, ImColor(.4f, .9f, .3f), DAY_LINE_WIDTH);
ImGui::SetCursorScreenPos({ cursorPos.x + DAY_LINE_OFFSET, cursorPos.y });
}
for (int i = 0; i < max(0, totalTasks - count); i++)
{
ImVec2 cursorPos = ImGui::GetCursorScreenPos();
drawList->AddLine({ cursorPos.x, cursorPos.y }, { cursorPos.x, cursorPos.y + lineHeight }, ImColor(.1f, .3f, .05f), 3.f);
ImGui::SetCursorScreenPos({ cursorPos.x + 5.f, cursorPos.y });
drawList->AddLine({ cursorPos.x, cursorPos.y }, { cursorPos.x, cursorPos.y + lineHeight }, ImColor(.1f, .3f, .05f), DAY_LINE_WIDTH);
ImGui::SetCursorScreenPos({ cursorPos.x + DAY_LINE_OFFSET, cursorPos.y });
}
}
time_t getDayStartOf(time_t time)
void drawDayLineButton(ApplicationData& appData, ImDrawList* drawList, float lineHeight, time_t day, bool drawRect = true)
{
tm localTime;
localtime_s(&localTime, &time);
localTime.tm_hour = 0;
localTime.tm_min = 0;
localTime.tm_sec = 0;
return mktime(&localTime);
ImVec2 pos = ImGui::GetCursorScreenPos();
ImVec2 startPos = { pos.x - DAY_OUTLINE_SIZE, pos.y - DAY_OUTLINE_SIZE };
size_t taskCount = appData.settings.taskNames.size();
ImVec2 size = { DAY_LINE_OFFSET * taskCount + DAY_OUTLINE_SIZE, lineHeight + DAY_OUTLINE_SIZE * 2.f };
ImVec2 endPos = { startPos.x + size.x, startPos.y + size.y };
ImGui::SetCursorScreenPos(startPos);
if (selectedDay == day)
{
if (drawRect) drawList->AddRect(startPos, endPos, ImColor(1.f, 1.f, 1.f));
}
else if (ImGui::InvisibleButton(std::format("daybn_{}", day).c_str(), size))
{
selectedDay = day;
}
ImGui::SetCursorScreenPos(pos);
}
ImVec2 checklistWindow(ApplicationData& appData, const char* title)
@@ -256,7 +279,9 @@ ImVec2 checklistWindow(ApplicationData& appData, const char* title)
for (int pastDay = 3; pastDay >= 1; pastDay--)
{
time_t date = today - (60 * 60 * 24 * pastDay);
drawCheclistDayLines(appData, drawList, lineHeight, date);
drawDayLineButton(appData, drawList, lineHeight, date);
drawChecklistDayLines(appData, drawList, lineHeight, date);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 5.f);
}
@@ -265,11 +290,13 @@ ImVec2 checklistWindow(ApplicationData& appData, const char* title)
drawList->AddLine({ cursorPos.x, cursorPos.y - 2.f }, { cursorPos.x, cursorPos.y + lineHeight + 2.f }, IM_COL32_WHITE, 1.f);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10.f);
drawCheclistDayLines(appData, drawList, lineHeight, today);
drawDayLineButton(appData, drawList, lineHeight, today, false);
drawChecklistDayLines(appData, drawList, lineHeight, today);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10.f);
auto todayMatcher = [&](time_t t) { return getDayStartOf(t) == today; };
auto selectedDayMatcher = [&](time_t t) { return getDayStartOf(t) == selectedDay; };
for (std::string& taskName : appData.settings.taskNames)
{
@@ -279,17 +306,17 @@ ImVec2 checklistWindow(ApplicationData& appData, const char* title)
}
std::vector<time_t>& taskDates = appData.settings.tasks[taskName];
bool taskDoneToday = std::any_of(taskDates.begin(), taskDates.end(), todayMatcher);
bool taskDone = std::any_of(taskDates.begin(), taskDates.end(), selectedDayMatcher);
if (ImGui::Checkbox(taskName.c_str(), &taskDoneToday))
if (ImGui::Checkbox(taskName.c_str(), &taskDone))
{
if (taskDoneToday)
if (taskDone)
{
taskDates.push_back(today);
taskDates.push_back(selectedDay);
}
else
{
std::erase_if(taskDates, todayMatcher);
std::erase_if(taskDates, selectedDayMatcher);
}
}
ImGui::SameLine();

View File

@@ -5,6 +5,10 @@
#include <vector>
#define DAY_LINE_WIDTH 3.f
#define DAY_LINE_OFFSET 5.f
#define DAY_OUTLINE_SIZE 3.f
void init(DrawData& drawData, ApplicationData& customData);
void draw(DrawData& drawData, ApplicationData& customData);
void cleanup(DrawData& drawData, ApplicationData& appData);