Skip to content

Commit 7abfc65

Browse files
authored
Merge pull request #66 from teknos293/Lib_Only
Lib only
2 parents 7cfed54 + 4f0fe30 commit 7abfc65

2 files changed

Lines changed: 45 additions & 23 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,11 @@ namespace IGFD
325325

326326
}
327327

328-
IGFD::FileExtentionInfos::FileExtentionInfos(const ImVec4& vColor, const std::string& vIcon)
328+
IGFD::FileExtentionInfos::FileExtentionInfos(const ImVec4& vColor, const std::string& vIcon, ImFont* f)
329329
{
330330
color = vColor;
331331
icon = vIcon;
332+
font = f;
332333
}
333334

334335
/////////////////////////////////////////////////////////////////////////////////////
@@ -824,12 +825,12 @@ namespace IGFD
824825
prFileExtentionInfos[vFilter] = vInfos;
825826
}
826827

827-
void IGFD::FilterManager::SetExtentionInfos(const std::string& vFilter, const ImVec4& vColor, const std::string& vIcon)
828+
void IGFD::FilterManager::SetExtentionInfos(const std::string& vFilter, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
828829
{
829-
prFileExtentionInfos[vFilter] = FileExtentionInfos(vColor, vIcon);
830+
prFileExtentionInfos[vFilter] = FileExtentionInfos(vColor, vIcon, vFont);
830831
}
831832

832-
bool IGFD::FilterManager::GetExtentionInfos(const std::string& vFilter, ImVec4* vOutColor, std::string* vOutIcon)
833+
bool IGFD::FilterManager::GetExtentionInfos(const std::string& vFilter, ImVec4* vOutColor, std::string* vOutIcon, ImFont **vOutFont)
833834
{
834835
if (vOutColor)
835836
{
@@ -840,6 +841,10 @@ namespace IGFD
840841
{
841842
*vOutIcon = prFileExtentionInfos[vFilter].icon;
842843
}
844+
if (vOutFont)
845+
{
846+
*vOutFont = prFileExtentionInfos[vFilter].font;
847+
}
843848
return true;
844849
}
845850
}
@@ -3757,20 +3762,29 @@ namespace IGFD
37573762

37583763
ImVec4 c;
37593764
std::string icon;
3760-
bool showColor = prFileDialogInternal.puFilterManager.GetExtentionInfos(infos->fileExt, &c, &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+
37613777
if (showColor)
37623778
ImGui::PushStyleColor(ImGuiCol_Text, c);
3779+
if (font)
3780+
ImGui::PushFont(font);
37633781

37643782
std::string str;// = " " + infos->fileName;
3765-
if (infos->fileType == 'd') str = dirEntryString;
3783+
if (showColor && !icon.empty()) str = icon;
3784+
else if (infos->fileType == 'd') str = dirEntryString;
37663785
else if (infos->fileType == 'l') str = linkEntryString;
3767-
else if (infos->fileType == 'f')
3768-
{
3769-
if (showColor && !icon.empty())
3770-
str = icon;
3771-
else
3772-
str = fileEntryString;
3773-
}
3786+
else if (infos->fileType == 'f') str = fileEntryString;
3787+
37743788
str += " " + infos->fileName;
37753789

37763790
bool selected = fdi.IsFileNameSelected(infos->fileName); // found
@@ -3803,6 +3817,8 @@ namespace IGFD
38033817
ImGui::Text("%s", infos->fileModifDate.c_str());
38043818
}
38053819

3820+
if (font)
3821+
ImGui::PopFont();
38063822
if (showColor)
38073823
ImGui::PopStyleColor();
38083824

@@ -4123,14 +4139,14 @@ namespace IGFD
41234139
prFileDialogInternal.puFilterManager.SetExtentionInfos(vFilter, vInfos);
41244140
}
41254141

4126-
void IGFD::FileDialog::SetExtentionInfos(const std::string& vFilter, const ImVec4& vColor, const std::string& vIcon)
4142+
void IGFD::FileDialog::SetExtentionInfos(const std::string& vFilter, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
41274143
{
4128-
prFileDialogInternal.puFilterManager.SetExtentionInfos(vFilter, vColor, vIcon);
4144+
prFileDialogInternal.puFilterManager.SetExtentionInfos(vFilter, vColor, vIcon, vFont);
41294145
}
41304146

4131-
bool IGFD::FileDialog::GetExtentionInfos(const std::string& vFilter, ImVec4* vOutColor, std::string* vOutIcon)
4147+
bool IGFD::FileDialog::GetExtentionInfos(const std::string& vFilter, ImVec4* vOutColor, std::string* vOutIcon, ImFont **vOutFont)
41324148
{
4133-
return prFileDialogInternal.puFilterManager.GetExtentionInfos(vFilter, vOutColor, vOutIcon);
4149+
return prFileDialogInternal.puFilterManager.GetExtentionInfos(vFilter, vOutColor, vOutIcon, vOutFont);
41344150
}
41354151

41364152
void IGFD::FileDialog::ClearExtentionInfos()

ImGuiFileDialog.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ namespace IGFD
625625
#define MAX_PATH_BUFFER_SIZE 1024
626626
#endif // MAX_PATH_BUFFER_SIZE
627627

628+
#define DIR_FILTER_STRING "\0d"
629+
#define LINK_FILTER_STRING "\0l"
630+
628631
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
629632
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
630633
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -656,10 +659,11 @@ namespace IGFD
656659
public:
657660
ImVec4 color = ImVec4(0, 0, 0, 0);
658661
std::string icon;
662+
ImFont* font = nullptr;
659663

660664
public:
661665
FileExtentionInfos();
662-
FileExtentionInfos(const ImVec4& vColor, const std::string& vIcon = "");
666+
FileExtentionInfos(const ImVec4& vColor, const std::string& vIcon = "", ImFont *f=nullptr);
663667
};
664668

665669
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -728,13 +732,13 @@ namespace IGFD
728732
void ParseFilters(const char* vFilters); // Parse filter syntax, detect and parse filter collection
729733
void SetSelectedFilterWithExt(const std::string& vFilter); // Select filter
730734
void SetExtentionInfos(const std::string& vFilter, const FileExtentionInfos& vInfos); // link filter to ExtentionInfos
731-
void SetExtentionInfos(const std::string& vFilter, const ImVec4& vColor, const std::string& vIcon); // link filter to Color and Icon
732-
bool GetExtentionInfos(const std::string& vFilter, ImVec4* vOutColor, std::string* vOutIcon); // get Color and Icon for Filter
735+
void SetExtentionInfos(const std::string& vFilter, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont);// link filter to Color and Icon and Font
736+
bool GetExtentionInfos(const std::string& vFilter, ImVec4* vOutColor, std::string* vOutIcon, ImFont **vOutFont); // get Color and Icon for Filter
733737
void ClearExtentionInfos(); // clear prFileExtentionInfos
734738
bool IsCoveredByFilters(const std::string& vTag) const; // check if current file extention (vTag) is covered by current filter
735739
bool DrawFilterComboBox(FileDialogInternal& vFileDialogInternal); // draw the filter combobox
736740
FilterInfosStruct GetSelectedFilter(); // get the current selected filter
737-
std::string ReplaceExtentionWithCurrentFilter(const std::string vFile) const; // replace the extention of the current file by the selected filter
741+
std::string ReplaceExtentionWithCurrentFilter(const std::string vFile) const; // replace the extention of the current file by the selected filter
738742
void SetDefaultFilterIfNotDefined(); // define the first filter if no filter is selected
739743
};
740744

@@ -1204,11 +1208,13 @@ namespace IGFD
12041208
void SetExtentionInfos( // SetExtention datas for have custom display of particular file type
12051209
const std::string& vFilter, // extention filter to tune
12061210
const ImVec4& vColor, // wanted color for the display of the file with extention filter
1207-
const std::string& vIcon = ""); // wanted text or icon of the file with extention filter
1211+
const std::string& vIcon = "", // wanted text or icon of the file with extention filter
1212+
ImFont *vFont = nullptr); // wantes font
12081213
bool GetExtentionInfos( // GetExtention datas. return true is extention exist
12091214
const std::string& vFilter, // extention filter (same as used in SetExtentionInfos)
12101215
ImVec4* vOutColor, // color to retrieve
1211-
std::string* vOutIcon = 0); // icon or text to retrieve
1216+
std::string* vOutIcon = nullptr, // icon or text to retrieve
1217+
ImFont** vOutFont = nullptr); // font to retreive
12121218
void ClearExtentionInfos(); // clear extentions setttings
12131219

12141220
void SetLocales( // set locales to use before and after the dialog display

0 commit comments

Comments
 (0)