timer stuff

This commit is contained in:
2023-03-26 17:29:32 +02:00
parent 132d493dc6
commit 3ecaf255d7
2 changed files with 75 additions and 28 deletions

View File

@@ -137,12 +137,13 @@ void draw(DrawData& drawData, ApplicationData& appData)
// Timer
ImGui::SetNextWindowPos(ImVec2(0, customYCursor));
ImGui::SetNextWindowSize(ImVec2(viewportSize.x / 2.f, 0));
timerWindow(drawData, appData);
float timerWindowHeight = timerWindow(drawData, appData).y;
// Base Stations
ImGui::SetNextWindowPos(ImVec2(viewportSize.x / 2.f, customYCursor));
ImGui::SetNextWindowSize(ImVec2(viewportSize.x / 2.f, 0));
customYCursor += baseStationWindow(appData).y;
float baseStationWindowHeight = baseStationWindow(appData).y;
customYCursor += max(baseStationWindowHeight, timerWindowHeight);
customYCursor += panelGap;
// Playback Devices
@@ -225,6 +226,12 @@ ImVec2 menuBar(DrawData& drawData, ApplicationData& appData)
ImGui::Text("display: %.1f ms", drawData.frameTimeDisplay);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Style"))
{
ImGui::ShowStyleEditor();
ImGui::EndMenu();
}
if (appData.settings.docked)
{
@@ -335,12 +342,22 @@ void drawDayLineButton(ApplicationData& appData, ImDrawList* drawList, float lin
}
}
void formatTime(std::chrono::system_clock::time_point time, char* buffer, size_t bufferSize)
void SetTimerDuration(ApplicationData& appData, int timerEndHours, int timerEndMinutes, tm& timeInfo)
{
const time_t tTime = std::chrono::system_clock::to_time_t(time);
tm timeInfo;
localtime_s(&timeInfo, &tTime);
std::strftime(buffer, bufferSize, "%H:%M", &timeInfo);
timeInfo.tm_hour = timerEndHours;
timeInfo.tm_min = timerEndMinutes;
std::chrono::time_point<std::chrono::system_clock> newEndTime = std::chrono::system_clock::from_time_t(mktime(&timeInfo));
if (newEndTime < std::chrono::system_clock::now())
{
newEndTime += std::chrono::days(1);
}
else if (newEndTime > std::chrono::system_clock::now() + std::chrono::days(1))
{
newEndTime -= std::chrono::days(1);
}
appData.settings.timerDuration = std::chrono::duration_cast<std::chrono::seconds>(newEndTime - std::chrono::system_clock::now()).count();
}
ImVec2 timerWindow(DrawData& drawData, ApplicationData& appData)
@@ -431,8 +448,12 @@ ImVec2 timerWindow(DrawData& drawData, ApplicationData& appData)
}
ImGui::SameLine();
ImGui::PushItemWidth(45.f);
if (ImGui::InputFloat("##timer", &timerDisplayMinutes, 0, 0, "%.0fm"))
const char* durationFormatStr = "%.0fm";
char durationCalcBuffer[32];
snprintf(durationCalcBuffer, 32, durationFormatStr, timerDisplayMinutes);
ImGui::PushItemWidth(ImGui::CalcTextSize(durationCalcBuffer).x + ImGui::GetStyle().FramePadding.x * 2.f);
if (ImGui::DragFloat("##timer", &timerDisplayMinutes, .1f, 0.f, 1000.f, durationFormatStr))
{
appData.settings.timerDuration = timerDisplayMinutes * 60.f;
}
@@ -446,31 +467,54 @@ ImVec2 timerWindow(DrawData& drawData, ApplicationData& appData)
ImGui::SameLine();
char timeStr[32];
std::string timerText;
std::chrono::time_point<std::chrono::system_clock> endTime;
const char* endTimeText;
if (timerData.isTimerActive)
{
if (timerData.timerHasNotified)
{
formatTime(timerData.timerStartTimestamp + std::chrono::seconds((int)appData.settings.timerDuration), timeStr, sizeof(timeStr));
timerText = std::format("Ended at {}", timeStr);
endTime = timerData.timerStartTimestamp + std::chrono::seconds((int)appData.settings.timerDuration);
endTimeText = "Ended";
}
else
{
formatTime(appData.timerData.timerStartTimestamp + std::chrono::seconds((int)appData.settings.timerDuration), timeStr, sizeof(timeStr));
timerText = std::format("Ends at {}", timeStr);
endTime = appData.timerData.timerStartTimestamp + std::chrono::seconds((int)appData.settings.timerDuration);
endTimeText = "Ends";
}
}
else
{
formatTime(std::chrono::system_clock::now() + std::chrono::seconds((int)appData.settings.timerDuration), timeStr, sizeof(timeStr));
timerText = std::format("Ends at {}", timeStr);
endTime = std::chrono::system_clock::now() + std::chrono::seconds((int)appData.settings.timerDuration);
endTimeText = "Ends";
}
float availWidth = ImGui::GetContentRegionMax().x - ImGui::GetCursorPosX();
float textWidth = ImGui::CalcTextSize(timerText.c_str()).x;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + availWidth - textWidth);
ImGui::Text(timerText.c_str());
const float timeDragWidth = 32.f;
float requiredWidth = ImGui::CalcTextSize(endTimeText).x + timeDragWidth * 2.f + ImGui::GetStyle().ItemSpacing.x * 4.f;
float spaceWidth = ImGui::GetContentRegionAvail().x - requiredWidth;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + spaceWidth);
const time_t tTime = std::chrono::system_clock::to_time_t(endTime);
tm timeInfo;
localtime_s(&timeInfo, &tTime);
int timerEndHours = timeInfo.tm_hour;
int timerEndMinutes = timeInfo.tm_min;
ImGui::Text("%s", endTimeText);
ImGui::SameLine();
ImGui::PushItemWidth(timeDragWidth);
if (ImGui::DragInt("##timerEndHours", &timerEndHours, .1f, 0, 23, "%d", ImGuiInputTextFlags_CharsDecimal))
{
SetTimerDuration(appData, timerEndHours, timerEndMinutes, timeInfo);
}
ImGui::SameLine();
ImGui::Text(":");
ImGui::SameLine();
if (ImGui::DragInt("##timerEndMinutes", &timerEndMinutes, .2f, 0, 59, "%02d", ImGuiInputTextFlags_CharsDecimal))
{
SetTimerDuration(appData, timerEndHours, timerEndMinutes, timeInfo);
}
ImGui::PopItemWidth();
}
if (ImGui::BeginPopup(SETTINGS_POPUP_NAME))
@@ -574,7 +618,7 @@ ImVec2 checklistWindow(ApplicationData& appData, const char* title)
std::erase_if(taskDates, selectedDayMatcher);
}
}
ImGui::SameLine();
ImGui::SameLine(0.f, 10.f);
if (highlightButton)
{
@@ -741,7 +785,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
ImGui::OpenPopup(SETTINGS_POPUP_NAME);
}
if (ImGui::BeginTable("DeviceTable", 4, ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders | ImGuiTableFlags_NoSavedSettings))
if (ImGui::BeginTable("DeviceTable", 4, ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_NoSavedSettings))
{
ImGui::TableSetupColumn("Devices", ImGuiTableColumnFlags_WidthStretch, 3.);
ImGui::TableSetupColumn("Volume", ImGuiTableColumnFlags_WidthStretch, 1.);
@@ -766,11 +810,14 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(.7, .7, .7, 1.));
}
// Device Name
ImGui::TableNextRow();
ImGui::TableNextColumn();
// Device Name
float yPosTemp = ImGui::GetCursorPosY();
ImGui::SetCursorPosY(yPosTemp + 4.f);
ImGui::Text(dev.name.c_str());
ImGui::SetCursorPosY(yPosTemp);
// Volume
ImGui::TableNextColumn();

View File

@@ -204,8 +204,8 @@ void loadUiStyle()
colors[ImGuiCol_CheckMark] = ImVec4(0.98f, 0.61f, 0.26f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.88f, 0.38f, 0.24f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.98f, 0.41f, 0.26f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.04f, 0.01f, 0.03f, 0.73f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.28f, 0.14f, 0.23f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.21f, 0.11f, 0.17f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.15f, 0.25f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.47f, 0.23f, 0.39f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.46f, 0.19f, 0.12f, 0.67f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.69f, 0.29f, 0.19f, 0.80f);
@@ -225,7 +225,7 @@ void loadUiStyle()
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.25f, 0.10f, 0.10f, 1.00f);
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);