@@ -128,9 +128,18 @@ namespace IGFD
128128#ifndef okButtonString
129129#define okButtonString " OK"
130130#endif // okButtonString
131+ #ifndef okButtonWidth
132+ #define okButtonWidth 0 .0f
133+ #endif // okButtonWidth
131134#ifndef cancelButtonString
132135#define cancelButtonString " Cancel"
133136#endif // cancelButtonString
137+ #ifndef cancelButtonWidth
138+ #define cancelButtonWidth 0 .0f
139+ #endif // cancelButtonWidth
140+ #ifndef okCancelButtonAlignement
141+ #define okCancelButtonAlignement 0 .0f
142+ #endif // okCancelButtonAlignement
134143#ifndef resetButtonString
135144#define resetButtonString " R"
136145#endif // resetButtonString
@@ -331,6 +340,15 @@ namespace IGFD
331340 }
332341#endif
333342
343+ inline void imAlignForWidth (float width, float alignment = 0 .5f )
344+ {
345+ ImGuiStyle& style = ImGui::GetStyle ();
346+ float avail = ImGui::GetContentRegionAvail ().x ;
347+ float off = (avail - width) * alignment;
348+ if (off > 0 .0f )
349+ ImGui::SetCursorPosX (ImGui::GetCursorPosX () + off);
350+ }
351+
334352 // ///////////////////////////////////////////////////////////////////////////////////
335353 // // FILE EXTENTIONS INFOS //////////////////////////////////////////////////////////
336354 // ///////////////////////////////////////////////////////////////////////////////////
@@ -3845,6 +3863,43 @@ namespace IGFD
38453863 }
38463864 }
38473865
3866+ bool IGFD::FileDialog::prDrawValidationButtons ()
3867+ {
3868+ bool res = false ;
3869+
3870+ auto & fdFile = prFileDialogInternal.puFileManager ;
3871+
3872+ ImGui::SetCursorPosX (ImGui::GetCursorPosX () + (ImGui::GetContentRegionAvail ().x - prOkCancelButtonWidth) * okCancelButtonAlignement);
3873+
3874+ ImGui::BeginGroup ();
3875+
3876+ // OK Button
3877+ if (prFileDialogInternal.puCanWeContinue && strlen (fdFile.puFileNameBuffer ))
3878+ {
3879+ if (IMGUI_BUTTON (okButtonString " ##validationdialog" , ImVec2 (okButtonWidth, 0 .0f )) || prFileDialogInternal.puIsOk )
3880+ {
3881+ prFileDialogInternal.puIsOk = true ;
3882+ res = true ;
3883+ }
3884+
3885+ ImGui::SameLine ();
3886+ }
3887+
3888+ // Cancel Button
3889+ if (IMGUI_BUTTON (cancelButtonString " ##validationdialog" , ImVec2 (cancelButtonWidth, 0 .0f )) ||
3890+ prFileDialogInternal.puNeedToExitDialog ) // dialog exit asked
3891+ {
3892+ prFileDialogInternal.puIsOk = false ;
3893+ res = true ;
3894+ }
3895+
3896+ ImGui::EndGroup ();
3897+
3898+ prOkCancelButtonWidth = ImGui::GetItemRectSize ().x ;
3899+
3900+ return res;
3901+ }
3902+
38483903 bool IGFD::FileDialog::prDrawFooter ()
38493904 {
38503905 auto & fdFile = prFileDialogInternal.puFileManager ;
@@ -3891,35 +3946,17 @@ namespace IGFD
38913946
38923947 bool res = false ;
38933948
3894- // OK Button
3895- if (prFileDialogInternal.puCanWeContinue && strlen (fdFile.puFileNameBuffer ))
3896- {
3897- if (IMGUI_BUTTON (okButtonString " ##validationdialog" ) || prFileDialogInternal.puIsOk )
3898- {
3899- prFileDialogInternal.puIsOk = true ;
3900- res = true ;
3901- }
3902-
3903- ImGui::SameLine ();
3904- }
3905-
3906- // Cancel Button
3907- if (IMGUI_BUTTON (cancelButtonString " ##validationdialog" ) ||
3908- prFileDialogInternal.puNeedToExitDialog ) // dialog exit asked
3909- {
3910- prFileDialogInternal.puIsOk = false ;
3911- res = true ;
3912- }
3949+ res = prDrawValidationButtons ();
39133950
39143951 prFileDialogInternal.puFooterHeight = ImGui::GetCursorPosY () - posY;
39153952
39163953 return res;
39173954 }
39183955
3919- bool IGFD::FileDialog::prSelectableItem (int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char * vFmt, ...)
3956+ void IGFD::FileDialog::prSelectableItem (int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char * vFmt, ...)
39203957 {
39213958 if (!vInfos.use_count ())
3922- return false ;
3959+ return ;
39233960
39243961 auto & fdi = prFileDialogInternal.puFileManager ;
39253962
@@ -3974,8 +4011,6 @@ namespace IGFD
39744011 fdi.SelectFileName (prFileDialogInternal, vInfos);
39754012 }
39764013 }
3977-
3978- // return true; // needToBreakTheloop
39794014 }
39804015 else
39814016 {
@@ -3987,8 +4022,6 @@ namespace IGFD
39874022 }
39884023 }
39894024 }
3990-
3991- return false ;
39924025 }
39934026
39944027 void IGFD::FileDialog::prBeginFileColorIconStyle (std::shared_ptr<FileInfos> vFileInfos, bool & vOutShowColor, std::string& vOutStr, ImFont** vOutFont)
@@ -4164,11 +4197,9 @@ namespace IGFD
41644197
41654198 ImGui::TableNextRow ();
41664199
4167- bool needToBreakTheloop = false ;
4168-
41694200 if (ImGui::TableNextColumn ()) // file name
41704201 {
4171- needToBreakTheloop = prSelectableItem (i, infos, selected, _str.c_str ());
4202+ prSelectableItem (i, infos, selected, _str.c_str ());
41724203 }
41734204 if (ImGui::TableNextColumn ()) // file type
41744205 {
@@ -4191,9 +4222,6 @@ namespace IGFD
41914222 }
41924223
41934224 prEndFileColorIconStyle (_showColor, _font);
4194-
4195- if (needToBreakTheloop)
4196- break ;
41974225 }
41984226 }
41994227 prFileListClipper.End ();
@@ -4381,11 +4409,9 @@ namespace IGFD
43814409
43824410 ImGui::TableNextRow ();
43834411
4384- bool needToBreakTheloop = false ;
4385-
43864412 if (ImGui::TableNextColumn ()) // file name
43874413 {
4388- needToBreakTheloop = prSelectableItem (i, infos, selected, _str.c_str ());
4414+ prSelectableItem (i, infos, selected, _str.c_str ());
43894415 }
43904416 if (ImGui::TableNextColumn ()) // file type
43914417 {
@@ -4424,9 +4450,6 @@ namespace IGFD
44244450 }
44254451
44264452 prEndFileColorIconStyle (_showColor, _font);
4427-
4428- if (needToBreakTheloop)
4429- break ;
44304453 }
44314454 }
44324455 prFileListClipper.End ();
0 commit comments