Skip to content

Commit beb5507

Browse files
committed
[ADD] : can invert the ok and cancel buttons (with the define invertOkAndCancelButtons)
1 parent 78f3df4 commit beb5507

3 files changed

Lines changed: 42 additions & 14 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ namespace IGFD
140140
#ifndef okCancelButtonAlignement
141141
#define okCancelButtonAlignement 0.0f
142142
#endif // okCancelButtonAlignement
143+
#ifndef invertOkAndCancelButtons
144+
#define invertOkAndCancelButtons false
145+
#endif // invertOkAndCancelButtons
143146
#ifndef resetButtonString
144147
#define resetButtonString "R"
145148
#endif // resetButtonString
@@ -3863,34 +3866,56 @@ namespace IGFD
38633866
}
38643867
}
38653868

3866-
bool IGFD::FileDialog::prDrawValidationButtons()
3869+
bool IGFD::FileDialog::prDrawOkButton()
38673870
{
3868-
bool res = false;
3869-
38703871
auto& fdFile = prFileDialogInternal.puFileManager;
3871-
3872-
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x - prOkCancelButtonWidth) * okCancelButtonAlignement);
3873-
3874-
ImGui::BeginGroup();
3875-
3876-
// OK Button
38773872
if (prFileDialogInternal.puCanWeContinue && strlen(fdFile.puFileNameBuffer))
38783873
{
38793874
if (IMGUI_BUTTON(okButtonString "##validationdialog", ImVec2(okButtonWidth, 0.0f)) || prFileDialogInternal.puIsOk)
38803875
{
38813876
prFileDialogInternal.puIsOk = true;
3882-
res = true;
3877+
return true;
38833878
}
38843879

3885-
ImGui::SameLine();
3880+
if (!invertOkAndCancelButtons)
3881+
ImGui::SameLine();
38863882
}
38873883

3888-
// Cancel Button
3884+
return false;
3885+
}
3886+
3887+
bool IGFD::FileDialog::prDrawCancelButton()
3888+
{
38893889
if (IMGUI_BUTTON(cancelButtonString "##validationdialog", ImVec2(cancelButtonWidth, 0.0f)) ||
38903890
prFileDialogInternal.puNeedToExitDialog) // dialog exit asked
38913891
{
38923892
prFileDialogInternal.puIsOk = false;
3893-
res = true;
3893+
return true;
3894+
}
3895+
3896+
if (invertOkAndCancelButtons)
3897+
ImGui::SameLine();
3898+
3899+
return false;
3900+
}
3901+
3902+
bool IGFD::FileDialog::prDrawValidationButtons()
3903+
{
3904+
bool res = false;
3905+
3906+
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x - prOkCancelButtonWidth) * okCancelButtonAlignement);
3907+
3908+
ImGui::BeginGroup();
3909+
3910+
if (invertOkAndCancelButtons)
3911+
{
3912+
prDrawCancelButton();
3913+
prDrawOkButton();
3914+
}
3915+
else
3916+
{
3917+
prDrawOkButton();
3918+
prDrawCancelButton();
38943919
}
38953920

38963921
ImGui::EndGroup();

ImGuiFileDialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,8 @@ namespace IGFD
13311331

13321332
// widgets components
13331333
virtual bool prDrawValidationButtons(); // ok, cancel buttons
1334+
virtual bool prDrawOkButton();
1335+
virtual bool prDrawCancelButton();
13341336
virtual void prDrawSidePane(float vHeight); // draw side pane
13351337
virtual void prSelectableItem(int vidx,
13361338
std::shared_ptr<FileInfos> vInfos,

ImGuiFileDialogConfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@
7373

7474
//Validation buttons
7575
//#define okButtonString " OK"
76-
//#define cancelButtonString " Cancel"
7776
//#define okButtonWidth 0.0f
77+
//#define cancelButtonString " Cancel"
7878
//#define cancelButtonWidth 0.0f
7979
//alignement [0:1], 0.0 is left, 0.5 middle, 1.0 right, and other ratios
8080
//#define okCancelButtonAlignement 0.0f
81+
//#define invertOkAndCancelButtons false
8182

8283
// DateTimeFormat
8384
// see strftime functionin <ctime> for customize

0 commit comments

Comments
 (0)