Skip to content

Commit c383fd8

Browse files
committed
[ADD] : add virtual methods for draw column selectable and texts of a row (needed by ex for a two color theme)
1 parent c66089f commit c383fd8

2 files changed

Lines changed: 33 additions & 35 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4105,7 +4105,22 @@ bool IGFD::FileDialog::m_DrawFooter() {
41054105
return res;
41064106
}
41074107

4108-
void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt, ...) {
4108+
bool IGFD::FileDialog::m_Selectable(int vRowIdx, const char* vLabel, bool vSelected, ImGuiSelectableFlags vFlags, const ImVec2& vSizeArg) {
4109+
bool res = false;
4110+
#ifdef USE_EXPLORATION_BY_KEYS
4111+
bool flashed = m_BeginFlashItem((size_t)vRowIdx);
4112+
res = m_FlashableSelectable(vLabel, vSelected, vFlags, flashed, vSizeArg);
4113+
if (flashed) {
4114+
m_EndFlashItem();
4115+
}
4116+
#else // USE_EXPLORATION_BY_KEYS
4117+
(void)vRowIdx; // remove a warnings for unused var
4118+
res = ImGui::Selectable(vLabel, vSelected, vFlags, vSizeArg);
4119+
#endif // USE_EXPLORATION_BY_KEYS
4120+
return res;
4121+
}
4122+
4123+
void IGFD::FileDialog::m_SelectableItem(int vRowIdx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt, ...) {
41094124
if (!vInfos.use_count()) return;
41104125

41114126
auto& fdi = m_FileDialogInternal.fileManager;
@@ -4123,18 +4138,7 @@ void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vIn
41234138
h = DisplayMode_ThumbailsList_ImageHeight;
41244139
}
41254140
#endif // USE_THUMBNAILS
4126-
#ifdef USE_EXPLORATION_BY_KEYS
4127-
bool flashed = m_BeginFlashItem((size_t)vidx);
4128-
bool res = m_FlashableSelectable(fdi.variadicBuffer, vSelected, selectableFlags, flashed, ImVec2(-1.0f, h));
4129-
if (flashed) {
4130-
m_EndFlashItem();
4131-
}
4132-
#else // USE_EXPLORATION_BY_KEYS
4133-
(void)vidx; // remove a warnings for unused var
4134-
4135-
bool res = ImGui::Selectable(fdi.variadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h));
4136-
#endif // USE_EXPLORATION_BY_KEYS
4137-
if (res) {
4141+
if (m_Selectable(vRowIdx, fdi.variadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h))) {
41384142
if (vInfos->fileType.isDir()) {
41394143
// nav system, selectable cause open directory or select directory
41404144
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) {
@@ -4203,6 +4207,10 @@ void IGFD::FileDialog::m_EndFileColorIconStyle(const bool vShowColor, ImFont* vF
42034207
if (vShowColor) ImGui::PopStyleColor();
42044208
}
42054209

4210+
void IGFD::FileDialog::m_drawColumnText(int /*vColIdx*/, const char* vLabel, bool /*vSelected*/, bool /*vHovered*/) {
4211+
ImGui::Text("%s", vLabel);
4212+
}
4213+
42064214
void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) {
42074215
auto& fdi = m_FileDialogInternal.fileManager;
42084216

@@ -4310,6 +4318,7 @@ void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) {
43104318
bool _showColor = false;
43114319

43124320
int column_id = 0;
4321+
bool _rowHovered = false;
43134322
m_FileListClipper.Begin((int)fdi.GetFilteredListSize(), ImGui::GetTextLineHeightWithSpacing());
43144323
while (m_FileListClipper.Step()) {
43154324
for (int i = m_FileListClipper.DisplayStart; i < m_FileListClipper.DisplayEnd; i++) {
@@ -4325,30 +4334,31 @@ void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) {
43254334
ImGui::TableNextRow();
43264335

43274336
column_id = 0;
4337+
_rowHovered = false;
43284338
if (ImGui::TableNextColumn()) { // file name
43294339
if (!infos_ptr->deviceInfos.empty()) {
43304340
_str += " " + infos_ptr->deviceInfos;
43314341
}
43324342
m_SelectableItem(i, infos_ptr, selected, _str.c_str());
4343+
_rowHovered = ImGui::IsItemHovered();
43334344
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
43344345
}
43354346
if (ImGui::TableNextColumn()) { // file type
4336-
ImGui::Text("%s", infos_ptr->fileExtLevels[0].c_str());
4347+
m_drawColumnText(column_id, infos_ptr->fileExtLevels[0].c_str(), selected, _rowHovered);
43374348
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
43384349
}
43394350
if (ImGui::TableNextColumn()) { // file size
43404351
if (!infos_ptr->fileType.isDir()) {
4341-
ImGui::Text("%s ", infos_ptr->formatedFileSize.c_str());
4352+
m_drawColumnText(column_id, infos_ptr->formatedFileSize.c_str(), selected, _rowHovered);
43424353
} else {
43434354
ImGui::TextUnformatted("");
43444355
}
43454356
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
43464357
}
43474358
if (ImGui::TableNextColumn()) { // file date + time
4348-
ImGui::Text("%s", infos_ptr->fileModifDate.c_str());
4359+
m_drawColumnText(column_id, infos_ptr->fileModifDate.c_str(), selected, _rowHovered);
43494360
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
43504361
}
4351-
43524362
m_EndFileColorIconStyle(_showColor, _font);
43534363
}
43544364
}

ImGuiFileDialog.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ class IGFD_API FileInfos;
313313
class IGFD_API FileDialogInternal;
314314

315315
class IGFD_API Utils {
316+
friend class TestUtils;
316317
public:
317318
struct PathStruct {
318319
std::string path;
@@ -339,11 +340,7 @@ class IGFD_API Utils {
339340
static std::string FormatFileSize(size_t vByteSize); // format file size field
340341
static bool NaturalCompare(const std::string& vA, const std::string& vB, bool vInsensitiveCase, bool vDescending); // natural sorting
341342

342-
#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
343-
public:
344-
#else
345343
private:
346-
#endif
347344
static bool M_IsAValidCharExt(const char& c);
348345
static bool M_IsAValidCharSuffix(const char& c);
349346
static bool M_ExtractNumFromStringAtPos(const std::string& str, size_t& pos, double& vOutNum);
@@ -403,11 +400,8 @@ class IGFD_API FilterInfos {
403400
};
404401

405402
class IGFD_API FilterManager {
406-
#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
407-
public:
408-
#else
403+
friend class TestFilterManager;
409404
private:
410-
#endif
411405
std::vector<FilterInfos> m_ParsedFilters;
412406
std::unordered_map<IGFD_FileStyleFlags, std::unordered_map<std::string, std::shared_ptr<FileStyle> > > m_FilesStyle; // file infos for file
413407
// extention only
@@ -535,6 +529,7 @@ class IFileSystem {
535529
};
536530

537531
class IGFD_API FileManager {
532+
friend class TestFileManager;
538533
public: // types
539534
enum class SortingFieldEnum { // sorting for filetering of the file lsit
540535
FIELD_NONE = 0, // no sorting reference, result indetermined haha..
@@ -545,11 +540,7 @@ class IGFD_API FileManager {
545540
FIELD_THUMBNAILS, // sorted by thumbnails (comparaison by width then by height)
546541
};
547542

548-
#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
549-
public:
550-
#else
551543
private:
552-
#endif
553544
std::string m_CurrentPath; // current path (to be decomposed in m_CurrentPathDecomposition
554545
std::vector<std::string> m_CurrentPathDecomposition; // part words
555546
std::vector<std::shared_ptr<FileInfos> > m_FileList; // base container
@@ -593,11 +584,7 @@ class IGFD_API FileManager {
593584

594585
std::string fsRoot;
595586

596-
#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
597-
public:
598-
#else
599587
private:
600-
#endif
601588
static void m_CompleteFileInfos(const std::shared_ptr<FileInfos>& vInfos); // set time and date infos of a file (detail view mode)
602589
void m_RemoveFileNameInSelection(const std::string& vFileName); // selection : remove a file name
603590
void m_AddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName); // selection : add a file name
@@ -993,8 +980,9 @@ class IGFD_API FileDialog : public PlacesFeature, public KeyExplorerFeature, pub
993980
virtual bool m_DrawOkButton(); // draw ok button
994981
virtual bool m_DrawCancelButton(); // draw cancel button
995982
virtual void m_DrawSidePane(float vHeight); // draw side pane
996-
virtual void m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt,
997-
...); // draw a custom selectable behavior item
983+
virtual bool m_Selectable(int vRowIdx, const char* vLabel, bool vSelected, ImGuiSelectableFlags vFlags, const ImVec2& vSizeArg);
984+
virtual void m_SelectableItem(int vRowIdx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt, ...); // draw a custom selectable behavior item
985+
virtual void m_drawColumnText(int vColIdx, const char* vLabel, bool vSelected, bool vHovered);
998986
virtual void m_DrawFileListView(ImVec2 vSize); // draw file list view (default mode)
999987

1000988
#ifdef USE_THUMBNAILS

0 commit comments

Comments
 (0)