Departures: Fix width of departure time and status columns

This commit is contained in:
Jonathan G Rennison 2024-09-08 20:54:19 +01:00
parent de972cd48f
commit 9ce255d706
3 changed files with 47 additions and 12 deletions

View File

@ -714,24 +714,35 @@ void DeparturesWindow::RecomputeDateWidth()
cached_status_width = std::max((GetStringBoundingBox(STR_DEPARTURES_ON_TIME)).width, cached_status_width);
cached_status_width = std::max((GetStringBoundingBox(STR_DEPARTURES_DELAYED)).width, cached_status_width);
cached_status_width = std::max((GetStringBoundingBox(STR_DEPARTURES_CANCELLED)).width, cached_status_width);
cached_status_width = std::max((GetStringBoundingBox(STR_DEPARTURES_SCHEDULED)).width, cached_status_width);
uint interval = cached_date_display_method ? _settings_time.ticks_per_minute : DAY_TICKS;
uint count = cached_date_display_method ? 24*60 : 365;
for (uint i = 0; i < count; ++i) {
SetDParam(0, STR_JUST_TT_TIME_ABS);
SetDParam(1, INT_MAX - (i*interval));
SetDParam(2, STR_JUST_TT_TIME_ABS);
SetDParam(3, INT_MAX - (i*interval));
cached_date_width = std::max(GetStringBoundingBox(STR_DEPARTURES_TIME_DEP).width, cached_date_width);
auto eval_tick = [&](StateTicks tick) {
SetDParam(0, TC_ORANGE);
SetDParam(1, STR_JUST_TT_TIME_ABS);
SetDParam(2, tick);
SetDParam(3, TC_ORANGE);
SetDParam(4, STR_JUST_TT_TIME_ABS);
SetDParam(5, tick);
cached_date_width = std::max(GetStringBoundingBox(STR_DEPARTURES_TIME).width, cached_date_width);
cached_date_combined_width = std::max(GetStringBoundingBox(STR_DEPARTURES_TIME_BOTH).width, cached_date_combined_width);
SetDParam(0, STR_JUST_TT_TIME_ABS);
SetDParam(1, tick);
cached_status_width = std::max((GetStringBoundingBox(STR_DEPARTURES_EXPECTED)).width, cached_status_width);
};
if (_settings_time.time_in_minutes) {
StateTicks tick = _settings_time.FromTickMinutes(_settings_time.NowInTickMinutes().ToSameDayClockTime(GetBroadestHourDigitsValue(), (int)GetBroadestDigitsValue(2)));
eval_tick(tick);
} else {
for (uint i = 0; i < 365; ++i) {
eval_tick(INT_MAX - (i * DAY_TICKS));
}
}
SetDParam(0, 0);
SetDParam(0, STR_JUST_TT_TIME_ABS);
SetDParam(1, 0);
cached_date_arrow_width = GetStringBoundingBox(STR_DEPARTURES_TIME_DEP).width - GetStringBoundingBox(STR_DEPARTURES_TIME).width;
cached_date_width -= cached_date_arrow_width;
}
uint DeparturesWindow::GetScrollbarCapacity() const

View File

@ -1343,6 +1343,29 @@ uint64_t GetBroadestDigitsValue(uint count, FontSize size)
return val;
}
/**
* Return some number in the range 0 - 23 that is suitable for string size computations.
* @param size Font of the number
* @return The number.
*/
uint GetBroadestHourDigitsValue(FontSize size)
{
int widths[2] = { -1, -1 };
uint8_t values[2] = { 0, 0 };
for (char c = '9'; c >= '0'; c--) {
int w = GetCharacterWidth(size, c);
auto test = [&](uint i) {
if (w > widths[i]) {
widths[i] = w;
values[i] = (uint8_t)(c - '0');
}
};
if (c <= '2') test(0);
test(1);
}
return (values[0] * 10) + values[1];
}
/**
* Determine the broadest digits for guessing the maximum width of a n-digit number.
* @param[out] front Broadest digit, which is not 0. (Use this digit as first digit for numbers with more than one digit.)

View File

@ -213,6 +213,7 @@ uint8_t GetCharacterWidth(FontSize size, char32_t key);
uint8_t GetDigitWidth(FontSize size = FS_NORMAL);
void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
uint64_t GetBroadestDigitsValue(uint count, FontSize size = FS_NORMAL);
uint GetBroadestHourDigitsValue(FontSize size = FS_NORMAL);
extern int font_height_cache[FS_END];