From 8a6745b26f0087d9a801ed2cf4dd7e4b99ce0b09 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 22 May 2024 19:06:52 +0100 Subject: [PATCH] Codechange: Use PIP instead of spacer widgets for OSK spacing. (#12709) This (slightly) simplifies the OSK widget layout. --- src/osk_gui.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp index 23c1a676e1..72d10e960f 100644 --- a/src/osk_gui.cpp +++ b/src/osk_gui.cpp @@ -227,16 +227,10 @@ static void AddKey(std::unique_ptr &hor, int pad_y, int num_h int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1); if (widtype == NWID_SPACER) { - if (!hor->IsEmpty()) key_width += INTER_KEY_SPACE; auto spc = std::make_unique(key_width, 0); spc->SetMinimalTextLines(1, pad_y, FS_NORMAL); hor->Add(std::move(spc)); } else { - if (!hor->IsEmpty()) { - auto spc = std::make_unique(INTER_KEY_SPACE, 0); - spc->SetMinimalTextLines(1, pad_y, FS_NORMAL); - hor->Add(std::move(spc)); - } auto leaf = std::make_unique(widtype, COLOUR_GREY, widnum, widdata, STR_NULL); leaf->SetMinimalSize(key_width, 0); leaf->SetMinimalTextLines(1, pad_y, FS_NORMAL); @@ -248,6 +242,7 @@ static void AddKey(std::unique_ptr &hor, int pad_y, int num_h static std::unique_ptr MakeTopKeys() { auto hor = std::make_unique(); + hor->SetPIP(0, INTER_KEY_SPACE, 0); AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_CANCEL, STR_BUTTON_CANCEL); AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_OK, STR_BUTTON_OK ); @@ -259,6 +254,7 @@ static std::unique_ptr MakeTopKeys() static std::unique_ptr MakeNumberKeys() { std::unique_ptr hor = std::make_unique(); + hor->SetPIP(0, INTER_KEY_SPACE, 0); for (WidgetID widnum = WID_OSK_NUMBERS_FIRST; widnum <= WID_OSK_NUMBERS_LAST; widnum++) { AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0); @@ -270,6 +266,7 @@ static std::unique_ptr MakeNumberKeys() static std::unique_ptr MakeQwertyKeys() { std::unique_ptr hor = std::make_unique(); + hor->SetPIP(0, INTER_KEY_SPACE, 0); AddKey(hor, KEY_PADDING, 3, WWT_PUSHIMGBTN, WID_OSK_SPECIAL, SPR_OSK_SPECIAL); for (WidgetID widnum = WID_OSK_QWERTY_FIRST; widnum <= WID_OSK_QWERTY_LAST; widnum++) { @@ -283,6 +280,7 @@ static std::unique_ptr MakeQwertyKeys() static std::unique_ptr MakeAsdfgKeys() { std::unique_ptr hor = std::make_unique(); + hor->SetPIP(0, INTER_KEY_SPACE, 0); AddKey(hor, KEY_PADDING, 4, WWT_IMGBTN, WID_OSK_CAPS, SPR_OSK_CAPS); for (WidgetID widnum = WID_OSK_ASDFG_FIRST; widnum <= WID_OSK_ASDFG_LAST; widnum++) { @@ -295,6 +293,7 @@ static std::unique_ptr MakeAsdfgKeys() static std::unique_ptr MakeZxcvbKeys() { std::unique_ptr hor = std::make_unique(); + hor->SetPIP(0, INTER_KEY_SPACE, 0); AddKey(hor, KEY_PADDING, 3, WWT_IMGBTN, WID_OSK_SHIFT, SPR_OSK_SHIFT); for (WidgetID widnum = WID_OSK_ZXCVB_FIRST; widnum <= WID_OSK_ZXCVB_LAST; widnum++) { @@ -308,6 +307,7 @@ static std::unique_ptr MakeZxcvbKeys() static std::unique_ptr MakeSpacebarKeys() { auto hor = std::make_unique(); + hor->SetPIP(0, INTER_KEY_SPACE, 0); AddKey(hor, KEY_PADDING, 8, NWID_SPACER, 0, 0); AddKey(hor, KEY_PADDING, 13, WWT_PUSHTXTBTN, WID_OSK_SPACE, STR_EMPTY); @@ -323,13 +323,15 @@ static constexpr NWidgetPart _nested_osk_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 12), SetPadding(2, 2, 2, 2), EndContainer(), - NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(5, 2, 3), - NWidgetFunction(MakeTopKeys), SetPadding(0, 3, 0, 3), - NWidgetFunction(MakeNumberKeys), SetPadding(0, 3, 0, 3), - NWidgetFunction(MakeQwertyKeys), SetPadding(0, 3, 0, 3), - NWidgetFunction(MakeAsdfgKeys), SetPadding(0, 3, 0, 3), - NWidgetFunction(MakeZxcvbKeys), SetPadding(0, 3, 0, 3), - NWidgetFunction(MakeSpacebarKeys), SetPadding(0, 3, 0, 3), + NWidget(WWT_PANEL, COLOUR_GREY), + NWidget(NWID_VERTICAL), SetPadding(3), SetPIP(0, INTER_KEY_SPACE, 0), + NWidgetFunction(MakeTopKeys), + NWidgetFunction(MakeNumberKeys), + NWidgetFunction(MakeQwertyKeys), + NWidgetFunction(MakeAsdfgKeys), + NWidgetFunction(MakeZxcvbKeys), + NWidgetFunction(MakeSpacebarKeys), + EndContainer(), EndContainer(), };