Skip to content

Commit

Permalink
[ADD] : add the feature #157, for display a custom tooltip for a file…
Browse files Browse the repository at this point in the history
… in a column
  • Loading branch information
aiekick committed Jan 7, 2024
1 parent f2e0012 commit fdca1a9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ImGuiFileDialog
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1040,11 +1040,29 @@ config.userFileAttributes = [](IGFD::FileInfos* vFileInfosPtr, IGFD::UserDatas v

Before the User of the userAttribute callback :

![user_files_attributes_before.gif](https://github.com/aiekick/ImGuiFileDialog/blob/DemoApp/doc/user_files_attributes_before.png)
![user_files_attributes_before.png](https://github.com/aiekick/ImGuiFileDialog/blob/DemoApp/doc/user_files_attributes_before.png)

After :

![user_files_attributes_after.gif](https://github.com/aiekick/ImGuiFileDialog/blob/DemoApp/doc/user_files_attributes_after.png)
![user_files_attributes_after.png](https://github.com/aiekick/ImGuiFileDialog/blob/DemoApp/doc/user_files_attributes_after.png)

You can also display a tootlip for a file displayed when the mouse is over a dedicated column

you juste need to set your message for the FileDialogConfig.tooltipMessage
and specify the column in FileDialogConfig.tooltipColumn

ex code from the DemoApp branch for display the decomposition of gltf total size

syntax :
```cpp
vFileInfosPtr->tooltipMessage = toStr("%s : %s\n%s : %s", //
(vFileInfosPtr->fileNameLevels[0] + ".gltf").c_str(), //
IGFD::Utils::FormatFileSize(vFileInfosPtr->fileSize).c_str(), //
(vFileInfosPtr->fileNameLevels[0] + ".bin").c_str(), //
IGFD::Utils::FormatFileSize((size_t)statInfos.st_size).c_str()); //
vFileInfosPtr->tooltipColumn = 1; // column of file size
```
![file_tooltip_message.png](https://github.com/aiekick/ImGuiFileDialog/blob/DemoApp/doc/file_tooltip_message.png)
</blockquote></details>
Expand Down
Binary file added doc/file_tooltip_message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 20 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ class CustomDrawReadOnlyCheckBoxFileDialog : public ImGuiFileDialog {
}
};

std::string toStr(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
char TempBuffer[3072 + 1]; // 3072 = 1024 * 3
const int w = vsnprintf(TempBuffer, 3072, fmt, args);
va_end(args);
if (w) {
return std::string(TempBuffer, (size_t)w);
}
return std::string();
}

int main(int, char**) {
#ifdef _MSC_VER
// active memory leak detector
Expand Down Expand Up @@ -736,7 +748,7 @@ int main(int, char**) {
config.path = ".";
config.countSelectionMax = 0;
config.flags = flags;
/*config.userFileAttributes = [](IGFD::FileInfos* vFileInfosPtr, IGFD::UserDatas vUserDatas) -> bool {
config.userFileAttributes = [](IGFD::FileInfos* vFileInfosPtr, IGFD::UserDatas vUserDatas) -> bool {
if (vFileInfosPtr != nullptr) {
// this demo not take into account .gltf who have data insise. besauce keepd easy just for demo
if (vFileInfosPtr->SearchForExt(".gltf", true)) {
Expand All @@ -745,6 +757,12 @@ int main(int, char**) {
char timebuf[100];
int result = stat(bin_file_path_name.c_str(), &statInfos);
if (!result) {
vFileInfosPtr->tooltipMessage = toStr("%s : %s\n%s : %s", //
(vFileInfosPtr->fileNameLevels[0] + ".gltf").c_str(), //
IGFD::Utils::FormatFileSize(vFileInfosPtr->fileSize).c_str(), //
(vFileInfosPtr->fileNameLevels[0] + ".bin").c_str(), //
IGFD::Utils::FormatFileSize((size_t)statInfos.st_size).c_str()); //
vFileInfosPtr->tooltipColumn = 1;
vFileInfosPtr->fileSize += (size_t)statInfos.st_size;
} else {
// no bin, so escaped.
Expand All @@ -755,7 +773,7 @@ int main(int, char**) {
}
}
return true;
};*/
};
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IGFD_FOLDER_OPEN " Choose a File", filters, config);
}
}
Expand Down

0 comments on commit fdca1a9

Please sign in to comment.