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).
This commit is contained in:
David Wagner
2025-02-14 16:38:25 +01:00
committed by GitHub
parent 1a03cb52a1
commit 3d57d3d65a

View File

@@ -114,6 +114,7 @@ DashboardItemElapsedTime::DashboardItemElapsedTime(const ghoul::Dictionary& dict
const Parameters p = codegen::bake<Parameters>(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<std::pair<double, std::string_view>> ts = splitTime(delta);
std::string time;
for (const std::pair<double, std::string_view>& 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,