From 4ee45db51b6ae7a03c3b9c06e9ca93ae6388bd3b Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 21 Jul 2024 14:01:29 +0100 Subject: [PATCH] Change: [UI] Use scaled sprite sizes and correct matrix padding for content list. (#12875) --- src/network/network_content_gui.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index d0f8afbde5..57abe51ca2 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -581,7 +581,7 @@ public: void OnInit() override { - this->checkbox_size = maxdim(maxdim(GetSpriteSize(SPR_BOX_EMPTY), GetSpriteSize(SPR_BOX_CHECKED)), GetSpriteSize(SPR_BLOT)); + this->checkbox_size = maxdim(maxdim(GetScaledSpriteSize(SPR_BOX_EMPTY), GetScaledSpriteSize(SPR_BOX_CHECKED)), GetScaledSpriteSize(SPR_BLOT)); } void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override @@ -644,15 +644,15 @@ public: */ void DrawMatrix(const Rect &r) const { - Rect checkbox = this->GetWidget(WID_NCL_CHECKBOX)->GetCurrentRect(); - Rect name = this->GetWidget(WID_NCL_NAME)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect); - Rect type = this->GetWidget(WID_NCL_TYPE)->GetCurrentRect(); + const Rect checkbox = this->GetWidget(WID_NCL_CHECKBOX)->GetCurrentRect(); + const Rect name = this->GetWidget(WID_NCL_NAME)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect); + const Rect type = this->GetWidget(WID_NCL_TYPE)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect); /* Fill the matrix with the information */ - int sprite_y_offset = (this->resize.step_height - this->checkbox_size.height) / 2; - int text_y_offset = (this->resize.step_height - GetCharacterHeight(FS_NORMAL)) / 2; + const uint step_height = this->GetWidget(WID_NCL_MATRIX)->resize_y; + const int text_y_offset = WidgetDimensions::scaled.matrix.top + (step_height - WidgetDimensions::scaled.matrix.Vertical() - GetCharacterHeight(FS_NORMAL)) / 2; - Rect mr = r.WithHeight(this->resize.step_height); + Rect mr = r.WithHeight(step_height); auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->content); for (auto iter = first; iter != last; iter++) { const ContentInfo *ci = *iter; @@ -669,13 +669,13 @@ public: case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break; default: NOT_REACHED(); } - DrawSprite(sprite, pal, checkbox.left + (sprite == SPR_BLOT ? 3 : 2), mr.top + sprite_y_offset + (sprite == SPR_BLOT ? 0 : 1)); + DrawSpriteIgnorePadding(sprite, pal, {checkbox.left, mr.top, checkbox.right, mr.bottom}, SA_CENTER); StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS; DrawString(type.left, type.right, mr.top + text_y_offset, str, TC_BLACK, SA_HOR_CENTER); DrawString(name.left, name.right, mr.top + text_y_offset, ci->name, TC_BLACK); - mr = mr.Translate(0, this->resize.step_height); + mr = mr.Translate(0, step_height); } } @@ -1054,13 +1054,13 @@ static constexpr NWidgetPart _nested_network_content_list_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(NWID_VERTICAL), NWidget(NWID_HORIZONTAL), - NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CHECKBOX), SetMinimalSize(13, 1), SetDataTip(STR_EMPTY, STR_NULL), + NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_CHECKBOX), SetDataTip(STR_EMPTY, STR_NULL), NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_TYPE), SetDataTip(STR_CONTENT_TYPE_CAPTION, STR_CONTENT_TYPE_CAPTION_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NCL_NAME), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_NAME_CAPTION, STR_CONTENT_NAME_CAPTION_TOOLTIP), EndContainer(), - NWidget(WWT_MATRIX, COLOUR_LIGHT_BLUE, WID_NCL_MATRIX), SetResize(1, 14), SetFill(1, 1), SetScrollbar(WID_NCL_SCROLLBAR), SetMatrixDataTip(1, 0, STR_CONTENT_MATRIX_TOOLTIP), + NWidget(WWT_MATRIX, COLOUR_LIGHT_BLUE, WID_NCL_MATRIX), SetResize(1, 1), SetFill(1, 1), SetScrollbar(WID_NCL_SCROLLBAR), SetMatrixDataTip(1, 0, STR_CONTENT_MATRIX_TOOLTIP), EndContainer(), NWidget(NWID_VSCROLLBAR, COLOUR_LIGHT_BLUE, WID_NCL_SCROLLBAR), EndContainer(),