gallickgunner / imgui-addons Goto Github PK
View Code? Open in Web Editor NEWCross Platform File Dialog for Dear-ImGui
License: MIT License
Cross Platform File Dialog for Dear-ImGui
License: MIT License
I saw #47, but saw that it was only for non-Windows use. Is there a particular reason why there isn't an option for it for Windows?
I tested compiling on Linux and this is what I found.
My system (Arch Linux) does not supply d_namlen
or define _DIRENT_HAVE_D_NAMLEN
.
There are a few windows-specific calls used:
GetLogicalDriveStringsA
GetLogicalDriveStringsA
GetDriveTypeA
Here are the errors. (warnings ommited)
$ clang++ -c FileBrowser/ImGuiFileBrowser.cpp -I imgui -o ImGuiFileBrowser.cpp
FileBrowser/ImGuiFileBrowser.cpp:306:51: error: no member named 'd_namlen' in 'dirent'; did you mean 'd_reclen'?
if((ent->d_name[0] == '.' && ent->d_namlen == 1))
^~~~~~~~
d_reclen
/usr/include/bits/dirent.h:31:24: note: 'd_reclen' declared here
unsigned short int d_reclen;
^
FileBrowser/ImGuiFileBrowser.cpp:308:28: error: no member named 'd_namlen' in 'dirent'; did you mean 'd_reclen'?
if( !(ent->d_namlen == 2 && ent->d_name[0] == '.' && ent->d_name[1] == '.') )
^~~~~~~~
d_reclen
/usr/include/bits/dirent.h:31:24: note: 'd_reclen' declared here
unsigned short int d_reclen;
^
FileBrowser/ImGuiFileBrowser.cpp:319:55: error: no member named 'd_namlen' in 'dirent'; did you mean 'd_reclen'?
if((ent->d_name[0] == '.' && ent->d_namlen > 1))
^~~~~~~~
d_reclen
/usr/include/bits/dirent.h:31:24: note: 'd_reclen' declared here
unsigned short int d_reclen;
^
FileBrowser/ImGuiFileBrowser.cpp:361:9: error: unknown type name 'DWORD'
DWORD len = GetLogicalDriveStringsA(0,NULL);
^
FileBrowser/ImGuiFileBrowser.cpp:361:21: error: use of undeclared identifier 'GetLogicalDriveStringsA'
DWORD len = GetLogicalDriveStringsA(0,NULL);
^
FileBrowser/ImGuiFileBrowser.cpp:370:16: error: use of undeclared identifier 'DRIVE_REMOVABLE'
if(DRIVE_REMOVABLE == GetDriveTypeA(drv))
^
FileBrowser/ImGuiFileBrowser.cpp:370:35: error: use of undeclared identifier 'GetDriveTypeA'
if(DRIVE_REMOVABLE == GetDriveTypeA(drv))
^
FileBrowser/ImGuiFileBrowser.cpp:372:21: error: use of undeclared identifier 'DRIVE_FIXED'
else if(DRIVE_FIXED == GetDriveTypeA(drv))
^
FileBrowser/ImGuiFileBrowser.cpp:372:36: error: use of undeclared identifier 'GetDriveTypeA'
else if(DRIVE_FIXED == GetDriveTypeA(drv))
^
2 warnings and 9 errors generated.
The method ImGui::GetFocusedFocusScope is not found anymore on ImGUI, as well the flag ImGuiSelectableFlags_SelectOnClick.
Thanks for sharing your code.
I think
ImGuiSelectableFlags_PressedOnClick
is obsolete (and does not compile with the latest version of ImGUI) and I replaced it with
ImGuiSelectableFlags_SelectOnClick
but I am not 100% sure.
Bests
Roberto
default value for valid_types = *.*
. However if you use that you first have to select *.*
under valid types before files are shown.
A function maybe to be able to render Open file with "All valid Files" as default option
I would like to be able to select a folder instead of a file.
Here's a simple fix I made. I haven't tested it thoroughly but it seems to have fix the bug.
- new_path = current_path.substr(0, current_path.find("/" + current_dirlist[idx]) + current_dirlist[idx].length() + 2 );
+ {
+ new_path = "";
+ for (auto iter = current_dirlist.begin() + 1; iter != current_dirlist.begin() + idx + 1; ++iter)
+ new_path += *iter + "/";
+ }
Since there was two folders with the same name in the path, if you navigate to the deepest one by clicking on it the current_path.find
is going to find the first folder instead.
Example: C:/a/path/to/a/folder
Clicking on the second folder "a" is going to cause the bug. In this case the path is still valid.
Example: C:/app/path/to/a/folder
In that case the new path would be "C:/ap" which does not exist.
I am just cutting and pasting your example on the main page. It doesn't work, and I am not sure if it is something that I am doing. It is crashing on line 5609 in imgui.cpp:
IM_ASSERT((window_flags & ImGuiWindowFlags_AlwaysAutoResize) == 0 && "Cannot specify ImGuiWindowFlags_AlwaysAutoResize for BeginChild(). Use ImGuiChildFlags_AlwaysAutoResize!");
Going up the stack, it originates here on line 236 in imGuiFileBrowser.cpp:
ImGui::BeginChild("##NavigationWindow", nw_size, true, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar);
I don't see how to differentiate between the user clicking cancel and the user not giving any input. Looking at the code, it appears like clicking cancel causes showFileDialog to return false, just like if the user didn't click anything. Is there something I am missing here? Would it be possible to give a quick example of how the cancel button works?
Windows 8.1 x64
Microsoft Visual Studio 2022 C++17
ImGui v.1.86
Other imgui items not working when selecting path
ImGui-Addons/FileBrowser/ImGuiFileBrowser.cpp
Lines 1007 to 1008 in 380b617
The fact that valid_exts.size() - 1
is regarded as "display extension count" is based on the assumption that there is a "All valid files" in the valid_exts
, which is only true if users provided more than 1 extension.
In the case of 1 extension, cw_height
would be 0 which is invalid for BeginChild()
.
auto ext_count = valid_exts.back() == "All valid files" ? valid_exts.size() - 1 : valid_exts.size()
, and replace the 2 occurrences of valid_exts.size() - 1
P.S. I tried that and it works, except that the visual is not very pleasing with child window showing scrollbar, so I think it's best for the repo owner to fix this problem.
Hi,
I'm trying to get the file dialog working using 1.84.2 but the dialog is not showing up
the function BeginPopupModal line 130 returns false:
if (ImGui::BeginPopupModal(label.c_str(), nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
my code:
bool open = false;
if (ImGui::MenuItem("Open", "Ctrl+O"))
{
open = true;
}
if (open)
{
ImGui::OpenPopup("Open File");
}
if (file_dialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310), ".bin"))
{
//std::cout << file_dialog.selected_fn << std::endl; // The name of the selected file or directory in case of Select Directory dialog mode
// std::cout << file_dialog.selected_path << std::endl; // The absolute path to the selected file
}
I started to play with the extension but I can see several improvement that could be made. It(s just my point , so it could differs from one to another :)
Here's a Windows 10 file dialog :
The allowed extensions are displayed in a list at the right of the filter in a list after the name filter.
So the names that don't corresponding to the extension pattern are not displayed , so not selectable.
Moreover, adding the classical jokers like '*' to the filter could be an improvement, at least for windows users :)
Finally it should be possible to pass a filename as a string to open the save dialog , to allow acting as a 'save as' with a already existing file
It would be great for the SELECT folder option to specify also a file filter, so as to get also the list of those filenames contained in the selected folder. Something like this:
file_dialog.showFileDialog("Select Directory##popup", imgui_addons::ImGuiFileBrowser::DialogMode::SELECT, ImVec2(500,300), ".zip,.tgz", &filelist)
Thanks
-R
The example code in the README is missing a ImGui::EndMenu()
after a call to ImGui::BeingMenu("Menu")
. This was causing the following error when trying to click on the top bar:
void ImGui::EndMenuBar(): Assertion `window->Flags & ImGuiWindowFlags_MenuBar' failed.
Adding the missing line should make it work again:
if(ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu("Menu"))
{
if (ImGui::MenuItem("Open", nullptr))
open = true;
if (ImGui::MenuItem("Save", nullptr))
save = true;
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
Hi, i've found a small bug inside the bool validateFile() function, file ImGuiFileBrowser.cpp, line 1055:
std::string file_ext = idx == std::string::npos ? "" : selected_fn.substr(idx, selected_fn.length() - idx);
is returning ".ext"
while in needed the extension without the dot to correctly check, "ext"
so idx+1, in the substring extraction, fix the issue:
std::string file_ext = idx == std::string::npos ? "" : selected_fn.substr(idx+1, selected_fn.length() - idx);
Hello, I have a program that currently runs on Linux, and I'm porting it to windows too.
I'm trying to use clang++ on windows to build it, but it gives me an error:
The command used to build is the following:
clang++ -c --std=c++17 ../ImGui-Addons/FileBrowser/ImGuiFileBrowser.cpp -I../ImGui-Addons/imgui -o filebrowser.o
(My makefile was not working, so i'm doing this at the moment)
It gives me the errors:
../ImGui-Addons/FileBrowser/ImGuiFileBrowser.cpp:589:47: error: no member named 'GetFocusScopeID' in namespace 'ImGui'; did you mean
'GetFocusScope'?
if(show_inputbar_combobox && ( ImGui::GetFocusScopeID() == focus_scope_id || ImGui::GetCurrentContext()->ActiveIdIsAliv...
~~~~~~~^~~~~~~~~~~~~~~
GetFocusScope
../ImGui-Addons/imgui\imgui_internal.h:2276:29: note: 'GetFocusScope' declared here
inline ImGuiID GetFocusScope() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DC.NavFocusScop...
^
../ImGui-Addons/FileBrowser/ImGuiFileBrowser.cpp:614:113: error: use of undeclared identifier 'ImGuiSelectableFlags_PressedOnClick'; did
you mean 'ImGuiSelectableFlags_SelectOnClick'?
...false, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_PressedOnClick))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ImGuiSelectableFlags_SelectOnClick
../ImGui-Addons/imgui\imgui_internal.h:728:5: note: 'ImGuiSelectableFlags_SelectOnClick' declared here
ImGuiSelectableFlags_SelectOnClick = 1 << 21, // Override button behavior to react on Click (default is Click+Release)
Can someone give me some help?
On Linux the file dialog will open only in the root folder.
Hi GallickRunner,
The dialog window works great! Is there a way to provide the dialog window with a path that would override the default path? There are cases where an application may want to specify a location, based on the context of the operation. I did attempt to make a tweak, but haven’t been successful.
Peter
imgui.h
lives in the root of the imgui file structure.
Rather specify the include dir through the build system.
I'm working on a game engine, and I'm already using this file browser to open and save projects and scenes. However, I'd also like to use it for selecting sprites, scripts, etc, but they are only in the Assets folder, so how could I modify it to only search in the Assets folder?
Hi there,
first, a big thx for this addon to Imgui.
Then it seems that there has been a litle change in Imgui, so that your file does not compile anymore with Imgui 1.77.
In imgui_internal.h it seems that ImGuiSelectableFlags_PressedOnClick becomes ImGuiSelectableFlags_SelectOnClick .
So you have to change accordingly you ImguiFileBrowser.ccp , line 615 .
I suppose that this line was in relation with the file filter combobox that seems to work ok.
After the file dialog is used once and a file is selected with the option "All valid files," the next file dialog opened will have the first extension selected, but will allow all files to be selected. The problem persists on future file dialogs until another extension is selected on the drop down
Like I said, it goes back to normal after the user selects an extension from the dropdown
Similar to most file dialogs, if you paste in a directory path and press Enter, instead of trying to select a file, the dialog should instead navigate to that directory.
They should be undefined imguifilebrowser.cpp
Not sure what change made this happen but I can't build on Windows anymore with imgui 1.85.
C:\projects\gazebosc-sphaero\ext\ImGui-Addons\FileBrowser\ImGuiFileBrowser.cpp(121,46): error C2589: '(': illegal token on right side of '::' [C:\projects\gazebosc-sphaero\build\gazebosc.vcxproj]
C:\projects\gazebosc-sphaero\ext\ImGui-Addons\FileBrowser\ImGuiFileBrowser.cpp(121): error C2144: syntax error: 'unknown-type' should be preceded by ')' [C:\projects\gazebosc-sphaero\build\gazebosc.vcxproj]
Very much related to #7
I think it can also be fixed by using std::max<float>
instead of std::max
etc
However it's just a workaround.
Hello,
Currently, the initial path looks based on the current path.
Is there any way to set the last opened path as the initial path?
Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.