Fix widths of time columns for fonts with proportional figures

This still breaks when the 0 digit is narrower than some other
digit, but that's unlikely and the current behavior now matches
the original behavior when all times are < 10h.

Fixes arch1t3cht/Aegisub#111 .
This commit is contained in:
arch1t3cht 2024-02-19 14:22:27 +01:00
parent eaf09b2850
commit 1515c77438
1 changed files with 16 additions and 6 deletions

View File

@ -159,9 +159,14 @@ struct GridColumnStartTime final : GridColumnTime {
int Width(const agi::Context *c, WidthHelper &helper) const override {
agi::Time max_time = max_value(&AssDialogue::Start, c->ass->Events);
if (!by_frame)
return helper(max_time.GetAssFormatted());
return helper(std::to_wstring(c->videoController->FrameAtTime(max_time, agi::vfr::START)));
std::string value = by_frame ? std::to_string(c->videoController->FrameAtTime(max_time, agi::vfr::START)) : max_time.GetAssFormatted();
for (char &c : value) {
if (c >= '0' && c <= '9')
c = '0';
}
return helper(value);
}
};
@ -177,9 +182,14 @@ struct GridColumnEndTime final : GridColumnTime {
int Width(const agi::Context *c, WidthHelper &helper) const override {
agi::Time max_time = max_value(&AssDialogue::End, c->ass->Events);
if (!by_frame)
return helper(max_time.GetAssFormatted());
return helper(std::to_wstring(c->videoController->FrameAtTime(max_time, agi::vfr::END)));
std::string value = by_frame ? std::to_string(c->videoController->FrameAtTime(max_time, agi::vfr::END)) : max_time.GetAssFormatted();
for (char &c : value) {
if (c >= '0' && c <= '9')
c = '0';
}
return helper(value);
}
};