mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 11:39:49 -06:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user