Skip to content

Commit

Permalink
[ADD] : add virtual methods for draw column selectable and texts of a…
Browse files Browse the repository at this point in the history
… row (needed by ex for a two color theme)
  • Loading branch information
aiekick committed Feb 1, 2025
1 parent c66089f commit c383fd8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
44 changes: 27 additions & 17 deletions ImGuiFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4105,7 +4105,22 @@ bool IGFD::FileDialog::m_DrawFooter() {
return res;
}

void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt, ...) {
bool IGFD::FileDialog::m_Selectable(int vRowIdx, const char* vLabel, bool vSelected, ImGuiSelectableFlags vFlags, const ImVec2& vSizeArg) {
bool res = false;
#ifdef USE_EXPLORATION_BY_KEYS
bool flashed = m_BeginFlashItem((size_t)vRowIdx);
res = m_FlashableSelectable(vLabel, vSelected, vFlags, flashed, vSizeArg);
if (flashed) {
m_EndFlashItem();
}
#else // USE_EXPLORATION_BY_KEYS
(void)vRowIdx; // remove a warnings for unused var
res = ImGui::Selectable(vLabel, vSelected, vFlags, vSizeArg);
#endif // USE_EXPLORATION_BY_KEYS
return res;
}

void IGFD::FileDialog::m_SelectableItem(int vRowIdx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char* vFmt, ...) {
if (!vInfos.use_count()) return;

auto& fdi = m_FileDialogInternal.fileManager;
Expand All @@ -4123,18 +4138,7 @@ void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vIn
h = DisplayMode_ThumbailsList_ImageHeight;
}
#endif // USE_THUMBNAILS
#ifdef USE_EXPLORATION_BY_KEYS
bool flashed = m_BeginFlashItem((size_t)vidx);
bool res = m_FlashableSelectable(fdi.variadicBuffer, vSelected, selectableFlags, flashed, ImVec2(-1.0f, h));
if (flashed) {
m_EndFlashItem();
}
#else // USE_EXPLORATION_BY_KEYS
(void)vidx; // remove a warnings for unused var

bool res = ImGui::Selectable(fdi.variadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h));
#endif // USE_EXPLORATION_BY_KEYS
if (res) {
if (m_Selectable(vRowIdx, fdi.variadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h))) {
if (vInfos->fileType.isDir()) {
// nav system, selectable cause open directory or select directory
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) {
Expand Down Expand Up @@ -4203,6 +4207,10 @@ void IGFD::FileDialog::m_EndFileColorIconStyle(const bool vShowColor, ImFont* vF
if (vShowColor) ImGui::PopStyleColor();
}

void IGFD::FileDialog::m_drawColumnText(int /*vColIdx*/, const char* vLabel, bool /*vSelected*/, bool /*vHovered*/) {
ImGui::Text("%s", vLabel);
}

void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) {
auto& fdi = m_FileDialogInternal.fileManager;

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

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

column_id = 0;
_rowHovered = false;
if (ImGui::TableNextColumn()) { // file name
if (!infos_ptr->deviceInfos.empty()) {
_str += " " + infos_ptr->deviceInfos;
}
m_SelectableItem(i, infos_ptr, selected, _str.c_str());
_rowHovered = ImGui::IsItemHovered();
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
}
if (ImGui::TableNextColumn()) { // file type
ImGui::Text("%s", infos_ptr->fileExtLevels[0].c_str());
m_drawColumnText(column_id, infos_ptr->fileExtLevels[0].c_str(), selected, _rowHovered);
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
}
if (ImGui::TableNextColumn()) { // file size
if (!infos_ptr->fileType.isDir()) {
ImGui::Text("%s ", infos_ptr->formatedFileSize.c_str());
m_drawColumnText(column_id, infos_ptr->formatedFileSize.c_str(), selected, _rowHovered);
} else {
ImGui::TextUnformatted("");
}
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
}
if (ImGui::TableNextColumn()) { // file date + time
ImGui::Text("%s", infos_ptr->fileModifDate.c_str());
m_drawColumnText(column_id, infos_ptr->fileModifDate.c_str(), selected, _rowHovered);
m_DisplayFileInfosTooltip(i, column_id++, infos_ptr);
}

m_EndFileColorIconStyle(_showColor, _font);
}
}
Expand Down
24 changes: 6 additions & 18 deletions ImGuiFileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class IGFD_API FileInfos;
class IGFD_API FileDialogInternal;

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

#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
public:
#else
private:
#endif
static bool M_IsAValidCharExt(const char& c);
static bool M_IsAValidCharSuffix(const char& c);
static bool M_ExtractNumFromStringAtPos(const std::string& str, size_t& pos, double& vOutNum);
Expand Down Expand Up @@ -403,11 +400,8 @@ class IGFD_API FilterInfos {
};

class IGFD_API FilterManager {
#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
public:
#else
friend class TestFilterManager;
private:
#endif
std::vector<FilterInfos> m_ParsedFilters;
std::unordered_map<IGFD_FileStyleFlags, std::unordered_map<std::string, std::shared_ptr<FileStyle> > > m_FilesStyle; // file infos for file
// extention only
Expand Down Expand Up @@ -535,6 +529,7 @@ class IFileSystem {
};

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

#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
public:
#else
private:
#endif
std::string m_CurrentPath; // current path (to be decomposed in m_CurrentPathDecomposition
std::vector<std::string> m_CurrentPathDecomposition; // part words
std::vector<std::shared_ptr<FileInfos> > m_FileList; // base container
Expand Down Expand Up @@ -593,11 +584,7 @@ class IGFD_API FileManager {

std::string fsRoot;

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

#ifdef USE_THUMBNAILS
Expand Down

0 comments on commit c383fd8

Please sign in to comment.