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.
This commit is contained in:
Robert Müller 2023-04-01 13:23:52 +02:00
parent 5cfecdb42f
commit 141571cc55
2 changed files with 25 additions and 25 deletions

View file

@ -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);
}

View file

@ -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;
}