From 141571cc553d14cce53997ed3d2b7879a4ea2f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 1 Apr 2023 13:23:52 +0200 Subject: [PATCH] Refactor `CEditor::PopupNewFolder` and improve layout Swap buttons so confirm button is on the right and cancel button is on the left consistently. Decrease empty space and popup size. --- src/game/editor/editor.cpp | 6 ++++-- src/game/editor/popups.cpp | 44 ++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 1de2a530a..009f5dbac 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -5079,8 +5079,10 @@ void CEditor::RenderFileDialog() if(DoButton_Editor(&s_NewFolderButton, "New folder", 0, &Button, 0, nullptr)) { m_aFileDialogNewFolderName[0] = 0; - static int s_NewFolderPopupID = 0; - UiInvokePopupMenu(&s_NewFolderPopupID, 0, Width / 2.0f - 200.0f, Height / 2.0f - 100.0f, 400.0f, 200.0f, PopupNewFolder); + static int s_PopupNewFolderId; + constexpr float PopupWidth = 400.0f; + constexpr float PopupHeight = 110.0f; + UiInvokePopupMenu(&s_PopupNewFolderId, 0, Width / 2.0f - PopupWidth / 2.0f, Height / 2.0f - PopupHeight / 2.0f, PopupWidth, PopupHeight, PopupNewFolder); UI()->SetActiveItem(nullptr); } diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index d5eef51a3..c80bc1e47 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1371,35 +1371,38 @@ int CEditor::PopupSound(CEditor *pEditor, CUIRect View, void *pContext) int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View, void *pContext) { - CUIRect Label, ButtonBar; + CUIRect Label, ButtonBar, Button; - // title - View.HSplitTop(10.0f, nullptr, &View); - View.HSplitTop(30.0f, &Label, &View); - pEditor->UI()->DoLabel(&Label, "Create new folder", 20.0f, TEXTALIGN_CENTER); - - View.HSplitBottom(10.0f, &View, nullptr); + View.Margin(10.0f, &View); View.HSplitBottom(20.0f, &View, &ButtonBar); - // interaction box - View.HSplitBottom(40.0f, &View, nullptr); - View.VMargin(40.0f, &View); - View.HSplitBottom(20.0f, &View, &Label); - static float s_FolderBox = 0; - pEditor->DoEditBox(&s_FolderBox, &Label, pEditor->m_aFileDialogNewFolderName, sizeof(pEditor->m_aFileDialogNewFolderName), 15.0f, &s_FolderBox); - View.HSplitBottom(20.0f, &View, &Label); + // title + View.HSplitTop(20.0f, &Label, &View); + pEditor->UI()->DoLabel(&Label, "Create new folder", 20.0f, TEXTALIGN_CENTER); + View.HSplitTop(10.0f, nullptr, &View); + + // folder name + View.HSplitTop(20.0f, &Label, &View); pEditor->UI()->DoLabel(&Label, "Name:", 10.0f, TEXTALIGN_LEFT); + Label.VSplitLeft(50.0f, nullptr, &Button); + Button.HMargin(2.0f, &Button); + static float s_FolderBox = 0; + pEditor->DoEditBox(&s_FolderBox, &Button, pEditor->m_aFileDialogNewFolderName, sizeof(pEditor->m_aFileDialogNewFolderName), 12.0f, &s_FolderBox); // button bar - ButtonBar.VSplitLeft(30.0f, nullptr, &ButtonBar); - ButtonBar.VSplitLeft(110.0f, &Label, &ButtonBar); + ButtonBar.VSplitLeft(110.0f, &Button, &ButtonBar); + static int s_CancelButton = 0; + if(pEditor->DoButton_Editor(&s_CancelButton, "Cancel", 0, &Button, 0, nullptr)) + return 1; + + ButtonBar.VSplitRight(110.0f, &ButtonBar, &Button); static int s_CreateButton = 0; - if(pEditor->DoButton_Editor(&s_CreateButton, "Create", 0, &Label, 0, nullptr) || pEditor->Input()->KeyPress(KEY_RETURN) || pEditor->Input()->KeyPress(KEY_KP_ENTER)) + if(pEditor->DoButton_Editor(&s_CreateButton, "Create", 0, &Button, 0, nullptr) || pEditor->UI()->ConsumeHotkey(CUI::HOTKEY_ENTER)) { // create the folder if(pEditor->m_aFileDialogNewFolderName[0]) { - char aBuf[512]; + char aBuf[IO_MAX_PATH_LENGTH]; str_format(aBuf, sizeof(aBuf), "%s/%s", pEditor->m_pFileDialogPath, pEditor->m_aFileDialogNewFolderName); if(pEditor->Storage()->CreateFolder(aBuf, IStorage::TYPE_SAVE)) { @@ -1412,11 +1415,6 @@ int CEditor::PopupNewFolder(CEditor *pEditor, CUIRect View, void *pContext) } } } - ButtonBar.VSplitRight(30.0f, &ButtonBar, nullptr); - ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label); - static int s_AbortButton = 0; - if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, nullptr)) - return 1; return 0; }