checklist stuff

This commit is contained in:
2022-12-22 10:55:56 +01:00
parent 7e76c4813d
commit 22f9a8a1a6
10 changed files with 2445 additions and 40 deletions

View File

@@ -19,8 +19,10 @@
#include <functional>
#include <iostream>
#include <sstream>
#include <format>
#include <ctime>
const size_t MAX_FONT_PATH_LENGTH = 2048;
#define MAX_FONT_PATH_LENGTH 2048
// Globals for use in callbacks
DrawData* gDrawData;
@@ -44,7 +46,7 @@ int main()
callbacks.drawFunc = std::bind(draw, std::placeholders::_1, std::ref(applicationData));
callbacks.cleanupFunc = std::bind(cleanup, std::placeholders::_1, std::ref(applicationData));
startImgui(callbacks, "Audio Thingy", 600, 400);
startImgui(callbacks, "Audio Thingy", 700, 400);
}
void init(DrawData& drawData, ApplicationData& appData)
@@ -70,6 +72,7 @@ void init(DrawData& drawData, ApplicationData& appData)
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
icons_config.GlyphOffset = { 0., 2. };
std::string iconFontPath = std::string(appPathStr);
iconFontPath.append("\\remixicon.ttf");
io.Fonts->AddFontFromFileTTF(iconFontPath.c_str(), 14.0f, &icons_config, icons_ranges);
@@ -96,17 +99,24 @@ void draw(DrawData& drawData, ApplicationData& appData)
// Menu Bar
customYCursor += menuBar(drawData, appData).y;
// Checklist
ImGui::SetNextWindowPos(ImVec2(0, customYCursor));
ImGui::SetNextWindowSize(ImVec2(viewportSize.x, 0));
customYCursor += checklistWindow(appData, std::format(" {} Checklist", ICON_CHECK_FILL).c_str()).y;
customYCursor += 5.;
// Playback Devices
ImGui::SetNextWindowPos(ImVec2(0, customYCursor));
ImGui::SetNextWindowSize(ImVec2(viewportSize.x, 0));
customYCursor += audioDeviceWindow(appData, appData.audioData->playbackDevices, " \xEE\xB8\x84 Playback").y;
customYCursor += audioDeviceWindow(appData, appData.audioData->playbackDevices, std::format(" {} Playback", ICON_HEADPHONE_FILL).c_str()).y;
customYCursor += 5.;
// Recording devices
ImGui::SetNextWindowPos(ImVec2(0, customYCursor));
ImGui::SetNextWindowSize(ImVec2(viewportSize.x, 0));
customYCursor += audioDeviceWindow(appData, appData.audioData->recordingDevices, " \xEE\xBD\x8F Recording").y;
customYCursor += audioDeviceWindow(appData, appData.audioData->recordingDevices, std::format(" {} Recording", ICON_MIC_FILL).c_str()).y;
// Resize viewport
drawData.window_size.y = customYCursor;
@@ -162,13 +172,13 @@ ImVec2 menuBar(DrawData& drawData, ApplicationData& appData)
{
ImVec2 availableSpace = ImGui::GetContentRegionAvail();
ImVec2 cursorPos = ImGui::GetCursorPos();
ImGui::SetCursorPosX(cursorPos.x + availableSpace.x - 33.);
ImGui::SetCursorPosX(cursorPos.x + availableSpace.x - 47.);
if (ImGui::SmallButton("-"))
if (ImGui::SmallButton(ICON_SUBTRACT_FILL))
{
glfwIconifyWindow(drawData.window);
}
if (ImGui::SmallButton("x"))
if (ImGui::SmallButton(ICON_CLOSE_FILL))
{
glfwSetWindowShouldClose(drawData.window, GLFW_TRUE);
}
@@ -206,6 +216,91 @@ 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)
{
auto& tasks = appData.settings.tasks;
size_t totalTasks = appData.settings.taskNames.size();
size_t count = std::count_if(tasks.begin(), tasks.end(), [&](std::pair<std::string, std::vector<time_t>> t) { return std::any_of(t.second.begin(), t.second.end(), [&](time_t tt) { return tt == day; }); });
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 });
}
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 });
}
}
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);
}
ImVec2 checklistWindow(ApplicationData& appData, const char* title)
{
if (ImGui::Begin(title, 0, ImGuiWindowFlags_NoResize))
{
time_t today = getDayStartOf(std::time(nullptr));
ImDrawList* drawList = ImGui::GetWindowDrawList();
float lineHeight = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2;
for (int pastDay = 3; pastDay >= 1; pastDay--)
{
time_t date = today - (60 * 60 * 24 * pastDay);
drawCheclistDayLines(appData, drawList, lineHeight, date);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 5.f);
}
ImVec2 cursorPos = ImGui::GetCursorScreenPos();
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);
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10.f);
auto todayMatcher = [&](time_t t) { return getDayStartOf(t) == today; };
for (std::string& taskName : appData.settings.taskNames)
{
if (!appData.settings.tasks.contains(taskName))
{
appData.settings.tasks.insert({ taskName, std::vector<time_t>{} });
}
std::vector<time_t>& taskDates = appData.settings.tasks[taskName];
bool taskDoneToday = std::any_of(taskDates.begin(), taskDates.end(), todayMatcher);
if (ImGui::Checkbox(taskName.c_str(), &taskDoneToday))
{
if (taskDoneToday)
{
taskDates.push_back(today);
}
else
{
std::erase_if(taskDates, todayMatcher);
}
}
ImGui::SameLine();
}
}
ImVec2 size = ImGui::GetWindowSize();
ImGui::End();
return size;
}
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title)
{
if (ImGui::Begin(title, 0, ImGuiWindowFlags_NoResize))
@@ -215,7 +310,6 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
ImGui::TableSetupColumn("Devices", ImGuiTableColumnFlags_WidthStretch, 3.);
ImGui::TableSetupColumn("Volume", ImGuiTableColumnFlags_WidthStretch, 1.);
ImGui::TableSetupColumn("Defaults", ImGuiTableColumnFlags_WidthFixed, 55.);
//ImGui::TableSetupColumn("Proc", ImGuiTableColumnFlags_WidthFixed, 30.);
ImGui::TableHeadersRow();
for (auto& dev : deviceList)
@@ -250,7 +344,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
bool isDeviceMuted = isMuted(dev.volumeInterface);
if (ImGui::Button(isDeviceMuted ? "\xEF\x8A\x9D" : "\xEF\x8A\xA1"))
if (ImGui::Button(isDeviceMuted ? ICON_VOLUME_MUTE_FILL : ICON_VOLUME_UP_FILL))
{
setMuted(dev.volumeInterface, !isDeviceMuted);
}
@@ -310,7 +404,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
{
drawCircle(5, IM_COL32(50, 50, 222, 255));
}
if (customButton("bn_d_", deviceIdUtf8.c_str(), "\xEE\xBE\x82", !dev.isDefaultConsole))
if (customButton("bn_d_", deviceIdUtf8.c_str(), ICON_MUSIC_2_FILL, !dev.isDefaultConsole))
{
setDefaultAudioDevice(*appData.audioData, dev.id.c_str(), ERole::eConsole);
}
@@ -320,27 +414,12 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
{
drawCircle(5, IM_COL32(222, 50, 50, 255));
}
if (customButton("bn_c_", deviceIdUtf8.c_str(), "\xEE\xBF\xA9", !dev.isDefaultCommunication))
if (customButton("bn_c_", deviceIdUtf8.c_str(), ICON_PHONE_FILL, !dev.isDefaultCommunication))
{
setDefaultAudioDevice(*appData.audioData, dev.id.c_str(), ERole::eCommunications);
}
}
// Advanced
/*ImGui::TableNextColumn();
AudioProcessingState procState = getAudioProcessing(dev);
bool procChecked = procState == AudioProcessingState::Enabled;
std::string procCbId("cb_proc_");
procCbId.append(deviceIdUtf8.c_str());
ImGui::PushID(procCbId.c_str());
if (ImGui::Checkbox("", &procChecked))
{
setAudioProcessing(dev, procChecked);
}
ImGui::PopID();*/
ImGui::PopStyleColor();
}