Skip to content

Commit 31ab88c

Browse files
committed
[INC] : inc version number
[RFR] : a bit of refactor and simplification
1 parent 7abfc65 commit 31ab88c

2 files changed

Lines changed: 102 additions & 69 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -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

47044712
IMGUIFILEDIALOG_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

47134721
IMGUIFILEDIALOG_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

47224730
IMGUIFILEDIALOG_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;

ImGuiFileDialog.h

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,18 @@ ImGuiFontStudio is using also ImGuiFileDialog.
556556
#ifndef IMGUIFILEDIALOG_H
557557
#define IMGUIFILEDIALOG_H
558558

559-
#define IMGUIFILEDIALOG_VERSION "v0.6.2"
559+
#define IMGUIFILEDIALOG_VERSION "v0.6.3"
560560

561561
#ifndef CUSTOM_IMGUIFILEDIALOG_CONFIG
562562
#include "ImGuiFileDialogConfig.h"
563563
#else // CUSTOM_IMGUIFILEDIALOG_CONFIG
564564
#include CUSTOM_IMGUIFILEDIALOG_CONFIG
565565
#endif // CUSTOM_IMGUIFILEDIALOG_CONFIG
566566

567+
#define DIR_FILTER_STRING "d"
568+
#define LINK_FILTER_STRING "l"
569+
#define FILE_FILTER_STRING "f"
570+
567571
typedef int ImGuiFileDialogFlags; // -> enum ImGuiFileDialogFlags_
568572
enum ImGuiFileDialogFlags_
569573
{
@@ -625,9 +629,6 @@ namespace IGFD
625629
#define MAX_PATH_BUFFER_SIZE 1024
626630
#endif // MAX_PATH_BUFFER_SIZE
627631

628-
#define DIR_FILTER_STRING "\0d"
629-
#define LINK_FILTER_STRING "\0l"
630-
631632
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
632633
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
633634
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -663,7 +664,7 @@ namespace IGFD
663664

664665
public:
665666
FileExtentionInfos();
666-
FileExtentionInfos(const ImVec4& vColor, const std::string& vIcon = "", ImFont *f=nullptr);
667+
FileExtentionInfos(const ImVec4& vColor, const std::string& vIcon = "", ImFont* vFont = nullptr);
667668
};
668669

669670
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -732,8 +733,16 @@ namespace IGFD
732733
void ParseFilters(const char* vFilters); // Parse filter syntax, detect and parse filter collection
733734
void SetSelectedFilterWithExt(const std::string& vFilter); // Select filter
734735
void SetExtentionInfos(const std::string& vFilter, const FileExtentionInfos& vInfos); // link filter to ExtentionInfos
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
736+
void SetExtentionInfos(
737+
const std::string& vFilter,
738+
const ImVec4& vColor,
739+
const std::string& vIcon,
740+
ImFont* vFont); // link filter to Color and Icon and Font
741+
bool GetExtentionInfos(
742+
const std::string& vFilter,
743+
ImVec4* vOutColor,
744+
std::string* vOutIcon,
745+
ImFont** vOutFont); // get Color and Icon for Filter
737746
void ClearExtentionInfos(); // clear prFileExtentionInfos
738747
bool IsCoveredByFilters(const std::string& vTag) const; // check if current file extention (vTag) is covered by current filter
739748
bool DrawFilterComboBox(FileDialogInternal& vFileDialogInternal); // draw the filter combobox
@@ -1248,6 +1257,19 @@ namespace IGFD
12481257
virtual void prDrawThumbnailsListView(ImVec2 vSize); // draw file list view with small thumbnails on the same line
12491258
virtual void prDrawThumbnailsGridView(ImVec2 vSize); // draw a grid of small thumbnails
12501259
#endif
1260+
1261+
// to be called only by these function and theirs overrides
1262+
// - prDrawFileListView
1263+
// - prDrawThumbnailsListView
1264+
// - prDrawThumbnailsGridView
1265+
void prBeginFileColorIconStyle(
1266+
std::shared_ptr<FileInfos> vFileInfos,
1267+
bool& vOutShowColor,
1268+
std::string& vOutStr,
1269+
ImFont** vOutFont); // begin style apply of filter with color an icon if any
1270+
void prEndFileColorIconStyle(
1271+
bool& vShowColor,
1272+
ImFont* vFont); // end style apply of filter
12511273
};
12521274
}
12531275

@@ -1458,19 +1480,22 @@ IMGUIFILEDIALOG_API void IGFD_SetExtentionInfos( // SetExtention datas for hav
14581480
ImGuiFileDialog* vContext, // ImGuiFileDialog context
14591481
const char* vFilter, // extention filter to tune
14601482
ImVec4 vColor, // wanted color for the display of the file with extention filter
1461-
const char* vIconText); // wanted text or icon of the file with extention filter (can be sued with font icon)
1483+
const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon)
1484+
ImFont* vFont); // wanted font pointer
14621485

14631486
IMGUIFILEDIALOG_API void IGFD_SetExtentionInfos2( // SetExtention datas for have custom display of particular file type
14641487
ImGuiFileDialog* vContext, // ImGuiFileDialog context
14651488
const char* vFilter, // extention filter to tune
14661489
float vR, float vG, float vB, float vA, // wanted color channels RGBA for the display of the file with extention filter
1467-
const char* vIconText); // wanted text or icon of the file with extention filter (can be sued with font icon)
1490+
const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon)
1491+
ImFont* vFont); // wanted font pointer
14681492

14691493
IMGUIFILEDIALOG_API bool IGFD_GetExtentionInfos(
14701494
ImGuiFileDialog* vContext, // ImGuiFileDialog context
14711495
const char* vFilter, // extention filter (same as used in SetExtentionInfos)
14721496
ImVec4* vOutColor, // color to retrieve
1473-
char** vOutIconText); // icon or text to retrieve
1497+
char** vOutIconText, // icon or text to retrieve
1498+
ImFont** vOutFont); // font pointer to retrived
14741499

14751500
IMGUIFILEDIALOG_API void IGFD_ClearExtentionInfos( // clear extentions setttings
14761501
ImGuiFileDialog* vContext); // ImGuiFileDialog context

0 commit comments

Comments
 (0)