From 3d57d3d65a0e008ed8e1dd1f608451f15c5de8a8 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Fri, 14 Feb 2025 16:38:25 +0100 Subject: [PATCH] Fixes for some "elapsed time" dashboard bugs (#3520) - Expose the FormatString property (closes #3519). Contrary to other properties, it wasn't accessible through the scripting API. - Fix the time simplification logic (closes #3515). If the lowest required time unit's value was zero, all time units where displayed regardless of what the user required. Fix this by using a "less than" comparison rather than an equality comparison. - Fix string truncation (closes #3516). The time string truncation was off by one, causing the trailing unit name to be truncated e.g. (minutes -> minute). --- modules/base/dashboard/dashboarditemelapsedtime.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/base/dashboard/dashboarditemelapsedtime.cpp b/modules/base/dashboard/dashboarditemelapsedtime.cpp index ef839ace01..bd0dda43b5 100644 --- a/modules/base/dashboard/dashboarditemelapsedtime.cpp +++ b/modules/base/dashboard/dashboarditemelapsedtime.cpp @@ -114,6 +114,7 @@ DashboardItemElapsedTime::DashboardItemElapsedTime(const ghoul::Dictionary& dict const Parameters p = codegen::bake(dictionary); _formatString = p.formatString.value_or(_formatString); + addProperty(_formatString); _referenceTime.onChange([this]() { _referenceJ2000 = Time::convertTime(_referenceTime); @@ -146,21 +147,19 @@ void DashboardItemElapsedTime::render(glm::vec2& penPosition) { using namespace std::chrono; const TimeUnit lowestTime = TimeUnit(_lowestTimeUnit.value()); - const std::string_view lowestUnitS = nameForTimeUnit(lowestTime, false); - const std::string_view lowestUnitP = nameForTimeUnit(lowestTime, true); const std::vector> ts = splitTime(delta); std::string time; for (const std::pair& t : ts) { - time += std::format("{} {} ", t.first, t.second); - if (t.second == lowestUnitS || t.second == lowestUnitP) { + if (timeUnitFromString(t.second) < lowestTime) { // We have reached the lowest unit the user was interested in break; } + time += std::format("{} {} ", t.first, t.second); } // Remove the " " at the end - time = time.substr(0, time.size() - 2); + time = time.substr(0, time.size() - 1); RenderFont( *_font,