@@ -325,11 +325,11 @@ namespace IGFD
325325
326326 }
327327
328- IGFD::FileExtentionInfos::FileExtentionInfos (const ImVec4& vColor, const std::string& vIcon, ImFont* f )
328+ IGFD::FileExtentionInfos::FileExtentionInfos (const ImVec4& vColor, const std::string& vIcon, ImFont* vFont )
329329 {
330330 color = vColor;
331331 icon = vIcon;
332- font = f ;
332+ font = vFont ;
333333 }
334334
335335 // ///////////////////////////////////////////////////////////////////////////////////
@@ -3680,6 +3680,50 @@ namespace IGFD
36803680 return false ;
36813681 }
36823682
3683+ void IGFD::FileDialog::prBeginFileColorIconStyle (std::shared_ptr<FileInfos> vFileInfos, bool & vOutShowColor, std::string& vOutStr, ImFont** vOutFont)
3684+ {
3685+ ImVec4 _color;
3686+ std::string _icon;
3687+
3688+ vOutFont = nullptr ;
3689+ vOutStr.clear ();
3690+ vOutShowColor = false ;
3691+
3692+ // Directory and Link infos override the one specified by extension
3693+
3694+ if (vFileInfos->fileType == ' d' )
3695+ vOutShowColor = prFileDialogInternal.puFilterManager .GetExtentionInfos (DIR_FILTER_STRING, &_color, &_icon, vOutFont);
3696+ else if (vFileInfos->fileType == ' l' )
3697+ vOutShowColor = prFileDialogInternal.puFilterManager .GetExtentionInfos (LINK_FILTER_STRING, &_color, &_icon, vOutFont);
3698+ // else
3699+ // vOutShowColor = prFileDialogInternal.puFilterManager.GetExtentionInfos(vFileInfos->fileExt, &_color, &_icon, vOutFont);
3700+
3701+ // prFileDialogInternal.puFilterManager.GetExtentionInfos(FILE_FILTER_STRING, &_color, &_icon, vOutFont);
3702+
3703+ if (!vOutShowColor)
3704+ vOutShowColor = prFileDialogInternal.puFilterManager .GetExtentionInfos (vFileInfos->fileExt , &_color, &_icon, vOutFont);
3705+
3706+ if (vOutShowColor && !_icon.empty ()) vOutStr = _icon;
3707+ else if (vFileInfos->fileType == ' d' ) vOutStr = dirEntryString;
3708+ else if (vFileInfos->fileType == ' l' ) vOutStr = linkEntryString;
3709+ else if (vFileInfos->fileType == ' f' ) vOutStr = fileEntryString;
3710+
3711+ vOutStr += " " + vFileInfos->fileName ;
3712+
3713+ if (vOutShowColor)
3714+ ImGui::PushStyleColor (ImGuiCol_Text, _color);
3715+ if (vOutFont)
3716+ ImGui::PushFont (*vOutFont);
3717+ }
3718+
3719+ void IGFD::FileDialog::prEndFileColorIconStyle (bool & vShowColor, ImFont* vFont)
3720+ {
3721+ if (vFont)
3722+ ImGui::PopFont ();
3723+ if (vShowColor)
3724+ ImGui::PopStyleColor ();
3725+ }
3726+
36833727 void IGFD::FileDialog::prDrawFileListView (ImVec2 vSize)
36843728 {
36853729 auto & fdi = prFileDialogInternal.puFileManager ;
@@ -3749,6 +3793,10 @@ namespace IGFD
37493793#endif // USE_CUSTOM_SORTING_ICON
37503794 if (!fdi.IsFilteredListEmpty ())
37513795 {
3796+ std::string _str;
3797+ ImFont* _font = nullptr ;
3798+ bool _showColor = false ;
3799+
37523800 prFileListClipper.Begin ((int )fdi.GetFilteredListSize (), ImGui::GetTextLineHeightWithSpacing ());
37533801 while (prFileListClipper.Step ())
37543802 {
@@ -3760,33 +3808,8 @@ namespace IGFD
37603808 if (!infos.use_count ())
37613809 continue ;
37623810
3763- ImVec4 c;
3764- std::string icon;
3765- ImFont* font = 0 ;
3766- // Directory and Link infos override the one specified by extension
3767- bool showColor;
3768- if (infos->fileType == ' d' )
3769- showColor = prFileDialogInternal.puFilterManager .GetExtentionInfos (DIR_FILTER_STRING, &c, &icon, &font);
3770- else if (infos->fileType == ' l' )
3771- showColor = prFileDialogInternal.puFilterManager .GetExtentionInfos (LINK_FILTER_STRING, &c, &icon, &font);
3772- else
3773- showColor = false ;
3774- if (!showColor)
3775- showColor = prFileDialogInternal.puFilterManager .GetExtentionInfos (infos->fileExt , &c, &icon, &font);
3776-
3777- if (showColor)
3778- ImGui::PushStyleColor (ImGuiCol_Text, c);
3779- if (font)
3780- ImGui::PushFont (font);
3781-
3782- std::string str;// = " " + infos->fileName;
3783- if (showColor && !icon.empty ()) str = icon;
3784- else if (infos->fileType == ' d' ) str = dirEntryString;
3785- else if (infos->fileType == ' l' ) str = linkEntryString;
3786- else if (infos->fileType == ' f' ) str = fileEntryString;
3787-
3788- str += " " + infos->fileName ;
3789-
3811+ prBeginFileColorIconStyle (infos, _showColor, _str, &_font);
3812+
37903813 bool selected = fdi.IsFileNameSelected (infos->fileName ); // found
37913814
37923815 ImGui::TableNextRow ();
@@ -3795,7 +3818,7 @@ namespace IGFD
37953818
37963819 if (ImGui::TableNextColumn ()) // file name
37973820 {
3798- needToBreakTheloop = prSelectableItem (i, infos, selected, str .c_str ());
3821+ needToBreakTheloop = prSelectableItem (i, infos, selected, _str .c_str ());
37993822 }
38003823 if (ImGui::TableNextColumn ()) // file type
38013824 {
@@ -3817,10 +3840,7 @@ namespace IGFD
38173840 ImGui::Text (" %s" , infos->fileModifDate .c_str ());
38183841 }
38193842
3820- if (font)
3821- ImGui::PopFont ();
3822- if (showColor)
3823- ImGui::PopStyleColor ();
3843+ prEndFileColorIconStyle (_showColor, _font);
38243844
38253845 if (needToBreakTheloop)
38263846 break ;
@@ -3924,6 +3944,10 @@ namespace IGFD
39243944#endif // USE_CUSTOM_SORTING_ICON
39253945 if (!fdi.IsFilteredListEmpty ())
39263946 {
3947+ std::string _str;
3948+ ImFont* _font = nullptr ;
3949+ bool _showColor = false ;
3950+
39273951 ImGuiContext& g = *GImGui;
39283952 const float itemHeight = ImMax (g.FontSize , DisplayMode_ThumbailsList_ImageHeight) + g.Style .ItemSpacing .y ;
39293953
@@ -3938,23 +3962,8 @@ namespace IGFD
39383962 if (!infos.use_count ())
39393963 continue ;
39403964
3941- ImVec4 c;
3942- std::string icon;
3943- bool showColor = prFileDialogInternal.puFilterManager .GetExtentionInfos (infos->fileExt , &c, &icon);
3944- if (showColor)
3945- ImGui::PushStyleColor (ImGuiCol_Text, c);
3965+ prBeginFileColorIconStyle (infos, _showColor, _str, &_font);
39463966
3947- std::string str;
3948- if (infos->fileType == ' d' ) str = dirEntryString;
3949- else if (infos->fileType == ' l' ) str = linkEntryString;
3950- else if (infos->fileType == ' f' )
3951- {
3952- if (showColor && !icon.empty ())
3953- str = icon;
3954- else
3955- str = fileEntryString;
3956- }
3957- str += " " + infos->fileName ;
39583967 bool selected = fdi.IsFileNameSelected (infos->fileName ); // found
39593968
39603969 ImGui::TableNextRow ();
@@ -3963,7 +3972,7 @@ namespace IGFD
39633972
39643973 if (ImGui::TableNextColumn ()) // file name
39653974 {
3966- needToBreakTheloop = prSelectableItem (i, infos, selected, str .c_str ());
3975+ needToBreakTheloop = prSelectableItem (i, infos, selected, _str .c_str ());
39673976 }
39683977 if (ImGui::TableNextColumn ()) // file type
39693978 {
@@ -3999,8 +4008,7 @@ namespace IGFD
39994008 }
40004009 }
40014010
4002- if (showColor)
4003- ImGui::PopStyleColor ();
4011+ prEndFileColorIconStyle (_showColor, _font);
40044012
40054013 if (needToBreakTheloop)
40064014 break ;
@@ -4702,30 +4710,30 @@ IMGUIFILEDIALOG_API void* IGFD_GetUserDatas(ImGuiFileDialog* vContext)
47024710}
47034711
47044712IMGUIFILEDIALOG_API void IGFD_SetExtentionInfos (ImGuiFileDialog* vContext,
4705- const char * vFilter, ImVec4 vColor, const char * vIcon)
4713+ const char * vFilter, ImVec4 vColor, const char * vIcon, ImFont* vFont )
47064714{
47074715 if (vContext)
47084716 {
4709- vContext->SetExtentionInfos (vFilter, vColor, vIcon);
4717+ vContext->SetExtentionInfos (vFilter, vColor, vIcon, vFont );
47104718 }
47114719}
47124720
47134721IMGUIFILEDIALOG_API void IGFD_SetExtentionInfos2 (ImGuiFileDialog* vContext,
4714- const char * vFilter, float vR, float vG, float vB, float vA, const char * vIcon)
4722+ const char * vFilter, float vR, float vG, float vB, float vA, const char * vIcon, ImFont* vFont )
47154723{
47164724 if (vContext)
47174725 {
4718- vContext->SetExtentionInfos (vFilter, ImVec4 (vR, vG, vB, vA), vIcon);
4726+ vContext->SetExtentionInfos (vFilter, ImVec4 (vR, vG, vB, vA), vIcon, vFont );
47194727 }
47204728}
47214729
47224730IMGUIFILEDIALOG_API bool IGFD_GetExtentionInfos (ImGuiFileDialog* vContext,
4723- const char * vFilter, ImVec4* vOutColor, char ** vOutIcon)
4731+ const char * vFilter, ImVec4* vOutColor, char ** vOutIcon, ImFont** vOutFont )
47244732{
47254733 if (vContext)
47264734 {
47274735 std::string icon;
4728- bool res = vContext->GetExtentionInfos (vFilter, vOutColor, &icon);
4736+ bool res = vContext->GetExtentionInfos (vFilter, vOutColor, &icon, vOutFont );
47294737 if (!icon.empty () && vOutIcon)
47304738 {
47314739 size_t siz = icon.size () + 1U ;
0 commit comments