-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to open dialog box without ImGui::Button #19
Comments
Well, as far as I can see, you have just copied what's written at the top of imguifilesystem.h, and you haven't explained the problem you've experiencing (you're just saying: it doesn't work). Your post is not very useful 😢 . Anyway:
const char* startingFolder = "./";
const char* optionalFileExtensionFilterString = "";//".jpg;.jpeg;.png;.tiff;.bmp;.gif;.txt";
//------------------------------------------------------------------------------------------
// 1 - ChooseFileDialogButton setup:
//------------------------------------------------------------------------------------------
ImGui::Text("Please choose a file: ");ImGui::SameLine();
const bool browseButtonPressed = ImGui::Button("...");
static ImGuiFs::Dialog fsInstance;
const char* chosenPath = fsInstance.chooseFileDialog(browseButtonPressed,startingFolder,optionalFileExtensionFilterString);
if (strlen(chosenPath)>0) {
// A path (chosenPath) has been chosen right now. However we can retrieve it later using: fsInstance.getChosenPath()
}
if (strlen(fsInstance.getChosenPath())>0) ImGui::Text("Chosen path: \"%s\"",fsInstance.getChosenPath()); One thing that is worth noting is that the line with:
|
Yes I just copied the same code, It works fine when There is
|
While it's not clear to me what showDialog is, browseButtonPressed must be true only in a single frame, while static ImGuiFs::Dialog dlg; // one per dialog (and must be static)
const char* chosenPath = dlg.chooseFileDialog(showDialog); // see other dialog types and the full list of arguments for advanced usage
if (strlen(chosenPath)>0)
{
// A path (chosenPath) has been chosen RIGHT NOW. However we can retrieve it later more comfortably using: dlg.getChosenPath()
}
if (strlen(dlg.getChosenPath())>0)
{
ImGui::Text("Chosen file: \"%s\"",dlg.getChosenPath());
}
if (showDialog) showDialog=false; |
Thanks it' working now. With changes you suggested. Just little doubt why Note for Future reference:browseButtonPressed must be true only in a single frame, while |
Well, it can't be a local variable, because it keeps a lot of state variables inside (for example the navigation history while the dialog is open). [Obviously, it can be a global variable too].
Yes. One thing that is worth noting is that the line with: fsInstance.chooseFileDialog(...) must be executed on every frame (modal dialogs in imgui can't just stop the main loop and wait for user selection). |
Hello there, I have similar question here. Could you kindly provide me an example using chooseFileDialog inside BeginMenu as menuitem, instead of a button? Here is my ugly solution, it works, but the selection area is smaller than the others MenuItems:
|
I'd do something like: bool browseButtonPressed = false;
if (ImGui::BeginMenu("File")) {
browseButtonPressed = ImGui::MenuItem("Open...", "CTRL+O");
ImGui::EndMenu();
}
static ImGuiFs::Dialog dlg;
const char* chosenPath = dlg.chooseFileDialog(browseButtonPressed); Does it work better or not ? |
That's awesome! Thank you! |
I am trying to open dialog box on pressing
ImGui::MenuItem
or by simplebool
variable, but it doesn't work.The text was updated successfully, but these errors were encountered: