1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-31 10:45:16 +01:00

Merge pull request #10953 from AaronVanGeffen/fix/10928

Fix #10928: File browser's date column is too narrow
This commit is contained in:
Aaron van Geffen
2020-03-30 23:00:57 +02:00
committed by GitHub
2 changed files with 25 additions and 10 deletions

View File

@@ -5,6 +5,7 @@
- Fix: [#475] Water sides drawn incorrectly (original bug).
- Fix: [#6123, #7907, #9472, #11028] Cannot build some track designs with 4 stations (original bug).
- Fix: [#7094] Back wall edge texture in water missing.
- Fix: [#10928] File browser's date column is too narrow.
- Fix: [#11005] Company value overflows.
- Fix: [#11027] Third color on walls becomes black when saving.
- Improved: [#11157] Slimmer virtual floor lines.

View File

@@ -635,27 +635,40 @@ static void window_loadsave_textinput(rct_window* w, rct_widgetindex widgetIndex
}
}
constexpr uint16_t DATE_TIME_GAP = 2;
static void window_loadsave_compute_max_date_width()
{
// Generate a time object for a relatively wide time: 2000-10-20 00:00:00
// Generate a time object for a relatively wide time: 2000-02-20 00:00:00
std::tm tm;
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 0;
tm.tm_mday = 20;
tm.tm_mon = 9;
tm.tm_mon = 2;
tm.tm_year = 100;
tm.tm_wday = 5;
tm.tm_yday = 294;
tm.tm_yday = 51;
tm.tm_isdst = -1;
std::time_t long_time = mktime(&tm);
// Check how how this date is represented (e.g. 2000-02-20, or 00/02/20)
std::string date = Platform::FormatShortDate(long_time);
maxDateWidth = gfx_get_string_width(date.c_str());
maxDateWidth = gfx_get_string_width(date.c_str()) + DATE_TIME_GAP;
// Some locales do not use leading zeros for months and days, so let's try October, too.
tm.tm_mon = 10;
tm.tm_yday = 294;
long_time = mktime(&tm);
// Again, check how how this date is represented (e.g. 2000-10-20, or 00/10/20)
date = Platform::FormatShortDate(long_time);
maxDateWidth = std::max(maxDateWidth, gfx_get_string_width(date.c_str()) + DATE_TIME_GAP);
// Time appears to be universally represented with two digits for minutes, so 12:00 or 00:00 should be representable.
std::string time = Platform::FormatTime(long_time);
maxTimeWidth = gfx_get_string_width(time.c_str());
maxTimeWidth = gfx_get_string_width(time.c_str()) + DATE_TIME_GAP;
}
static void window_loadsave_invalidate(rct_window* w)
@@ -670,8 +683,8 @@ static void window_loadsave_invalidate(rct_window* w)
window_loadsave_widgets[WIDX_RESIZE].bottom = w->height - 1;
rct_widget* date_widget = &window_loadsave_widgets[WIDX_SORT_DATE];
date_widget->left = w->width - maxDateWidth - maxTimeWidth - 24;
date_widget->right = w->width - 5;
date_widget->left = date_widget->right - (maxDateWidth + maxTimeWidth + (4 * DATE_TIME_GAP) + (SCROLLBAR_WIDTH + 1));
window_loadsave_widgets[WIDX_SORT_NAME].left = 4;
window_loadsave_widgets[WIDX_SORT_NAME].right = window_loadsave_widgets[WIDX_SORT_DATE].left - 1;
@@ -735,6 +748,7 @@ static void window_loadsave_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i
{
gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, ColourMapA[w->colours[1]].mid_light);
const int32_t listWidth = w->widgets[WIDX_SCROLL].right - w->widgets[WIDX_SCROLL].left;
const int32_t dateAnchor = w->widgets[WIDX_SORT_DATE].left + maxDateWidth + DATE_TIME_GAP;
for (int32_t i = 0; i < w->no_list_items; i++)
{
@@ -769,14 +783,14 @@ static void window_loadsave_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i
// Print formatted modified date, if this is a file
if (_listItems[i].type == TYPE_FILE)
{
int32_t offset = w->widgets[WIDX_SORT_DATE].left + maxDateWidth;
set_format_arg(0, rct_string_id, STR_STRING);
set_format_arg(2, char*, _listItems[i].date_formatted.c_str());
gfx_draw_string_right_clipped(dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, offset - 2, y, maxDateWidth);
gfx_draw_string_right_clipped(
dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, dateAnchor - DATE_TIME_GAP, y, maxDateWidth);
set_format_arg(2, char*, _listItems[i].time_formatted.c_str());
gfx_draw_string_left_clipped(dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, offset + 2, y, maxTimeWidth);
gfx_draw_string_left_clipped(
dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, dateAnchor + DATE_TIME_GAP, y, maxTimeWidth);
}
}
}