Codechange: Make GetCurrentRect() conform to usual Rect bounds, and reuse it.

Similar code is already repeated in other locations.
This commit is contained in:
Peter Nelson
2021-05-04 00:24:14 +01:00
committed by PeterN
parent 52b16237ad
commit d8e06e590a
5 changed files with 9 additions and 28 deletions

View File

@@ -2097,10 +2097,7 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny)
Rect caption_rect;
const NWidgetBase *caption = w->nested_root->GetWidgetOfType(WWT_CAPTION);
if (caption != nullptr) {
caption_rect.left = caption->pos_x;
caption_rect.right = caption->pos_x + caption->current_x;
caption_rect.top = caption->pos_y;
caption_rect.bottom = caption->pos_y + caption->current_y;
caption_rect = caption->GetCurrentRect();
/* Make sure the window doesn't leave the screen */
nx = Clamp(nx, MIN_VISIBLE_TITLE_BAR - caption_rect.right, _screen.width - MIN_VISIBLE_TITLE_BAR - caption_rect.left);